Search in sources :

Example 1 with DataCenterColumn

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();
    }
}
Also used : DataCenterColumn(io.hetu.core.plugin.datacenter.DataCenterColumn) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) StatementClient(io.prestosql.client.StatementClient) DataCenterStatementClient(io.prestosql.client.DataCenterStatementClient) DataCenterClientSession(io.prestosql.client.DataCenterClientSession) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 DataCenterColumn (io.hetu.core.plugin.datacenter.DataCenterColumn)1 DataCenterClientSession (io.prestosql.client.DataCenterClientSession)1 DataCenterStatementClient (io.prestosql.client.DataCenterStatementClient)1 StatementClient (io.prestosql.client.StatementClient)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1