Search in sources :

Example 1 with QueryableTable

use of org.apache.calcite.schema.QueryableTable in project calcite by apache.

the class CloneSchema method getTableMap.

@Override
protected Map<String, Table> getTableMap() {
    final Map<String, Table> map = new LinkedHashMap<>();
    for (String name : sourceSchema.getTableNames()) {
        final Table table = sourceSchema.getTable(name);
        if (table instanceof QueryableTable) {
            final QueryableTable sourceTable = (QueryableTable) table;
            map.put(name, createCloneTable(MATERIALIZATION_CONNECTION, sourceTable, name));
        }
    }
    return map;
}
Also used : QueryableTable(org.apache.calcite.schema.QueryableTable) QueryableTable(org.apache.calcite.schema.QueryableTable) Table(org.apache.calcite.schema.Table) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with QueryableTable

use of org.apache.calcite.schema.QueryableTable in project calcite by apache.

the class TableScanNode method create.

/**
 * Creates a TableScanNode.
 *
 * <p>Tries various table SPIs, and negotiates with the table which filters
 * and projects it can implement. Adds to the Enumerable implementations of
 * any filters and projects that cannot be implemented by the table.
 */
static TableScanNode create(Compiler compiler, TableScan rel, ImmutableList<RexNode> filters, ImmutableIntList projects) {
    final RelOptTable relOptTable = rel.getTable();
    final ProjectableFilterableTable pfTable = relOptTable.unwrap(ProjectableFilterableTable.class);
    if (pfTable != null) {
        return createProjectableFilterable(compiler, rel, filters, projects, pfTable);
    }
    final FilterableTable filterableTable = relOptTable.unwrap(FilterableTable.class);
    if (filterableTable != null) {
        return createFilterable(compiler, rel, filters, projects, filterableTable);
    }
    final ScannableTable scannableTable = relOptTable.unwrap(ScannableTable.class);
    if (scannableTable != null) {
        return createScannable(compiler, rel, filters, projects, scannableTable);
    }
    // noinspection unchecked
    final Enumerable<Row> enumerable = relOptTable.unwrap(Enumerable.class);
    if (enumerable != null) {
        return createEnumerable(compiler, rel, enumerable, null, filters, projects);
    }
    final QueryableTable queryableTable = relOptTable.unwrap(QueryableTable.class);
    if (queryableTable != null) {
        return createQueryable(compiler, rel, filters, projects, queryableTable);
    }
    throw new AssertionError("cannot convert table " + relOptTable + " to enumerable");
}
Also used : QueryableTable(org.apache.calcite.schema.QueryableTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) FilterableTable(org.apache.calcite.schema.FilterableTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) RelOptTable(org.apache.calcite.plan.RelOptTable) ScannableTable(org.apache.calcite.schema.ScannableTable)

Example 3 with QueryableTable

use of org.apache.calcite.schema.QueryableTable in project calcite by apache.

the class EnumerableTableScan method deduceElementType.

public static Class deduceElementType(Table table) {
    if (table instanceof QueryableTable) {
        final QueryableTable queryableTable = (QueryableTable) table;
        final Type type = queryableTable.getElementType();
        if (type instanceof Class) {
            return (Class) type;
        } else {
            return Object[].class;
        }
    } else if (table instanceof ScannableTable || table instanceof FilterableTable || table instanceof ProjectableFilterableTable || table instanceof StreamableTable) {
        return Object[].class;
    } else {
        return Object.class;
    }
}
Also used : QueryableTable(org.apache.calcite.schema.QueryableTable) RelDataType(org.apache.calcite.rel.type.RelDataType) Type(java.lang.reflect.Type) StreamableTable(org.apache.calcite.schema.StreamableTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) FilterableTable(org.apache.calcite.schema.FilterableTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) ScannableTable(org.apache.calcite.schema.ScannableTable)

Example 4 with QueryableTable

