Search in sources :

Example 1 with TableExportResult

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;
}
Also used : Setter(lombok.Setter) FileExtensionType(com.yahoo.elide.async.models.FileExtensionType) Getter(lombok.Getter) Iterator(java.util.Iterator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) IOException(java.io.IOException) Singleton(javax.inject.Singleton) File(java.io.File) TableExportResult(com.yahoo.elide.async.models.TableExportResult) Slf4j(lombok.extern.slf4j.Slf4j) Paths(java.nio.file.Paths) Observable(io.reactivex.Observable) BufferedReader(java.io.BufferedReader) TableExport(com.yahoo.elide.async.models.TableExport) IOException(java.io.IOException) TableExportResult(com.yahoo.elide.async.models.TableExportResult) BufferedWriter(java.io.BufferedWriter)

Example 2 with TableExportResult

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;
}
Also used : TableExportResult(com.yahoo.elide.async.models.TableExportResult) Setter(lombok.Setter) Slf4j(lombok.extern.slf4j.Slf4j) UnifiedJedis(redis.clients.jedis.UnifiedJedis) FileExtensionType(com.yahoo.elide.async.models.FileExtensionType) Getter(lombok.Getter) Iterator(java.util.Iterator) Observable(io.reactivex.Observable) Singleton(javax.inject.Singleton) TableExport(com.yahoo.elide.async.models.TableExport) TableExportResult(com.yahoo.elide.async.models.TableExportResult)

Example 3 with TableExportResult

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());
}
Also used : TableExport(com.yahoo.elide.async.models.TableExport) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) TableExportResult(com.yahoo.elide.async.models.TableExportResult) Test(org.junit.jupiter.api.Test)

Example 4 with TableExportResult

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());
}
Also used : TableExport(com.yahoo.elide.async.models.TableExport) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) TableExportResult(com.yahoo.elide.async.models.TableExportResult) Test(org.junit.jupiter.api.Test)

Example 5 with TableExportResult

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());
}
Also used : TableExport(com.yahoo.elide.async.models.TableExport) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) TableExportResult(com.yahoo.elide.async.models.TableExportResult) Test(org.junit.jupiter.api.Test)

Aggregations

TableExport (com.yahoo.elide.async.models.TableExport)13 TableExportResult (com.yahoo.elide.async.models.TableExportResult)13 JSONExportFormatter (com.yahoo.elide.async.export.formatter.JSONExportFormatter)10 Test (org.junit.jupiter.api.Test)10 FileExtensionType (com.yahoo.elide.async.models.FileExtensionType)3 Observable (io.reactivex.Observable)3 Getter (lombok.Getter)3 Slf4j (lombok.extern.slf4j.Slf4j)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 Singleton (javax.inject.Singleton)2 Setter (lombok.Setter)2 Elide (com.yahoo.elide.Elide)1 TableExportFormatter (com.yahoo.elide.async.export.formatter.TableExportFormatter)1 SingleRootProjectionValidator (com.yahoo.elide.async.export.validator.SingleRootProjectionValidator)1 Validator (com.yahoo.elide.async.export.validator.Validator)1 AsyncAPI (com.yahoo.elide.async.models.AsyncAPI)1 AsyncAPIResult (com.yahoo.elide.async.models.AsyncAPIResult)1 AsyncExecutorService (com.yahoo.elide.async.service.AsyncExecutorService)1 ResultStorageEngine (com.yahoo.elide.async.service.storageengine.ResultStorageEngine)1