Search in sources :

Example 1 with MetadataMapper

use of org.apache.drill.metastore.rdbms.transform.MetadataMapper in project drill by apache.

the class RdbmsRead method internalExecute.

@Override
protected List<T> internalExecute() {
    Set<MetadataMapper<T, ? extends Record>> mappers = context.transformer().toMappers(metadataTypes);
    if (mappers.isEmpty()) {
        return Collections.emptyList();
    }
    List<T> units = new ArrayList<>();
    try (DSLContext executor = context.executorProvider().executor()) {
        for (MetadataMapper<T, ? extends Record> mapper : mappers) {
            Condition condition = mapper.toCondition(filter);
            logger.debug("Query data from RDBMS Metastore table {} using condition: {}", mapper.table(), condition);
            List<Field<?>> fields = columns.isEmpty() ? Arrays.asList(mapper.table().fields()) : mapper.toFields(columns);
            try {
                if (fields.isEmpty()) {
                    units.addAll(countRecords(executor, mapper, condition));
                } else {
                    units.addAll(queryRecords(executor, mapper, fields, condition));
                }
            } catch (DataAccessException e) {
                throw new RdbmsMetastoreException("Error when reading data from Metastore: " + e.getMessage(), e);
            }
        }
        return units;
    }
}
Also used : Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) DSLContext(org.jooq.DSLContext) MetadataMapper(org.apache.drill.metastore.rdbms.transform.MetadataMapper) Field(org.jooq.Field) RdbmsMetastoreException(org.apache.drill.metastore.rdbms.exception.RdbmsMetastoreException) Record(org.jooq.Record) DataAccessException(org.jooq.exception.DataAccessException)

Aggregations

ArrayList (java.util.ArrayList)1 RdbmsMetastoreException (org.apache.drill.metastore.rdbms.exception.RdbmsMetastoreException)1 MetadataMapper (org.apache.drill.metastore.rdbms.transform.MetadataMapper)1 Condition (org.jooq.Condition)1 DSLContext (org.jooq.DSLContext)1 Field (org.jooq.Field)1 Record (org.jooq.Record)1 DataAccessException (org.jooq.exception.DataAccessException)1