在 class 错误中找不到列
Columns not found in class error
我正在尝试从 cassandra table 中提取某些数据,然后将其写回 cassandra 中的另一个 table。
这是我的:
JavaRDD<MeasuredValue> mvRDD = javaFunctions(sc).cassandraTable("SB1000_47130646", "Measured_Value", mapRowTo(MeasuredValue.class))
.where ("\"Time_Key\" IN (1601823,1601824)")
.select("Time_Key","Start_Frequency","Bandwidth", "Power");
然后我写回一个新的table:
javaFunctions(mvRDD).writerBuilder("spark_reports","SB1000_47130646", mapToRow(MeasuredValue.class)).withColumnSelector(someColumns("Time_Key", "Start_Frequency", "Bandwidth", "Power")).saveToCassandra();
我的测量值 Class 看起来像这样:
public static class MeasuredValue implements Serializable {
public MeasuredValue() { }
public MeasuredValue(Long Time_Key, Double Start_Frequency, Double Bandwidth, Float Power) {
this.Time_Key = Time_Key;
this.Start_Frequency = Start_Frequency;
this.Bandwidth = Bandwidth;
this.Power = Power;
}
private Long Time_Key;
public Long gettime_key() { return Time_Key; }
public void settime_key(Long Time_Key) { this.Time_Key = Time_Key; }
private Double Start_Frequency;
public Double getstart_frequency() { return Start_Frequency; }
public void setstart_frequency(Double Start_Frequency) { this.Start_Frequency = Start_Frequency; }
private Double Bandwidth;
public Double getbandwidth() { return Bandwidth; }
public void setbandwidth(Double Bandwidth) { this.Bandwidth = Bandwidth; }
private Float Power;
public Float getpower() { return Power; }
public void setpower(Float Power) { this.Power = Power;
}
我在 运行 时得到的错误是:
Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Columns not found in class com.neutronis.spark_reports.Spark_Reports$MeasuredValue: [Time_Key, Start_Frequency, Bandwidth, Power]
我发现这是因为 getters/setters 在大写字母和变量方面遵循 JAVA 命名方案。由于我的 table 中的列是驼峰式大小写,因此我不得不将列名称重新配置为正确的全小写命名约定,以使其正常工作。
为了使用大写字母,我不得不使用 HashMap:
HashMap<String,String> colmap = new HashMap<String,String>();
colmap.put( "start_frequency", "Start_Frequency" );
colmap.put( "bandwith", "Bandwidth" );
colmap.put( "power", "Power" );
RowReaderFactory<MeasuredValue> mapRowTo = mapRowTo(MeasuredValue.class, colmap);
我正在尝试从 cassandra table 中提取某些数据,然后将其写回 cassandra 中的另一个 table。
这是我的:
JavaRDD<MeasuredValue> mvRDD = javaFunctions(sc).cassandraTable("SB1000_47130646", "Measured_Value", mapRowTo(MeasuredValue.class))
.where ("\"Time_Key\" IN (1601823,1601824)")
.select("Time_Key","Start_Frequency","Bandwidth", "Power");
然后我写回一个新的table:
javaFunctions(mvRDD).writerBuilder("spark_reports","SB1000_47130646", mapToRow(MeasuredValue.class)).withColumnSelector(someColumns("Time_Key", "Start_Frequency", "Bandwidth", "Power")).saveToCassandra();
我的测量值 Class 看起来像这样:
public static class MeasuredValue implements Serializable {
public MeasuredValue() { }
public MeasuredValue(Long Time_Key, Double Start_Frequency, Double Bandwidth, Float Power) {
this.Time_Key = Time_Key;
this.Start_Frequency = Start_Frequency;
this.Bandwidth = Bandwidth;
this.Power = Power;
}
private Long Time_Key;
public Long gettime_key() { return Time_Key; }
public void settime_key(Long Time_Key) { this.Time_Key = Time_Key; }
private Double Start_Frequency;
public Double getstart_frequency() { return Start_Frequency; }
public void setstart_frequency(Double Start_Frequency) { this.Start_Frequency = Start_Frequency; }
private Double Bandwidth;
public Double getbandwidth() { return Bandwidth; }
public void setbandwidth(Double Bandwidth) { this.Bandwidth = Bandwidth; }
private Float Power;
public Float getpower() { return Power; }
public void setpower(Float Power) { this.Power = Power;
}
我在 运行 时得到的错误是:
Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Columns not found in class com.neutronis.spark_reports.Spark_Reports$MeasuredValue: [Time_Key, Start_Frequency, Bandwidth, Power]
我发现这是因为 getters/setters 在大写字母和变量方面遵循 JAVA 命名方案。由于我的 table 中的列是驼峰式大小写,因此我不得不将列名称重新配置为正确的全小写命名约定,以使其正常工作。
为了使用大写字母,我不得不使用 HashMap:
HashMap<String,String> colmap = new HashMap<String,String>();
colmap.put( "start_frequency", "Start_Frequency" );
colmap.put( "bandwith", "Bandwidth" );
colmap.put( "power", "Power" );
RowReaderFactory<MeasuredValue> mapRowTo = mapRowTo(MeasuredValue.class, colmap);