Search in sources :

Example 1 with RowTransform

use of com.thinkbiganalytics.spark.jdbc.RowTransform in project kylo by Teradata.

the class SqlTransformStage method extractData.

@Override
public TransformResult extractData(@Nonnull final ResultSet rs) throws SQLException {
    final ResultSetMetaData metaData = rs.getMetaData();
    final TransformResult result = new TransformResult();
    final StructType schema = extractSchema(metaData, result);
    // Create data set
    final Function0<Connection> getConnection = ScalaUtil.wrap(Suppliers.compose(JdbcUtil.getDataSourceConnection(), dataSource));
    final Function1<ResultSet, Row> mapRow = ScalaUtil.wrap(new RowTransform());
    // noinspection RedundantCast,unchecked
    final ClassTag<Row> classTag = (ClassTag) ClassTag$.MODULE$.apply(Row.class);
    final RDD<Row> rdd = new JdbcRDD<Row>(sqlContext.sparkContext(), getConnection, "SELECT * FROM (" + sql + ") rdd WHERE ? = ?", 1, 1, 1, mapRow, classTag);
    result.setDataSet(sparkContextService.toDataSet(sqlContext, rdd.toJavaRDD(), schema));
    return result;
}
Also used : TransformResult(com.thinkbiganalytics.spark.model.TransformResult) StructType(org.apache.spark.sql.types.StructType) Connection(java.sql.Connection) ResultSetMetaData(java.sql.ResultSetMetaData) JdbcRDD(org.apache.spark.rdd.JdbcRDD) RowTransform(com.thinkbiganalytics.spark.jdbc.RowTransform) ResultSet(java.sql.ResultSet) Row(org.apache.spark.sql.Row) ClassTag(scala.reflect.ClassTag)

Aggregations

RowTransform (com.thinkbiganalytics.spark.jdbc.RowTransform)1 TransformResult (com.thinkbiganalytics.spark.model.TransformResult)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 JdbcRDD (org.apache.spark.rdd.JdbcRDD)1 Row (org.apache.spark.sql.Row)1 StructType (org.apache.spark.sql.types.StructType)1 ClassTag (scala.reflect.ClassTag)1