我有一个有序的Spark DataFrame
,我想改变几行,同时使用以下代码迭代它,但似乎没有任何方法来更新行对象。
orderedDataFrame.foreach(new Function1<Row,BoxedUnit>(){
@Override
public BoxedUnit apply(Row v1) {
// How do I change Row here?
// I want to change column no 2 using v1.get(2)
// also what is BoxedUnit, and how do I use it
return null;
}
});
上面的代码也给出了编译错误:
myclassname不是抽象的,它不会覆盖抽象方法。
我是Spark的新手。我使用的是1.4.0版本
Try This:
final DataFrame withoutCurrency = sqlContext.createDataFrame(somedf.javaRDD().map(row -> {
return RowFactory.create(row.get(0), row.get(1), someMethod(row.get(2)));
}), somedf.schema());
Dataset<Row> ds = spark.createDataFrame(Collections.singletonList(data), SellerAsinAttribute.class);
ds.map((i)-> {
Object arrayObj = Array.newInstance(Object.class, i.length());
for (int n = 0; n < i.length(); ++n) {
Array.set(arrayObj, n, i.get(n));//change 'i.get(n)' to anything you want, if you change type, remember to update schema
}
Method create = RowFactory.class.getMethod("create", Object[].class);
return (Row) create.invoke(null, arrayObj);
}, RowEncoder.apply(ds.schema())).show();