use of org.apache.calcite.schema.QueryableTable in project calcite by apache.

the class CloneSchema method createCloneTable.

public static <T> Table createCloneTable(final JavaTypeFactory typeFactory, final RelProtoDataType protoRowType, final List<RelCollation> collations, final List<ColumnMetaData.Rep> repList, final Enumerable<T> source) {
    final Type elementType;
    if (source instanceof QueryableTable) {
        elementType = ((QueryableTable) source).getElementType();
    } else if (protoRowType.apply(typeFactory).getFieldCount() == 1) {
        if (repList != null) {
            elementType = repList.get(0).clazz;
        } else {
            elementType = Object.class;
        }
    } else {
        elementType = Object[].class;
    }
    return new ArrayTable(elementType, protoRowType, Suppliers.memoize(new Supplier<ArrayTable.Content>() {

        public ArrayTable.Content get() {
            final ColumnLoader loader = new ColumnLoader<>(typeFactory, source, protoRowType, repList);
            final List<RelCollation> collation2 = collations.isEmpty() && loader.sortField >= 0 ? RelCollations.createSingleton(loader.sortField) : collations;
            return new ArrayTable.Content(loader.representationValues, loader.size(), collation2);
        }
    }));
}
Also used : QueryableTable(org.apache.calcite.schema.QueryableTable) RelProtoDataType(org.apache.calcite.rel.type.RelProtoDataType) Type(java.lang.reflect.Type) RelCollation(org.apache.calcite.rel.RelCollation) Supplier(com.google.common.base.Supplier)

Example 5 with QueryableTable

use of org.apache.calcite.schema.QueryableTable in project calcite by apache.

the class QueryableRelBuilder method toRel.

RelNode toRel(Queryable<T> queryable) {
    if (queryable instanceof QueryableDefaults.Replayable) {
        // noinspection unchecked
        ((QueryableDefaults.Replayable) queryable).replay(this);
        return rel;
    }
    if (queryable instanceof AbstractTableQueryable) {
        final AbstractTableQueryable tableQueryable = (AbstractTableQueryable) queryable;
        final QueryableTable table = tableQueryable.table;
        final CalciteSchema.TableEntry tableEntry = CalciteSchema.from(tableQueryable.schema).add(tableQueryable.tableName, tableQueryable.table);
        final RelOptTableImpl relOptTable = RelOptTableImpl.create(null, table.getRowType(translator.typeFactory), tableEntry, null);
        if (table instanceof TranslatableTable) {
            return ((TranslatableTable) table).toRel(translator, relOptTable);
        } else {
            return LogicalTableScan.create(translator.cluster, relOptTable);
        }
    }
    return translator.translate(queryable.getExpression());
}
Also used : QueryableTable(org.apache.calcite.schema.QueryableTable) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) TranslatableTable(org.apache.calcite.schema.TranslatableTable) AbstractTableQueryable(org.apache.calcite.schema.impl.AbstractTableQueryable)

Aggregations

QueryableTable (org.apache.calcite.schema.QueryableTable)6 FilterableTable (org.apache.calcite.schema.FilterableTable)3 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)3 ScannableTable (org.apache.calcite.schema.ScannableTable)3 Type (java.lang.reflect.Type)2 RelOptTable (org.apache.calcite.plan.RelOptTable)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 TranslatableTable (org.apache.calcite.schema.TranslatableTable)2 Supplier (com.google.common.base.Supplier)1 LinkedHashMap (java.util.LinkedHashMap)1 CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelCollation (org.apache.calcite.rel.RelCollation)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 RelProtoDataType (org.apache.calcite.rel.type.RelProtoDataType)1 RelRecordType (org.apache.calcite.rel.type.RelRecordType)1 ColumnStrategy (org.apache.calcite.schema.ColumnStrategy)1 StreamableTable (org.apache.calcite.schema.StreamableTable)1 Table (org.apache.calcite.schema.Table)1