I have one dataset in spark application has the following shape:
some_id class city
1 A ROME
1 A undefined
1 A ROME
1 null ROME
2 B MILAN
2 B unkown
2 B MILAN
2 unknown MILAN
3 C PALERMO
3 C PALERMO
3 C null
3 null PALERMO
And the resulting dataset should look like the following:
some_id class city
1 A ROME
1 A ROME
1 A ROME
1 A ROME
2 B MILAN
2 B MILAN
2 B MILAN
2 B MILAN
3 C PALERMO
3 C PALERMO
3 C PALERMO
3 C PALERMO
I tried basic way of loops but I found it not practical, what is the best way to do that?
here is what i tried to do:
String[] columnsNames = {"class", "city"};
for (String columnName : columnsNames) {
Dataset<Row> grouped = mydataset.groupBy(col("some_id"), col(columnName)).agg(functions.count("*").alias("itemCount"));
grouped = grouped
.where(not(col(columnName).equalTo("null")))
.groupBy(col("some_id"))
.agg(functions.max(col("itemCount")))
;
grouped.show();
...etc
}