use of com.yahoo.elide.async.models.TableExportResult in project elide by yahoo.
the class FileResultStorageEngine method storeResults.
@Override
public TableExportResult storeResults(TableExport tableExport, Observable<String> result) {
log.debug("store TableExportResults for Download");
String extension = this.isExtensionEnabled() ? tableExport.getResultType().getFileExtensionType().getExtension() : FileExtensionType.NONE.getExtension();
TableExportResult exportResult = new TableExportResult();
try (BufferedWriter writer = getWriter(tableExport.getId(), extension)) {
result.map(record -> record.concat(System.lineSeparator())).subscribe(recordCharArray -> {
writer.write(recordCharArray);
writer.flush();
}, throwable -> {
StringBuilder message = new StringBuilder();
message.append(throwable.getClass().getCanonicalName()).append(" : ");
message.append(throwable.getMessage());
exportResult.setMessage(message.toString());
throw new IllegalStateException(STORE_ERROR, throwable);
}, writer::flush);
} catch (IOException e) {
throw new IllegalStateException(STORE_ERROR, e);
}
return exportResult;
}
use of com.yahoo.elide.async.models.TableExportResult in project elide by yahoo.
the class RedisResultStorageEngine method storeResults.
@Override
public TableExportResult storeResults(TableExport tableExport, Observable<String> result) {
log.debug("store TableExportResults for Download");
String extension = this.isExtensionEnabled() ? tableExport.getResultType().getFileExtensionType().getExtension() : FileExtensionType.NONE.getExtension();
TableExportResult exportResult = new TableExportResult();
String key = tableExport.getId() + extension;
result.map(record -> record).subscribe(recordCharArray -> {
jedis.rpush(key, recordCharArray);
}, throwable -> {
StringBuilder message = new StringBuilder();
message.append(throwable.getClass().getCanonicalName()).append(" : ");
message.append(throwable.getMessage());
exportResult.setMessage(message.toString());
throw new IllegalStateException(STORE_ERROR, throwable);
});
jedis.expire(key, expirationSeconds);
return exportResult;
}
use of com.yahoo.elide.async.models.TableExportResult in project elide by yahoo.
the class GraphQLTableExportOperationTest method testProcessMultipleQuery.
@Test
public void testProcessMultipleQuery() {
TableExport queryObj = new TableExport();
String query = "{\"query\":\"{ tableExport { edges { node { principalName } } } } { asyncQuery { edges { node { principalName } } } }\",\"variables\":null}";
String id = "edc4a871-dff2-4094-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
GraphQLTableExportOperation graphQLOperation = new GraphQLTableExportOperation(new JSONExportFormatter(elide), asyncExecutorService, queryObj, requestScope, engine);
TableExportResult queryResultObj = (TableExportResult) graphQLOperation.call();
assertEquals(200, queryResultObj.getHttpStatus());
assertEquals("Export is only supported for single Query with one root projection.", queryResultObj.getMessage());
assertNull(queryResultObj.getRecordCount());
assertNull(queryResultObj.getUrl());
}
use of com.yahoo.elide.async.models.TableExportResult in project elide by yahoo.
the class GraphQLTableExportOperationTest method testProcessQuery.
@Test
public void testProcessQuery() throws IOException {
dataPrep();
TableExport queryObj = new TableExport();
String query = "{\"query\":\"{ tableExport { edges { node { id principalName} } } }\",\"variables\":null}";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
GraphQLTableExportOperation graphQLOperation = new GraphQLTableExportOperation(new JSONExportFormatter(elide), asyncExecutorService, queryObj, requestScope, engine);
TableExportResult queryResultObj = (TableExportResult) graphQLOperation.call();
assertEquals(200, queryResultObj.getHttpStatus());
assertEquals("https://elide.io/export/edc4a871-dff2-4054-804e-d80075cf827d", queryResultObj.getUrl().toString());
assertEquals(1, queryResultObj.getRecordCount());
}
use of com.yahoo.elide.async.models.TableExportResult in project elide by yahoo.
the class GraphQLTableExportOperationTest method testProcessBadEntityQuery.
@Test
public void testProcessBadEntityQuery() throws IOException {
dataPrep();
TableExport queryObj = new TableExport();
String query = "{\"query\":\"{ tableExportInvalid { edges { node { id principalName} } } }\",\"variables\":null}";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
GraphQLTableExportOperation graphQLOperation = new GraphQLTableExportOperation(new JSONExportFormatter(elide), asyncExecutorService, queryObj, requestScope, engine);
TableExportResult queryResultObj = (TableExportResult) graphQLOperation.call();
assertEquals(200, queryResultObj.getHttpStatus());
assertEquals("Bad Request Body'Unknown entity {tableExportInvalid}.'", queryResultObj.getMessage());
}
Aggregations