Search in sources :

Example 1 with TransformQueryResult

use of com.thinkbiganalytics.spark.rest.model.TransformQueryResult in project kylo by Teradata.

the class ResponseStage method apply.

@Nonnull
@Override
public TransformResponse apply(@Nullable final TransformResult result) {
    Preconditions.checkNotNull(result);
    // Transform data set into rows
    final QueryResultRowTransform rowTransform = new QueryResultRowTransform(result.getDataSet().schema(), table);
    final List<List<Object>> rows = Lists.transform(result.getDataSet().collectAsList(), new Function<Row, List<Object>>() {

        @Nullable
        @Override
        public List<Object> apply(@Nullable Row row) {
            return (row != null) ? rowTransform.convertRow(row) : null;
        }
    });
    // Build the query result
    final TransformQueryResult queryResult = new TransformQueryResult();
    queryResult.setColumns(result.getColumns());
    queryResult.setRows(rows);
    queryResult.setValidationResults(result.getValidationResults());
    // Build the response
    final TransformResponse response = new TransformResponse();
    response.setProfile(result.getProfile());
    response.setResults(queryResult);
    response.setStatus(TransformResponse.Status.SUCCESS);
    response.setTable(table);
    return response;
}
Also used : TransformQueryResult(com.thinkbiganalytics.spark.rest.model.TransformQueryResult) List(java.util.List) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Row(org.apache.spark.sql.Row) Nullable(javax.annotation.Nullable) Nonnull(javax.annotation.Nonnull)

Example 2 with TransformQueryResult

use of com.thinkbiganalytics.spark.rest.model.TransformQueryResult in project kylo by Teradata.

the class TransformService method execute.

/**
 * Executes the specified transformation and returns the name of the Hive table containing the results.
 *
 * @param request the transformation request
 * @return the Hive table containing the results
 * @throws IllegalStateException if this service is not running
 * @throws ScriptException       if the script cannot be executed
 */
@Nonnull
public TransformResponse execute(@Nonnull final TransformRequest request) throws ScriptException {
    log.entry(request);
    // Handle async request
    if (request.isAsync()) {
        return cacheTransform(request);
    }
    // Execute script
    final DataSet dataSet = createShellTask(request);
    final StructType schema = dataSet.schema();
    TransformResponse response = submitTransformJob(new ShellTransformStage(dataSet), getPolicies(request));
    // Build response
    if (response.getStatus() != TransformResponse.Status.SUCCESS) {
        final String table = response.getTable();
        final TransformQueryResult partialResult = new TransformQueryResult();
        partialResult.setColumns(Arrays.<QueryResultColumn>asList(new QueryResultRowTransform(schema, table).columns()));
        response = new TransformResponse();
        response.setProgress(0.0);
        response.setResults(partialResult);
        response.setStatus(TransformResponse.Status.PENDING);
        response.setTable(table);
    }
    return log.exit(response);
}
Also used : QueryResultRowTransform(com.thinkbiganalytics.spark.metadata.QueryResultRowTransform) StructType(org.apache.spark.sql.types.StructType) DataSet(com.thinkbiganalytics.spark.DataSet) ShellTransformStage(com.thinkbiganalytics.spark.metadata.ShellTransformStage) TransformQueryResult(com.thinkbiganalytics.spark.rest.model.TransformQueryResult) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Nonnull(javax.annotation.Nonnull)

Example 3 with TransformQueryResult

use of com.thinkbiganalytics.spark.rest.model.TransformQueryResult in project kylo by Teradata.

the class SparkFileSchemaParserServiceTest method transformResponse.

private TransformResponse transformResponse(List<QueryResultColumn> columns) {
    TransformResponse transformResponse = new TransformResponse();
    transformResponse.setStatus(TransformResponse.Status.SUCCESS);
    TransformQueryResult result = new TransformQueryResult();
    result.setColumns(columns);
    transformResponse.setResults(result);
    return transformResponse;
}
Also used : TransformQueryResult(com.thinkbiganalytics.spark.rest.model.TransformQueryResult) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse)

Aggregations

TransformQueryResult (com.thinkbiganalytics.spark.rest.model.TransformQueryResult)3 TransformResponse (com.thinkbiganalytics.spark.rest.model.TransformResponse)3 Nonnull (javax.annotation.Nonnull)2 DataSet (com.thinkbiganalytics.spark.DataSet)1 QueryResultRowTransform (com.thinkbiganalytics.spark.metadata.QueryResultRowTransform)1 ShellTransformStage (com.thinkbiganalytics.spark.metadata.ShellTransformStage)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 Row (org.apache.spark.sql.Row)1 StructType (org.apache.spark.sql.types.StructType)1