use of com.airbnb.airpal.core.execution.QueryClient 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.core.execution.QueryClient 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();
}
use of com.airbnb.airpal.core.execution.QueryClient in project airpal by airbnb.
the class SchemaCache method queryMetadata.
private Map<String, List<String>> queryMetadata(String query) {
final Map<String, List<String>> cache = 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) {
for (List<Object> row : results.getData()) {
String schema = (String) row.get(1);
String table = (String) row.get(2);
if (EXCLUDED_SCHEMAS.contains(schema)) {
continue;
}
List<String> tables = cache.get(schema);
if (tables == null) {
tables = Lists.newArrayList();
cache.put(schema, tables);
}
tables.add(table);
}
}
return null;
}
});
} catch (QueryClient.QueryTimeOutException e) {
log.error("Caught timeout loading columns", e);
}
return ImmutableMap.copyOf(cache);
}
use of com.airbnb.airpal.core.execution.QueryClient in project airpal by airbnb.
the class PreviewTableCache method queryRows.
private List<List<Object>> queryRows(String query) {
final ImmutableList.Builder<List<Object>> 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) {
cache.addAll(results.getData());
}
return null;
}
});
} catch (QueryClient.QueryTimeOutException e) {
log.error("Caught timeout loading columns", e);
}
return cache.build();
}
Aggregations