Guest User

Untitled

a guest
Feb 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. orderedDataFrame.foreach(new Function1<Row,BoxedUnit>(){
  2.  
  3. @Override
  4. public BoxedUnit apply(Row v1) {
  5. //how to I change Row here
  6. //I want to change column no 2 using v1.get(2)
  7. //also what is BoxedUnit how do I use it
  8. return null;
  9. }
  10. });
  11.  
  12. final DataFrame withoutCurrency = sqlContext.createDataFrame(somedf.javaRDD().map(row -> {
  13. return RowFactory.create(row.get(0), row.get(1), someMethod(row.get(2)));
  14. }), somedf.schema());
  15.  
  16. Dataset<Row> ds = spark.createDataFrame(Collections.singletonList(data), SellerAsinAttribute.class);
  17. ds.map((i)-> {
  18. Object arrayObj = Array.newInstance(Object.class, i.length());
  19. for (int n = 0; n < i.length(); ++n) {
  20. Array.set(arrayObj, n, i.get(n));//change 'i.get(n)' to anything you want, if you change type, remember to update schema
  21. }
  22. Method create = RowFactory.class.getMethod("create", Object[].class);
  23. return (Row) create.invoke(null, arrayObj);
  24. }, RowEncoder.apply(ds.schema())).show();
Add Comment
Please, Sign In to add comment