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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations