I try to map Dataset<Row>
into Dataset<MyRow>
in Apache Spark in Java. Does anyone know where could be the problem?
Dataset<Row> flightsDF = spark.read().format("csv").option("header", "true").load( ... );
Dataset<Row> DSOfRows = flightsDF
.filter( ... );
DSOfRows.show(5);
Code will show 5 first rows, then I will try to map the Row into MyRow.
Dataset<MyRow> DSOfMyRows = DSOfRows.map(
(MapFunction<Row, MyRow>) row -> new MyRow(row.getAs("Carrier"),
row.getAs("ArrDelay")), Encoders.bean(MyRow.class));
DSOfMyRows.show(5);
and there is the problem because it will print only empty rows.
++
||
++
||
||
||
||
||
++
only showing top 5 rows
The MyRow class looks like this:
public static class MyRow implements Serializable {
public String carrier;
public Double arrDelay;
MyRow(String carrier, Double delay) {
this.carrier = carrier;
this.arrDelay = delay;
}
String getCarrier() {
return carrier;
}
public void setCarrier(String c) {
this.carrier = c;
}
Double getArrDelay() {
return arrDelay;
}
public void setArrDelay(Double delay) {
this.arrDelay = delay;
}
}