Search in sources :

Example 1 with HiveColumn

use of com.airbnb.airpal.presto.hive.HiveColumn in project airpal by airbnb.

the class ColumnCache method queryColumns.

private List<HiveColumn> queryColumns(String query) {
    final ImmutableList.Builder<HiveColumn> cache = ImmutableList.builder();
    QueryRunner queryRunner = queryRunnerFactory.create();
    QueryClient queryClient = new QueryClient(queryRunner, io.dropwizard.util.Duration.seconds(60), query);
    try {
        queryClient.executeWith(new Function<StatementClient, Void>() {

            @Nullable
            @Override
            public Void apply(StatementClient client) {
                QueryResults results = client.current();
                if (results.getData() != null) {
                    for (List<Object> row : results.getData()) {
                        Column column = new Column((String) row.get(0), (String) row.get(1), new ClientTypeSignature(TypeSignature.parseTypeSignature((String) row.get(1))));
                        boolean isNullable = (Boolean) row.get(2);
                        boolean isPartition = (Boolean) row.get(3);
                        cache.add(HiveColumn.fromColumn(column, isNullable, isPartition));
                    }
                }
                return null;
            }
        });
    } catch (QueryClient.QueryTimeOutException e) {
        log.error("Caught timeout loading columns", e);
    }
    return cache.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) StatementClient(com.facebook.presto.client.StatementClient) QueryRunner(com.airbnb.airpal.presto.QueryRunner) QueryResults(com.facebook.presto.client.QueryResults) QueryClient(com.airbnb.airpal.core.execution.QueryClient) Column(com.facebook.presto.client.Column) HiveColumn(com.airbnb.airpal.presto.hive.HiveColumn) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HiveColumn(com.airbnb.airpal.presto.hive.HiveColumn) ClientTypeSignature(com.facebook.presto.client.ClientTypeSignature) Nullable(javax.annotation.Nullable)

Aggregations

QueryClient (com.airbnb.airpal.core.execution.QueryClient)1 QueryRunner (com.airbnb.airpal.presto.QueryRunner)1 HiveColumn (com.airbnb.airpal.presto.hive.HiveColumn)1 ClientTypeSignature (com.facebook.presto.client.ClientTypeSignature)1 Column (com.facebook.presto.client.Column)1 QueryResults (com.facebook.presto.client.QueryResults)1 StatementClient (com.facebook.presto.client.StatementClient)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1