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();
}
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();
}
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);
}
Aggregations