use of com.thinkbiganalytics.spark.rest.model.TransformResponse 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;
}
use of com.thinkbiganalytics.spark.rest.model.TransformResponse in project kylo by Teradata.
the class AbstractTransformController method createErrorResponse.
/**
* Creates a response for the specified message.
*
* @param status the response status
* @param message the message text
* @return the response
*/
private Response createErrorResponse(@Nonnull final Response.Status status, @Nonnull final String message) {
final TransformResponse entity = new TransformResponse();
entity.setMessage(message);
entity.setStatus(TransformResponse.Status.ERROR);
return Response.status(status).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(entity).build();
}
use of com.thinkbiganalytics.spark.rest.model.TransformResponse in project kylo by Teradata.
the class AbstractTransformController method getTable.
/**
* Requests the status of a transformation.
*
* @param id the destination table name
* @return the transformation status
*/
@GET
@Path("{table}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Fetches the status of a transformation.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the status of the transformation.", response = TransformResponse.class), @ApiResponse(code = 404, message = "The transformation does not exist.", response = TransformResponse.class), @ApiResponse(code = 500, message = "There was a problem accessing the data.", response = TransformResponse.class) })
@Nonnull
public Response getTable(@Nonnull @PathParam("table") final String id) {
try {
TransformJob job = transformService.getTransformJob(id);
if (job.isDone()) {
return Response.ok(job.get()).build();
} else {
TransformResponse response = new TransformResponse();
response.setProgress(job.progress());
response.setStatus(TransformResponse.Status.PENDING);
response.setTable(job.getGroupId());
return Response.ok(response).build();
}
} catch (final IllegalArgumentException e) {
return error(Response.Status.NOT_FOUND, "getTable.notFound");
} catch (final Exception e) {
return error(Response.Status.INTERNAL_SERVER_ERROR, e);
}
}
use of com.thinkbiganalytics.spark.rest.model.TransformResponse 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);
}
use of com.thinkbiganalytics.spark.rest.model.TransformResponse in project kylo by Teradata.
the class TransformService method query.
/**
* Executes the specified SQL query and returns the result.
*
* @param request the transformation request
* @return the transformation results
* @throws IllegalStateException if this service is not running
* @throws ScriptException if the script cannot be executed
*/
@Nonnull
public TransformResponse query(@Nonnull final TransformRequest request) throws ScriptException {
log.entry(request);
// Handle async request
if (request.isAsync()) {
return cacheTransform(request);
}
// Execute query
final TransformResponse response = submitTransformJob(createSqlTask(request), getPolicies(request));
return log.exit(response);
}
Aggregations