use of io.prestosql.queryeditorui.execution.QueryClient 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.QueryClient 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.QueryClient in project hetu-core by openlookeng.
the class SchemaService method queryStatement.
private Set<String> queryStatement(QueryRunner queryRunner, String statement) {
QueryClient queryClient = new QueryClient(queryRunner, Duration.standardSeconds(120), statement);
final Set<String> resultSet = new HashSet();
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()) {
resultSet.add((String) row.get(0));
}
}
return null;
}
});
} catch (QueryClient.QueryTimeOutException e) {
LOG.error("Caught timeout loading data", e);
}
return resultSet;
}
Aggregations