Search in sources :

Example 1 with QueryRunner

use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.

the class SchemaService method querySchemas.

public CatalogSchema querySchemas(String catalogName, String user) {
    QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
    String statement = format("SHOW SCHEMAS FROM %s", catalogName);
    Set<String> schemasResult = queryStatement(queryRunner, statement);
    return new CatalogSchema(catalogName, ImmutableList.copyOf(schemasResult));
}
Also used : CatalogSchema(io.prestosql.queryeditorui.protocol.CatalogSchema) QueryRunner(io.prestosql.queryeditorui.execution.QueryRunner)

Example 2 with QueryRunner

use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.

the class ColumnService method queryColumns.

private List<Column> queryColumns(String fqnTableName, String user) {
    String statement = format("SHOW COLUMNS FROM %s", fqnTableName);
    QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
    QueryClient queryClient = new QueryClient(queryRunner, Duration.standardSeconds(60), statement);
    final ImmutableList.Builder<Column> cache = ImmutableList.builder();
    try {
        queryClient.executeWith(new Function<StatementClient, Void>() {

            @Nullable
            @Override
            public Void apply(StatementClient client) {
                QueryData results = client.currentData();
                if (results.getData() != null) {
                    for (List<Object> row : results.getData()) {
                        TypeSignature typeSignature = TypeSignature.parseTypeSignature((String) row.get(1));
                        Column column = new Column((String) row.get(0), (String) row.get(1), Query.toClientTypeSignature(typeSignature));
                        cache.add(column);
                    }
                }
                return null;
            }
        });
    } catch (QueryClient.QueryTimeOutException e) {
        log.error("Caught timeout loading columns", e);
    }
    return cache.build();
}
Also used : QueryData(io.prestosql.client.QueryData) ImmutableList(com.google.common.collect.ImmutableList) StatementClient(io.prestosql.client.StatementClient) QueryRunner(io.prestosql.queryeditorui.execution.QueryRunner) QueryClient(io.prestosql.queryeditorui.execution.QueryClient) TypeSignature(io.prestosql.spi.type.TypeSignature) Column(io.prestosql.client.Column) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Nullable(javax.annotation.Nullable)

Example 3 with QueryRunner

use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.

the class PreviewTableService method queryRows.

private List<List<Object>> queryRows(String fqnTableName, String user) {
    String statement = format("SELECT * FROM %s LIMIT %d", fqnTableName, PREVIEW_LIMIT);
    QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
    QueryClient queryClient = new QueryClient(queryRunner, Duration.standardSeconds(60), statement);
    final ImmutableList.Builder<List<Object>> cache = ImmutableList.builder();
    try {
        queryClient.executeWith(new Function<StatementClient, Void>() {

            @Nullable
            @Override
            public Void apply(StatementClient client) {
                QueryData results = client.currentData();
                if (results.getData() != null) {
                    List<List<Object>> resultsData = ImmutableList.copyOf(results.getData());
                    for (List<Object> row : resultsData) {
                        final String[] values = new String[row.size()];
                        for (int i = 0; i < values.length; i++) {
                            // Display byte array as Hexadecimal in order to keep consistent with OpenLooKeng client
                            if (row.get(i) instanceof byte[]) {
                                byte[] bytes = (byte[]) row.get(i);
                                StringBuilder sb = new StringBuilder();
                                for (byte b : bytes) {
                                    String hex = Integer.toHexString(b & 0xFF);
                                    if (hex.length() < 2) {
                                        sb.append(0);
                                    }
                                    sb.append(hex);
                                }
                                values[i] = sb.toString();
                            } else {
                                final Object value = row.get(i);
                                values[i] = (value == null) ? "" : value.toString();
                            }
                        }
                        cache.add(Arrays.asList(values));
                    }
                }
                return null;
            }
        });
    } catch (QueryClient.QueryTimeOutException e) {
        log.error("Caught timeout loading columns", e);
    }
    return cache.build();
}
Also used : QueryData(io.prestosql.client.QueryData) ImmutableList(com.google.common.collect.ImmutableList) StatementClient(io.prestosql.client.StatementClient) QueryRunner(io.prestosql.queryeditorui.execution.QueryRunner) QueryClient(io.prestosql.queryeditorui.execution.QueryClient) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Nullable(javax.annotation.Nullable)

Example 4 with QueryRunner

use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.

the class SchemaService method queryCatalogs.

public Set<String> queryCatalogs(String user) {
    QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
    String statement = "SHOW CATALOGS";
    return queryStatement(queryRunner, statement);
}
Also used : QueryRunner(io.prestosql.queryeditorui.execution.QueryRunner)

Example 5 with QueryRunner

use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.

the class SchemaService method queryTables.

public ImmutableList<Table> queryTables(String catalogName, String schemaName, String user) {
    QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
    String statement = format("SHOW TABLES FROM %s.%s", catalogName, schemaName);
    Set<String> tablesResult = queryStatement(queryRunner, statement);
    final ImmutableList.Builder<Table> builder = ImmutableList.builder();
    for (String tableName : tablesResult) {
        builder.add(new Table(catalogName, schemaName, tableName));
    }
    return builder.build();
}
Also used : Table(io.prestosql.queryeditorui.protocol.Table) ImmutableList(com.google.common.collect.ImmutableList) QueryRunner(io.prestosql.queryeditorui.execution.QueryRunner)

Aggregations

QueryRunner (io.prestosql.queryeditorui.execution.QueryRunner)5 ImmutableList (com.google.common.collect.ImmutableList)3 QueryData (io.prestosql.client.QueryData)2 StatementClient (io.prestosql.client.StatementClient)2 QueryClient (io.prestosql.queryeditorui.execution.QueryClient)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 Column (io.prestosql.client.Column)1 CatalogSchema (io.prestosql.queryeditorui.protocol.CatalogSchema)1 Table (io.prestosql.queryeditorui.protocol.Table)1 TypeSignature (io.prestosql.spi.type.TypeSignature)1