Search in sources :

Example 6 with QueryableTable

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

the class RelOptTableImpl method toRel.

public RelNode toRel(ToRelContext context) {
    // RelOptTable by replacing with immutable RelRecordType using the same field list.
    if (this.getRowType().isDynamicStruct()) {
        final RelDataType staticRowType = new RelRecordType(getRowType().getFieldList());
        final RelOptTable relOptTable = this.copy(staticRowType);
        return relOptTable.toRel(context);
    }
    // If there are any virtual columns, create a copy of this table without
    // those virtual columns.
    final List<ColumnStrategy> strategies = getColumnStrategies();
    if (strategies.contains(ColumnStrategy.VIRTUAL)) {
        final RelDataTypeFactory.Builder b = context.getCluster().getTypeFactory().builder();
        for (RelDataTypeField field : rowType.getFieldList()) {
            if (strategies.get(field.getIndex()) != ColumnStrategy.VIRTUAL) {
                b.add(field.getName(), field.getType());
            }
        }
        final RelOptTable relOptTable = new RelOptTableImpl(this.schema, b.build(), this.names, this.table, this.expressionFunction, this.rowCount) {

            @Override
            public <T> T unwrap(Class<T> clazz) {
                if (clazz.isAssignableFrom(InitializerExpressionFactory.class)) {
                    return clazz.cast(NullInitializerExpressionFactory.INSTANCE);
                }
                return super.unwrap(clazz);
            }
        };
        return relOptTable.toRel(context);
    }
    if (table instanceof TranslatableTable) {
        return ((TranslatableTable) table).toRel(context, this);
    }
    final RelOptCluster cluster = context.getCluster();
    if (Hook.ENABLE_BINDABLE.get(false)) {
        return LogicalTableScan.create(cluster, this);
    }
    if (CalcitePrepareImpl.ENABLE_ENUMERABLE && table instanceof QueryableTable) {
        return EnumerableTableScan.create(cluster, this);
    }
    if (table instanceof ScannableTable || table instanceof FilterableTable || table instanceof ProjectableFilterableTable) {
        return LogicalTableScan.create(cluster, this);
    }
    if (CalcitePrepareImpl.ENABLE_ENUMERABLE) {
        return EnumerableTableScan.create(cluster, this);
    }
    throw new AssertionError();
}
Also used : ColumnStrategy(org.apache.calcite.schema.ColumnStrategy) RelOptCluster(org.apache.calcite.plan.RelOptCluster) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) FilterableTable(org.apache.calcite.schema.FilterableTable) RelDataType(org.apache.calcite.rel.type.RelDataType) RelRecordType(org.apache.calcite.rel.type.RelRecordType) QueryableTable(org.apache.calcite.schema.QueryableTable) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) TranslatableTable(org.apache.calcite.schema.TranslatableTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) RelOptTable(org.apache.calcite.plan.RelOptTable) ScannableTable(org.apache.calcite.schema.ScannableTable)

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