Skip to content

Commit 136753d

Browse files
committed
Merge branch 'release/2.0' into develop
2 parents 9eff321 + 2e2c5c0 commit 136753d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/co/cask/hydrator/plugin/spark/dynamic/ScalaSparkCompute.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.io.IOException;
4949
import java.io.PrintWriter;
5050
import java.io.StringWriter;
51+
import java.lang.reflect.InvocationTargetException;
5152
import java.lang.reflect.Method;
5253
import java.lang.reflect.ParameterizedType;
5354
import java.lang.reflect.Type;
@@ -207,7 +208,7 @@ public JavaRDD<StructuredRecord> transform(SparkExecutionPluginContext context,
207208
StructType rowType = DataFrames.toDataType(inputSchema);
208209
JavaRDD<Row> rowRDD = javaRDD.map(new RecordToRow(rowType));
209210

210-
Object dataFrame = sqlContext.createDataFrame(rowRDD, rowType);
211+
Object dataFrame = createDataFrame(sqlContext, rowRDD, rowType);
211212
Object result = takeContext ? method.invoke(null, dataFrame, context) : method.invoke(null, dataFrame);
212213

213214
// Convert the DataFrame back to RDD<StructureRecord>
@@ -373,6 +374,20 @@ private boolean isDataFrame(Type type) {
373374
return false;
374375
}
375376

377+
private Object createDataFrame(SQLContext sqlContext, JavaRDD<Row> rdd, StructType type) {
378+
try {
379+
return sqlContext.getClass()
380+
.getMethod("createDataFrame", JavaRDD.class, StructType.class)
381+
.invoke(sqlContext, rdd, type);
382+
} catch (NoSuchMethodException e) {
383+
throw new RuntimeException("Unable to find SQLContext.createDataFrame(JavaRDD, StructType) method", e);
384+
} catch (IllegalAccessException e) {
385+
throw new RuntimeException("No permission to invoke SQLContext.createDataFrame(JavaRDD, StructType) method", e);
386+
} catch (InvocationTargetException e) {
387+
throw new RuntimeException("Failed to invoke SQLContext.createDataFrame(JavaRDD, StructType) method", e);
388+
}
389+
}
390+
376391
/**
377392
* Configuration object for the plugin
378393
*/

0 commit comments

Comments
 (0)