use of io.hetu.core.plugin.datacenter.DataCenterColumn in project hetu-core by openlookeng.
the class DataCenterClient method getColumns.
/**
* Get the columns information of this sql.
*
* @param sql statement.
* @return the list of data center column that this sql contains.
*/
public List<DataCenterColumn> getColumns(String sql) {
String query = "PREPARE subStatement FROM " + sql;
String describe = "DESCRIBE OUTPUT subStatement";
try (StatementClient preparedClient = execute(query)) {
DataCenterClientSession newClientSession = DataCenterStatementClientFactory.createClientSession(preparedClient, this.config, this.typeManager);
ImmutableList.Builder<DataCenterColumn> builder = new ImmutableList.Builder<>();
Iterable<List<Object>> data = getResults(newClientSession, describe);
for (List<Object> row : data) {
String name = row.get(0).toString();
String type = row.get(TYPE_POSITION).toString();
if ("unknown".equalsIgnoreCase(type)) {
// Cannot support unknown types
return Collections.emptyList();
}
try {
builder.add(new DataCenterColumn(name, parseType(typeManager, type)));
} catch (IllegalArgumentException ex) {
return Collections.emptyList();
}
}
return builder.build();
} catch (SQLException ex) {
return Collections.emptyList();
}
}
Aggregations