Please see section "Programmatically Specifying the Schema". Java section.
The example works. But I have a question about this particular code snippet.
JavaRDD<Row> rowRDD = people.map(
new Function<String, Row>() {
public Row call(String record) throws Exception {
String[] fields = record.split(",");
return Row.create(fields[0], fields[1].trim());
}
The Row create method is being called with a static number of objects determined at compile time.
However, in my code, I need to call the Row.create method for a dynamic number of arguments.
I will only know the number of fields at run time
For example, it may be one of:
return Row.create(fields[0], fields[1].trim(), fields[2]);
or
return Row.create(fields[0]);
or
return Row.create(fields[0],fields[1].trim(), fields[2], fields[3],fields[4]);
How do I do it?