Search in sources :

Example 11 with Column

use of io.prestosql.client.Column 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)

Aggregations

Column (io.prestosql.client.Column)11 StringWriter (java.io.StringWriter)5 Test (org.testng.annotations.Test)5 ImmutableList (com.google.common.collect.ImmutableList)4 QueryData (io.prestosql.client.QueryData)2 QueryStatusInfo (io.prestosql.client.QueryStatusInfo)2 List (java.util.List)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ErrorLocation (io.prestosql.client.ErrorLocation)1 QueryError (io.prestosql.client.QueryError)1 StatementClient (io.prestosql.client.StatementClient)1 QueryStats (io.prestosql.execution.QueryStats)1 TaskLocation (io.prestosql.operator.TaskLocation)1 ExecutionFailureException (io.prestosql.queryeditorui.execution.ExecutionClient.ExecutionFailureException)1 QueryClient (io.prestosql.queryeditorui.execution.QueryClient)1 QueryTimeOutException (io.prestosql.queryeditorui.execution.QueryClient.QueryTimeOutException)1 BasicQueryInfo (io.prestosql.queryeditorui.execution.QueryInfoClient.BasicQueryInfo)1 QueryRunner (io.prestosql.queryeditorui.execution.QueryRunner)1 FileTooLargeException (io.prestosql.queryeditorui.output.builders.FileTooLargeException)1 JobOutputBuilder (io.prestosql.queryeditorui.output.builders.JobOutputBuilder)1