use of com.thinkbiganalytics.spark.rest.model.PreviewDataSetTransformResponse in project kylo by Teradata.
the class SparkShellProxyController method preview.
@POST
@Path("/preview")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Returns the dataset preview")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the status of the file-metadata job.", response = PreviewDataSetTransformResponse.class), @ApiResponse(code = 400, message = "The requested data source does not exist.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "There was a problem processing the data.", response = RestResponseStatus.class) })
public Response preview(PreviewDataSetRequest previewRequest) {
DataSource catalogDataSource = fetchCatalogDataSource(previewRequest.getDataSource().getId());
previewRequest.setDataSource(catalogDataSource);
if (previewRequest.isFilePreview() && previewRequest.getSchemaParser() == null) {
// set it to a text preview
previewRequest.setSchemaParser(getTextSchemaParserDescriptor());
}
KyloCatalogReadRequest request = KyloCatalogReaderUtil.toKyloCatalogRequest(previewRequest);
final SparkShellProcess process = getSparkShellProcess();
return getTransformResponse(() -> {
PreviewDataSetTransformResponse response = null;
boolean fallbackToTextParser = previewRequest.isFallbackToTextOnError();
try {
TransformResponse transformResponse = restClient.kyloCatalogTransform(process, request);
response = new PreviewDataSetTransformResponse(transformResponse, previewRequest.getSchemaParser());
} catch (Exception e) {
// should we attempt to re preview the data as plain text
if (fallbackToTextParser && previewRequest.getSchemaParser() != null && !"text".equalsIgnoreCase(previewRequest.getSchemaParser().getSparkFormat())) {
previewRequest.setSchemaParser(getTextSchemaParserDescriptor());
KyloCatalogReadRequest request2 = KyloCatalogReaderUtil.toKyloCatalogRequest(previewRequest);
TransformResponse transformResponse = restClient.kyloCatalogTransform(process, request2);
response = new PreviewDataSetTransformResponse(transformResponse, previewRequest.getSchemaParser());
} else {
throw e;
}
throw e;
}
return response;
});
}
Aggregations