use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.
the class SchemaService method querySchemas.
public CatalogSchema querySchemas(String catalogName, String user) {
QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
String statement = format("SHOW SCHEMAS FROM %s", catalogName);
Set<String> schemasResult = queryStatement(queryRunner, statement);
return new CatalogSchema(catalogName, ImmutableList.copyOf(schemasResult));
}
use of io.prestosql.queryeditorui.execution.QueryRunner 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();
}
use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.
the class PreviewTableService method queryRows.
private List<List<Object>> queryRows(String fqnTableName, String user) {
String statement = format("SELECT * FROM %s LIMIT %d", fqnTableName, PREVIEW_LIMIT);
QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
QueryClient queryClient = new QueryClient(queryRunner, Duration.standardSeconds(60), statement);
final ImmutableList.Builder<List<Object>> 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) {
List<List<Object>> resultsData = ImmutableList.copyOf(results.getData());
for (List<Object> row : resultsData) {
final String[] values = new String[row.size()];
for (int i = 0; i < values.length; i++) {
// Display byte array as Hexadecimal in order to keep consistent with OpenLooKeng client
if (row.get(i) instanceof byte[]) {
byte[] bytes = (byte[]) row.get(i);
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(b & 0xFF);
if (hex.length() < 2) {
sb.append(0);
}
sb.append(hex);
}
values[i] = sb.toString();
} else {
final Object value = row.get(i);
values[i] = (value == null) ? "" : value.toString();
}
}
cache.add(Arrays.asList(values));
}
}
return null;
}
});
} catch (QueryClient.QueryTimeOutException e) {
log.error("Caught timeout loading columns", e);
}
return cache.build();
}
use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.
the class SchemaService method queryCatalogs.
public Set<String> queryCatalogs(String user) {
QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
String statement = "SHOW CATALOGS";
return queryStatement(queryRunner, statement);
}
use of io.prestosql.queryeditorui.execution.QueryRunner in project hetu-core by openlookeng.
the class SchemaService method queryTables.
public ImmutableList<Table> queryTables(String catalogName, String schemaName, String user) {
QueryRunner queryRunner = queryRunnerFactory.create(QueryEditorUIModule.UI_QUERY_SOURCE, user);
String statement = format("SHOW TABLES FROM %s.%s", catalogName, schemaName);
Set<String> tablesResult = queryStatement(queryRunner, statement);
final ImmutableList.Builder<Table> builder = ImmutableList.builder();
for (String tableName : tablesResult) {
builder.add(new Table(catalogName, schemaName, tableName));
}
return builder.build();
}
Aggregations