Search in sources :

Example 1 with DataFrameWriter

use of org.apache.spark.sql.DataFrameWriter in project kylo by Teradata.

the class SaveDataSetStage method apply.

@Nonnull
@Override
public SaveResult apply(@Nullable final TransformResult transform) {
    Preconditions.checkNotNull(transform);
    // Configure writer
    final DataFrameWriter writer = getDataSet(transform).write();
    if (request.getFormat() != null) {
        writer.format(request.getFormat());
    }
    if (request.getMode() != null) {
        writer.mode(request.getMode());
    }
    if (request.getOptions() != null) {
        writer.options(request.getOptions());
    }
    // Save transformation
    final SaveResult result = new SaveResult();
    if (request.getJdbc() != null) {
        final Properties properties = new Properties();
        properties.setProperty("driver", request.getJdbc().getDatabaseDriverClassName());
        properties.setProperty("user", request.getJdbc().getDatabaseUser());
        properties.setProperty("password", request.getJdbc().getPassword());
        writer.jdbc(request.getJdbc().getDatabaseConnectionUrl(), request.getTableName(), properties);
    } else if (request.getTableName() != null) {
        writer.saveAsTable(request.getTableName());
    } else {
        final String hadoopTmpDir = fs.getConf().get("hadoop.tmp.dir", "/tmp");
        final Path absolutePath = new Path(hadoopTmpDir, UUID.randomUUID().toString());
        final Path qualifiedPath = fs.makeQualified(absolutePath);
        result.setPath(qualifiedPath);
        writer.save(qualifiedPath.toString());
    }
    return result;
}
Also used : Path(org.apache.hadoop.fs.Path) DataFrameWriter(org.apache.spark.sql.DataFrameWriter) SaveResult(com.thinkbiganalytics.spark.model.SaveResult) Properties(java.util.Properties) Nonnull(javax.annotation.Nonnull)

Aggregations

SaveResult (com.thinkbiganalytics.spark.model.SaveResult)1 Properties (java.util.Properties)1 Nonnull (javax.annotation.Nonnull)1 Path (org.apache.hadoop.fs.Path)1 DataFrameWriter (org.apache.spark.sql.DataFrameWriter)1