Search in sources :

Example 21 with TransformResponse

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

the class SparkFileSchemaParserServiceTest method transformResponse.

private TransformResponse transformResponse(List<QueryResultColumn> columns) {
    TransformResponse transformResponse = new TransformResponse();
    transformResponse.setStatus(TransformResponse.Status.SUCCESS);
    TransformQueryResult result = new TransformQueryResult();
    result.setColumns(columns);
    transformResponse.setResults(result);
    return transformResponse;
}
Also used : TransformQueryResult(com.thinkbiganalytics.spark.rest.model.TransformQueryResult) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse)

Example 22 with TransformResponse

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

the class SparkShellIT method testScriptSave.

/**
 * Verify saving the result of a script.
 */
@Test
public void testScriptSave() {
    final TransformResponse transform = executeScript(SCRIPT, true);
    final String tableName = newTableName();
    final SaveResponse save = saveScript(transform.getTable(), "orc", null, tableName);
    Assert.assertEquals(SaveResponse.Status.SUCCESS, save.getStatus());
    try {
        final List<HashMap<String, String>> table = getHiveQuery("SELECT * FROM " + tableName);
        Assert.assertEquals(ImmutableList.of(ImmutableMap.of("id", 1, "value", "a"), ImmutableMap.of("id", 2, "value", "b"), ImmutableMap.of("id", 3, "value", "c")), table);
    } finally {
        ssh("hive -e \"drop table " + tableName + "\"");
    }
}
Also used : SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) HashMap(java.util.HashMap) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Test(org.junit.Test)

Example 23 with TransformResponse

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

the class SparkShellProxyController method transformError.

/**
 * Generates an error response for a failed transform.
 *
 * <p>Example:
 * <code>
 * throw transformError(Response.Status.BAD_REQUEST, "transform.error", e);
 * </code></p>
 *
 * @param status HTTP response status
 * @param key    resource key or error message
 * @param cause  the cause
 * @return the error response
 */
@Nonnull
private WebApplicationException transformError(@Nonnull final Response.Status status, @Nonnull final String key, @Nullable final Throwable cause) {
    // Create entity
    final TransformResponse entity = new TransformResponse();
    entity.setStatus(TransformResponse.Status.ERROR);
    try {
        entity.setMessage(STRINGS.getString(key));
    } catch (final MissingResourceException e) {
        log.warn("Missing resource message: {}", key, e);
        entity.setMessage(key);
    }
    // Generate the response
    final Response response = Response.status(status).entity(entity).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
    if (cause != null) {
        return new WebApplicationException(cause, response);
    } else {
        return new WebApplicationException(response);
    }
}
Also used : Response(javax.ws.rs.core.Response) SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) ApiResponse(io.swagger.annotations.ApiResponse) WebApplicationException(javax.ws.rs.WebApplicationException) MissingResourceException(java.util.MissingResourceException) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Nonnull(javax.annotation.Nonnull)

Aggregations

TransformResponse (com.thinkbiganalytics.spark.rest.model.TransformResponse)23 Test (org.junit.Test)12 TransformRequest (com.thinkbiganalytics.spark.rest.model.TransformRequest)8 Nonnull (javax.annotation.Nonnull)7 Response (javax.ws.rs.core.Response)7 SaveResponse (com.thinkbiganalytics.spark.rest.model.SaveResponse)4 DataSet (com.thinkbiganalytics.spark.DataSet)3 TransformJob (com.thinkbiganalytics.spark.metadata.TransformJob)3 TransformQueryResult (com.thinkbiganalytics.spark.rest.model.TransformQueryResult)3 TransformService (com.thinkbiganalytics.spark.service.TransformService)3 InputStream (java.io.InputStream)3 List (java.util.List)3 StructType (org.apache.spark.sql.types.StructType)3 SparkContextService (com.thinkbiganalytics.spark.SparkContextService)2 SparkScriptEngine (com.thinkbiganalytics.spark.repl.SparkScriptEngine)2 MissingResourceException (java.util.MissingResourceException)2 ScriptException (javax.script.ScriptException)2 SparkContext (org.apache.spark.SparkContext)2 StorageLevel (org.apache.spark.storage.StorageLevel)2 NamedParam (scala.tools.nsc.interpreter.NamedParam)2