在 Row Java API 中,有 row.schema(),但没有 row.set(StructType schema)。
我也尝试了 RowFactory.create(objects),但我不知道如何继续
更新:
问题是当我修改 worker 中的结构时如何生成新的数据框,我举了例子
DataFrame sentenceData = jsql.createDataFrame(jrdd, schema);
List<Row> resultRows2 = sentenceData.toJavaRDD()
.map(new MyFunction<Row, Row>(parameters) {
/** my map function **//
public Row call(Row row) {
// I want to change Row definition adding new columns
Row newRow = functionAddnewNewColumns (row);
StructType newSchema = functionGetNewSchema (row.schema);
// Here I want to insert the structure
//
return newRow
}
}
}).collect();
JavaRDD<Row> jrdd = jsc.parallelize(resultRows);
// Here is the problema I don't know how to get the new schema to create the new modified dataframe
DataFrame newDataframe = jsql.createDataFrame(jrdd, newSchema);
最佳答案
您可以使用架构创建一行:
Row newRow = new GenericRowWithSchema(values, newSchema);
关于apache-spark - 如何在 Spark 中引入 Row 中的 schema?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33934615/