I have worked with RDD.flatMap function in java. Now trying my hands on DataFrames.
They say:
public <R> RDD<R> flatMap(scala.Function1<org.apache.spark.sql.Row,
scala.collection.TraversableOnce<R>> f, scala.reflect.ClassTag<R> evidence$4)
Returns a new RDD by first applying a function to all rows of this DataFrame, and then flattening the results.
Specified by: flatMap in interface RDDApi
But when I tried this, Function1
, is forcing me to override lots and lots of unimplemented methods. This is what I get:
RDD<Row> res = df.flatMap(new Function1<Row, TraversableOnce<Row>>() {
@Override
public <A> Function1<Row, A> andThen(
Function1<TraversableOnce<Row>, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcDD$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcDF$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcDI$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcDJ$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcFD$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcFF$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcFI$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcFJ$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcID$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcIF$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcII$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcIJ$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcJD$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcJF$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcJI$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcJJ$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcVD$sp(
Function1<BoxedUnit, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcVF$sp(
Function1<BoxedUnit, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcVI$sp(
Function1<BoxedUnit, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcVJ$sp(
Function1<BoxedUnit, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcZD$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcZF$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcZI$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<Object, A> andThen$mcZJ$sp(
Function1<Object, A> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public TraversableOnce<Row> apply(Row arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public double apply$mcDD$sp(double arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double apply$mcDF$sp(float arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double apply$mcDI$sp(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double apply$mcDJ$sp(long arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public float apply$mcFD$sp(double arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public float apply$mcFF$sp(float arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public float apply$mcFI$sp(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public float apply$mcFJ$sp(long arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int apply$mcID$sp(double arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int apply$mcIF$sp(float arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int apply$mcII$sp(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int apply$mcIJ$sp(long arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long apply$mcJD$sp(double arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long apply$mcJF$sp(float arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long apply$mcJI$sp(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long apply$mcJJ$sp(long arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public void apply$mcVD$sp(double arg0) {
// TODO Auto-generated method stub
}
@Override
public void apply$mcVF$sp(float arg0) {
// TODO Auto-generated method stub
}
@Override
public void apply$mcVI$sp(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void apply$mcVJ$sp(long arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean apply$mcZD$sp(double arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean apply$mcZF$sp(float arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean apply$mcZI$sp(int arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean apply$mcZJ$sp(long arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public <A> Function1<A, TraversableOnce<Row>> compose(
Function1<A, Row> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcDD$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcDF$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcDI$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcDJ$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcFD$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcFF$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcFI$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcFJ$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcID$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcIF$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcII$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcIJ$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcJD$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcJF$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcJI$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcJJ$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, BoxedUnit> compose$mcVD$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, BoxedUnit> compose$mcVF$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, BoxedUnit> compose$mcVI$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, BoxedUnit> compose$mcVJ$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcZD$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcZF$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcZI$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public <A> Function1<A, Object> compose$mcZJ$sp(
Function1<A, Object> arg0) {
// TODO Auto-generated method stub
return null;
}
}, evidence$4);
This looks weird, but I went on to make evidence$4
as:
ClassTag<Row> evidence$4 = scala.reflect.ClassTag$.MODULE$.apply(Row.class);
My intention is to just play around with flatMap
(of-course on DataFrames not on RDD). So I don't need any changes on Row
. Can return the input as is without any changes.
So I guess I need to make change only in apply
method.
@Override
public TraversableOnce<Row> apply(Row arg0) {
// TODO Auto-generated method stub
return null;
}
But again, how should I get TraversableOnce<Row>
from Row
?
Also, is the method I am trying correct? Or am I missing something?
I am using Apache Spark 1.3.1