Search in sources :

Example 36 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project hazelcast by hazelcast.

the class UpdateByKeyMapLogicalRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    TableModifyLogicalRel update = call.rel(0);
    FullScanLogicalRel scan = call.rel(1);
    RelOptTable table = scan.getTable();
    RexNode keyCondition = OptUtils.extractKeyConstantExpression(table, update.getCluster().getRexBuilder());
    if (keyCondition != null) {
        UpdateByKeyMapLogicalRel rel = new UpdateByKeyMapLogicalRel(update.getCluster(), OptUtils.toLogicalConvention(update.getTraitSet()), table, keyCondition, update.getUpdateColumnList(), update.getSourceExpressionList());
        call.transformTo(rel);
    }
}
Also used : RelOptTable(org.apache.calcite.plan.RelOptTable) RexNode(org.apache.calcite.rex.RexNode)

Example 37 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project hazelcast by hazelcast.

the class DeleteByKeyMapLogicalRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    TableModify delete = call.rel(0);
    TableScan scan = call.rel(1);
    RelOptTable table = scan.getTable();
    RexNode keyCondition = OptUtils.extractKeyConstantExpression(table, delete.getCluster().getRexBuilder());
    if (keyCondition != null) {
        DeleteByKeyMapLogicalRel rel = new DeleteByKeyMapLogicalRel(delete.getCluster(), OptUtils.toLogicalConvention(delete.getTraitSet()), table, keyCondition);
        call.transformTo(rel);
    }
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) RelOptTable(org.apache.calcite.plan.RelOptTable) TableModify(org.apache.calcite.rel.core.TableModify) RexNode(org.apache.calcite.rex.RexNode)

Example 38 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project hazelcast by hazelcast.

the class IndexResolver method createIndexScan.

private static IndexScanMapPhysicalRel createIndexScan(FullScanLogicalRel scan, MapTableIndex index, List<RexNode> conjunctions, List<IndexComponentFilter> filterDescriptors, List<Boolean> ascs) {
    // Collect filters and relevant expressions
    List<IndexFilter> filters = new ArrayList<>(filterDescriptors.size());
    Set<RexNode> exps = new HashSet<>();
    for (IndexComponentFilter filterDescriptor : filterDescriptors) {
        filters.add(filterDescriptor.getFilter());
        exps.addAll(filterDescriptor.getExpressions());
    }
    // Construct Calcite expressions.
    RexBuilder rexBuilder = scan.getCluster().getRexBuilder();
    RexNode exp = RexUtil.composeConjunction(rexBuilder, exps);
    List<RexNode> remainderConjunctiveExps = excludeNodes(conjunctions, exps);
    RexNode remainderExp = remainderConjunctiveExps.isEmpty() ? null : RexUtil.composeConjunction(rexBuilder, remainderConjunctiveExps);
    // Prepare traits
    RelTraitSet traitSet = scan.getTraitSet();
    // Make a collation trait
    RelCollation relCollation = buildCollationTrait(scan, index, ascs);
    traitSet = OptUtils.traitPlus(traitSet, relCollation);
    // Prepare table
    HazelcastRelOptTable originalRelTable = (HazelcastRelOptTable) scan.getTable();
    HazelcastTable originalHazelcastTable = OptUtils.extractHazelcastTable(scan);
    RelOptTable newRelTable = createRelTable(originalRelTable, originalHazelcastTable.withFilter(null), scan.getCluster().getTypeFactory());
    // Try composing the final filter out of the isolated component filters if possible
    IndexFilter filter = composeFilter(filters, index.getType(), index.getComponentsCount());
    if (filter == null) {
        return null;
    }
    // Construct the scan
    return new IndexScanMapPhysicalRel(scan.getCluster(), OptUtils.toPhysicalConvention(traitSet), newRelTable, index, filter, exp, remainderExp);
}
Also used : ArrayList(java.util.ArrayList) RelTraitSet(org.apache.calcite.plan.RelTraitSet) IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) RelCollation(org.apache.calcite.rel.RelCollation) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) RexBuilder(org.apache.calcite.rex.RexBuilder) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) RelOptTable(org.apache.calcite.plan.RelOptTable) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) RexNode(org.apache.calcite.rex.RexNode) HashSet(java.util.HashSet)

