Search in sources :

Example 6 with TransformRequest

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

the class TransformService method saveSql.

/**
 * Executes and saves a Spark SQL request.
 */
@Nonnull
public SaveResponse saveSql(@Nonnull final String id, @Nonnull final SaveRequest save) {
    log.entry(id, save);
    // Create task
    final Supplier<SaveResult> task;
    final TransformRequest transform = getTransformRequest(id);
    final JdbcDatasource transformDatasource = (transform.getDatasources() != null && transform.getDatasources().size() == 1 && transform.getDatasources().get(0) instanceof JdbcDatasource) ? (JdbcDatasource) transform.getDatasources().get(0) : null;
    if (transformDatasource != null && save.getJdbc() != null && Objects.equal(transformDatasource.getId(), save.getJdbc().getId())) {
        Preconditions.checkArgument(save.getTableName() != null, "Missing target table name.");
        task = new SaveSqlStage(save.getTableName(), transform.getScript(), save.getJdbc());
    } else {
        task = createSaveTask(save, createSqlTask(transform));
    }
    // Submit job
    final SaveResponse response = submitSaveJob(task);
    return log.exit(response);
}
Also used : JdbcDatasource(com.thinkbiganalytics.spark.rest.model.JdbcDatasource) SaveSqlStage(com.thinkbiganalytics.spark.metadata.SaveSqlStage) SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) SaveResult(com.thinkbiganalytics.spark.model.SaveResult) TransformRequest(com.thinkbiganalytics.spark.rest.model.TransformRequest) Nonnull(javax.annotation.Nonnull)

Example 7 with TransformRequest

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

the class SparkShellTransformControllerTest method createWithMissingScript.

/**
 * Verify response if missing script.
 */
@Test
public void createWithMissingScript() {
    SparkShellTransformController controller = new SparkShellTransformController();
    Response response = controller.create(new TransformRequest());
    Assert.assertEquals(Response.Status.BAD_REQUEST, response.getStatusInfo());
    TransformResponse entity = (TransformResponse) response.getEntity();
    Assert.assertEquals("The request must include a script with the transformations to perform.", entity.getMessage());
    Assert.assertEquals(TransformResponse.Status.ERROR, entity.getStatus());
}
Also used : TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Response(javax.ws.rs.core.Response) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) TransformRequest(com.thinkbiganalytics.spark.rest.model.TransformRequest) Test(org.junit.Test)

Example 8 with TransformRequest

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

the class SparkShellTransformControllerTest method createWithMissingParentTable.

/**
 * Verify response if missing parent table.
 */
@Test
public void createWithMissingParentTable() {
    // Create transform request
    TransformRequest request = new TransformRequest();
    request.setScript("parent");
    TransformRequest.Parent parent = new TransformRequest.Parent();
    parent.setScript("sqlContext.sql(\"SELECT * FROM invalid\")");
    request.setParent(parent);
    // Test missing parent table
    SparkShellTransformController controller = new SparkShellTransformController();
    Response response = controller.create(request);
    Assert.assertEquals(Response.Status.BAD_REQUEST, response.getStatusInfo());
    TransformResponse entity = (TransformResponse) response.getEntity();
    Assert.assertEquals("The parent must include the table containing the results.", entity.getMessage());
    Assert.assertEquals(TransformResponse.Status.ERROR, entity.getStatus());
}
Also used : TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Response(javax.ws.rs.core.Response) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) TransformRequest(com.thinkbiganalytics.spark.rest.model.TransformRequest) Test(org.junit.Test)

Example 9 with TransformRequest

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

the class SparkShellTransformControllerTest method create.

/**
 * Verify requesting a Spark transformation.
 */
@Test
public void create() throws Exception {
    // Mock transform objects
    TransformRequest transformRequest = new TransformRequest();
    transformRequest.setScript("sqlContext.sql(\"SELECT * FROM invalid\")");
    TransformResponse transformResponse = new TransformResponse();
    transformResponse.setProgress(0.0);
    transformResponse.setStatus(TransformResponse.Status.PENDING);
    transformResponse.setTable("results");
    TransformService transformService = Mockito.mock(TransformService.class);
    Mockito.when(transformService.execute(transformRequest)).thenReturn(transformResponse);
    // Test transforming
    SparkShellTransformController controller = new SparkShellTransformController();
    controller.transformService = transformService;
    Response response = controller.create(transformRequest);
    Assert.assertEquals(Response.Status.OK, response.getStatusInfo());
    Assert.assertEquals(transformResponse, response.getEntity());
}
Also used : TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Response(javax.ws.rs.core.Response) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) TransformService(com.thinkbiganalytics.spark.service.TransformService) TransformRequest(com.thinkbiganalytics.spark.rest.model.TransformRequest) Test(org.junit.Test)

Example 10 with TransformRequest

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

the class SparkShellTransformControllerTest method createWithMissingParentScript.

/**
 * Verify response if missing parent script.
 */
@Test
public void createWithMissingParentScript() {
    // Create transform request
    TransformRequest request = new TransformRequest();
    request.setScript("parent");
    request.setParent(new TransformRequest.Parent());
    // Test missing parent script
    SparkShellTransformController controller = new SparkShellTransformController();
    Response response = controller.create(request);
    Assert.assertEquals(Response.Status.BAD_REQUEST, response.getStatusInfo());
    TransformResponse entity = (TransformResponse) response.getEntity();
    Assert.assertEquals("The parent must include a script with the transformations performed.", entity.getMessage());
    Assert.assertEquals(TransformResponse.Status.ERROR, entity.getStatus());
}
Also used : TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Response(javax.ws.rs.core.Response) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) TransformRequest(com.thinkbiganalytics.spark.rest.model.TransformRequest) Test(org.junit.Test)

Aggregations

TransformRequest (com.thinkbiganalytics.spark.rest.model.TransformRequest)12 Test (org.junit.Test)9 TransformResponse (com.thinkbiganalytics.spark.rest.model.TransformResponse)8 Response (javax.ws.rs.core.Response)5 SparkContextService (com.thinkbiganalytics.spark.SparkContextService)4 SparkScriptEngine (com.thinkbiganalytics.spark.repl.SparkScriptEngine)4 InputStream (java.io.InputStream)4 DataSet (com.thinkbiganalytics.spark.DataSet)2 SaveResponse (com.thinkbiganalytics.spark.rest.model.SaveResponse)2 TransformService (com.thinkbiganalytics.spark.service.TransformService)2 List (java.util.List)2 SparkContext (org.apache.spark.SparkContext)2 StructType (org.apache.spark.sql.types.StructType)2 StorageLevel (org.apache.spark.storage.StorageLevel)2 NamedParam (scala.tools.nsc.interpreter.NamedParam)2 Response (com.jayway.restassured.response.Response)1 Profiler (com.thinkbiganalytics.spark.dataprofiler.Profiler)1 SaveSqlStage (com.thinkbiganalytics.spark.metadata.SaveSqlStage)1 SaveResult (com.thinkbiganalytics.spark.model.SaveResult)1 Datasource (com.thinkbiganalytics.spark.rest.model.Datasource)1