Search in sources :

Example 1 with PreviewDataSetTransformResponse

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;
    });
}
Also used : SparkShellProcess(com.thinkbiganalytics.spark.shell.SparkShellProcess) PreviewDataSetTransformResponse(com.thinkbiganalytics.spark.rest.model.PreviewDataSetTransformResponse) KyloCatalogReadRequest(com.thinkbiganalytics.spark.rest.model.KyloCatalogReadRequest) PreviewDataSetTransformResponse(com.thinkbiganalytics.spark.rest.model.PreviewDataSetTransformResponse) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) ModifiedTransformResponse(com.thinkbiganalytics.spark.rest.model.ModifiedTransformResponse) SparkException(com.thinkbiganalytics.kylo.spark.SparkException) WebApplicationException(javax.ws.rs.WebApplicationException) NoSuchMessageException(org.springframework.context.NoSuchMessageException) TimeoutException(java.util.concurrent.TimeoutException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) SparkShellSaveException(com.thinkbiganalytics.spark.shell.SparkShellSaveException) SparkShellTransformException(com.thinkbiganalytics.spark.shell.SparkShellTransformException) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)1 SparkException (com.thinkbiganalytics.kylo.spark.SparkException)1 KyloCatalogReadRequest (com.thinkbiganalytics.spark.rest.model.KyloCatalogReadRequest)1 ModifiedTransformResponse (com.thinkbiganalytics.spark.rest.model.ModifiedTransformResponse)1 PreviewDataSetTransformResponse (com.thinkbiganalytics.spark.rest.model.PreviewDataSetTransformResponse)1 TransformResponse (com.thinkbiganalytics.spark.rest.model.TransformResponse)1 SparkShellProcess (com.thinkbiganalytics.spark.shell.SparkShellProcess)1 SparkShellSaveException (com.thinkbiganalytics.spark.shell.SparkShellSaveException)1 SparkShellTransformException (com.thinkbiganalytics.spark.shell.SparkShellTransformException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 TimeoutException (java.util.concurrent.TimeoutException)1 BadRequestException (javax.ws.rs.BadRequestException)1 Consumes (javax.ws.rs.Consumes)1 NotFoundException (javax.ws.rs.NotFoundException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 NoSuchMessageException (org.springframework.context.NoSuchMessageException)1