Example 39 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project beam by apache.

the class TableScanConverter method convert.

@Override
public RelNode convert(ResolvedTableScan zetaNode, List<RelNode> inputs) {
    List<String> tablePath = getTablePath(zetaNode.getTable());
    SchemaPlus defaultSchemaPlus = getConfig().getDefaultSchema();
    if (defaultSchemaPlus == null) {
        throw new AssertionError("Default schema is null.");
    }
    // TODO: reject incorrect top-level schema
    Table calciteTable = TableResolution.resolveCalciteTable(defaultSchemaPlus, tablePath);
    // we already resolved the table before passing the query to Analyzer, so it should be there
    checkNotNull(calciteTable, "Unable to resolve the table path %s in schema %s", tablePath, defaultSchemaPlus.getName());
    String defaultSchemaName = defaultSchemaPlus.getName();
    final CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(defaultSchemaPlus), ImmutableList.of(defaultSchemaName), getCluster().getTypeFactory(), new CalciteConnectionConfigImpl(new Properties()));
    RelOptTableImpl relOptTable = RelOptTableImpl.create(catalogReader, calciteTable.getRowType(getCluster().getTypeFactory()), calciteTable, ImmutableList.<String>builder().add(defaultSchemaName).addAll(tablePath).build());
    if (calciteTable instanceof TranslatableTable) {
        return ((TranslatableTable) calciteTable).toRel(createToRelContext(), relOptTable);
    } else {
        throw new UnsupportedOperationException("Does not support non TranslatableTable type table!");
    }
}
Also used : CalciteConnectionConfigImpl(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.config.CalciteConnectionConfigImpl) RelOptTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable) Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) TranslatableTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable) CalciteCatalogReader(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.CalciteCatalogReader) SchemaPlus(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus) RelOptTableImpl(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.RelOptTableImpl) TranslatableTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable) Properties(java.util.Properties)

Example 40 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class EnumerableTableScan method create.

/**
 * Creates an EnumerableTableScan.
 */
public static EnumerableTableScan create(RelOptCluster cluster, RelOptTable relOptTable) {
    final Table table = relOptTable.unwrap(Table.class);
    Class elementType = EnumerableTableScan.deduceElementType(table);
    final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {

        public List<RelCollation> get() {
            if (table != null) {
                return table.getStatistic().getCollations();
            }
            return ImmutableList.of();
        }
    });
    return new EnumerableTableScan(cluster, traitSet, relOptTable, elementType);
}
Also used : RelOptTable(org.apache.calcite.plan.RelOptTable) QueryableTable(org.apache.calcite.schema.QueryableTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) ScannableTable(org.apache.calcite.schema.ScannableTable) Table(org.apache.calcite.schema.Table) FilterableTable(org.apache.calcite.schema.FilterableTable) StreamableTable(org.apache.calcite.schema.StreamableTable) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Aggregations

RelOptTable (org.apache.calcite.plan.RelOptTable)63 RelDataType (org.apache.calcite.rel.type.RelDataType)20 RexNode (org.apache.calcite.rex.RexNode)18 RelNode (org.apache.calcite.rel.RelNode)17 Table (org.apache.calcite.schema.Table)15 ArrayList (java.util.ArrayList)14 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)12 RelTraitSet (org.apache.calcite.plan.RelTraitSet)10 SqlNode (org.apache.calcite.sql.SqlNode)10 RelOptCluster (org.apache.calcite.plan.RelOptCluster)9 ImmutableList (com.google.common.collect.ImmutableList)8 NlsString (org.apache.calcite.util.NlsString)8 List (java.util.List)6 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)6 SchemaPlus (org.apache.calcite.schema.SchemaPlus)6 RelOptSchema (org.apache.calcite.plan.RelOptSchema)5 Project (org.apache.calcite.rel.core.Project)5 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)5 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)5 Test (org.junit.Test)5