Search in sources :

Example 1 with HivePartition

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

the class TablesResource method getPartitionsWithMetaData.

private List<HivePartitionItem> getPartitionsWithMetaData(PartitionedTable table) throws ExecutionException {
    List<HivePartition> partitions = columnCache.getPartitions(table.getSchema(), table.getTable());
    ImmutableList.Builder<HivePartitionItem> partitionItems = ImmutableList.builder();
    for (HivePartition partition : partitions) {
        for (Object value : partition.getValues()) {
            PartitionedTable partitionedTable = table.withPartitionName(HivePartition.getPartitionId(partition.getName(), value));
            DateTime updatedAt = null;
            partitionItems.add(new HivePartitionItem(partition.getName(), partition.getType(), value, updatedAt));
        }
    }
    return partitionItems.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) HivePartitionItem(com.airbnb.airpal.presto.hive.HivePartition.HivePartitionItem) DateTime(org.joda.time.DateTime) HivePartition(com.airbnb.airpal.presto.hive.HivePartition)

Example 2 with HivePartition

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

the class ColumnCache method queryPartitions.

private List<HivePartition> queryPartitions(String query) {
    final ImmutableList.Builder<HivePartition> cache = ImmutableList.builder();
    final Map<Column, List<Object>> objects = Maps.newHashMap();
    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 && results.getColumns() != null) {
                    final List<Column> columns = results.getColumns();
                    for (Column column : columns) {
                        objects.put(column, Lists.newArrayList());
                    }
                    for (List<Object> row : results.getData()) {
                        for (int i = 0; i < row.size(); i++) {
                            Column column = columns.get(i);
                            objects.get(column).add(row.get(i));
                        }
                    }
                }
                return null;
            }
        });
    } catch (QueryClient.QueryTimeOutException e) {
        log.error("Caught timeout loading columns", e);
    }
    for (Map.Entry<Column, List<Object>> entry : objects.entrySet()) {
        cache.add(HivePartition.fromColumn(entry.getKey(), entry.getValue()));
    }
    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) Map(java.util.Map) Nullable(javax.annotation.Nullable) HivePartition(com.airbnb.airpal.presto.hive.HivePartition)

Example 3 with HivePartition

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

the class PreviewTableCache method buildQueryWithLimit.

private static String buildQueryWithLimit(PartitionedTableWithValue tableWithValue, int limit) {
    Table table = tableWithValue.getTable();
    HivePartition partition = tableWithValue.getPartition().orNull();
    String partitionClause = "";
    if (partition != null) {
        String value = tableWithValue.getValue();
        String partitionValue = (Objects.equals(partition.getType(), "varchar")) ? "'" + value + "'" : String.valueOf(value);
        partitionClause = format("WHERE %s = %s", partition.getName(), partitionValue);
    }
    return format("SELECT * FROM %s %s LIMIT %d", Util.fqn(table.getConnectorId(), table.getSchema(), table.getTable()), partitionClause, limit);
}
Also used : Table(com.airbnb.airpal.presto.Table) HivePartition(com.airbnb.airpal.presto.hive.HivePartition)

Aggregations

HivePartition (com.airbnb.airpal.presto.hive.HivePartition)3 ImmutableList (com.google.common.collect.ImmutableList)2 QueryClient (com.airbnb.airpal.core.execution.QueryClient)1 PartitionedTable (com.airbnb.airpal.presto.PartitionedTable)1 QueryRunner (com.airbnb.airpal.presto.QueryRunner)1 Table (com.airbnb.airpal.presto.Table)1 HiveColumn (com.airbnb.airpal.presto.hive.HiveColumn)1 HivePartitionItem (com.airbnb.airpal.presto.hive.HivePartition.HivePartitionItem)1 Column (com.facebook.presto.client.Column)1 QueryResults (com.facebook.presto.client.QueryResults)1 StatementClient (com.facebook.presto.client.StatementClient)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 DateTime (org.joda.time.DateTime)1