Search in sources :

Example 1 with InternalIgniteTable

use of org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable in project ignite-3 by apache.

the class LogicalRelImplementor method visit.

/**
 * {@inheritDoc}
 */
@Override
public Node<RowT> visit(IgniteTableScan rel) {
    RexNode condition = rel.condition();
    List<RexNode> projects = rel.projects();
    ImmutableBitSet requiredColumns = rel.requiredColumns();
    InternalIgniteTable tbl = rel.getTable().unwrap(InternalIgniteTable.class);
    assert tbl != null;
    IgniteTypeFactory typeFactory = ctx.getTypeFactory();
    RelDataType rowType = tbl.getRowType(typeFactory, requiredColumns);
    Predicate<RowT> filters = condition == null ? null : expressionFactory.predicate(condition, rowType);
    Function<RowT, RowT> prj = projects == null ? null : expressionFactory.project(projects, rowType);
    ColocationGroup group = ctx.group(rel.sourceId());
    if (!group.nodeIds().contains(ctx.localNodeId())) {
        return new ScanNode<>(ctx, rowType, Collections.emptyList());
    }
    return new TableScanNode<>(ctx, rowType, tbl, group.partitions(ctx.localNodeId()), filters, prj, requiredColumns);
}
Also used : ColocationGroup(org.apache.ignite.internal.sql.engine.metadata.ColocationGroup) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) TableScanNode(org.apache.ignite.internal.sql.engine.exec.rel.TableScanNode) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) ScanNode(org.apache.ignite.internal.sql.engine.exec.rel.ScanNode) TableScanNode(org.apache.ignite.internal.sql.engine.exec.rel.TableScanNode) RexNode(org.apache.calcite.rex.RexNode)

Example 2 with InternalIgniteTable

use of org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable in project ignite-3 by apache.

the class LogicalRelImplementor method visit.

/**
 * {@inheritDoc}
 */
@Override
public Node<RowT> visit(IgniteIndexScan rel) {
    // TODO: fix this
    // RexNode condition = rel.condition();
    // List<RexNode> projects = rel.projects();
    InternalIgniteTable tbl = rel.getTable().unwrap(InternalIgniteTable.class);
    IgniteTypeFactory typeFactory = ctx.getTypeFactory();
    ImmutableBitSet requiredColumns = rel.requiredColumns();
    // List<RexNode> lowerCond = rel.lowerBound();
    // List<RexNode> upperCond = rel.upperBound();
    RelDataType rowType = tbl.getRowType(typeFactory, requiredColumns);
    // Predicate<Row> filters = condition == null ? null : expressionFactory.predicate(condition, rowType);
    // Supplier<Row> lower = lowerCond == null ? null : expressionFactory.rowSource(lowerCond);
    // Supplier<Row> upper = upperCond == null ? null : expressionFactory.rowSource(upperCond);
    // Function<Row, Row> prj = projects == null ? null : expressionFactory.project(projects, rowType);
    // 
    // IgniteIndex idx = tbl.getIndex(rel.indexName());
    // 
    // ColocationGroup group = ctx.group(rel.sourceId());
    Iterable<RowT> rowsIter = (Iterable<RowT>) List.of(new Object[] { 0, 0 }, // idx.scan(ctx, group, filters, lower, upper, prj, requiredColumns);
    new Object[] { 1, 1 });
    return new ScanNode<>(ctx, rowType, rowsIter);
}
Also used : InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) ScanNode(org.apache.ignite.internal.sql.engine.exec.rel.ScanNode) TableScanNode(org.apache.ignite.internal.sql.engine.exec.rel.TableScanNode)

Example 3 with InternalIgniteTable

use of org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable in project ignite-3 by apache.

the class IgniteLogicalIndexScan method create.

/**
 * Creates a IgniteLogicalIndexScan.
 */
public static IgniteLogicalIndexScan create(RelOptCluster cluster, RelTraitSet traits, RelOptTable table, String idxName, @Nullable List<RexNode> proj, @Nullable RexNode cond, @Nullable ImmutableBitSet requiredColumns) {
    InternalIgniteTable tbl = table.unwrap(InternalIgniteTable.class);
    IgniteTypeFactory typeFactory = Commons.typeFactory(cluster);
    RelCollation collation = tbl.getIndex(idxName).collation();
    if (requiredColumns != null) {
        Mappings.TargetMapping targetMapping = Commons.mapping(requiredColumns, tbl.getRowType(typeFactory).getFieldCount());
        collation = collation.apply(targetMapping);
    }
    IndexConditions idxCond = new IndexConditions();
    if (collation != null && !collation.getFieldCollations().isEmpty()) {
        idxCond = RexUtils.buildSortedIndexConditions(cluster, collation, cond, tbl.getRowType(typeFactory), requiredColumns);
    }
    return new IgniteLogicalIndexScan(cluster, traits, table, idxName, proj, cond, idxCond, requiredColumns);
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) Mappings(org.apache.calcite.util.mapping.Mappings) IndexConditions(org.apache.ignite.internal.sql.engine.util.IndexConditions) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)

Example 4 with InternalIgniteTable

use of org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable in project ignite-3 by apache.

the class ExposeIndexRule method onMatch.

/**
 * {@inheritDoc}
 */
@Override
public void onMatch(RelOptRuleCall call) {
    IgniteLogicalTableScan scan = call.rel(0);
    RelOptCluster cluster = scan.getCluster();
    RelOptTable optTable = scan.getTable();
    InternalIgniteTable igniteTable = optTable.unwrap(InternalIgniteTable.class);
    List<RexNode> proj = scan.projects();
    RexNode condition = scan.condition();
    ImmutableBitSet requiredCols = scan.requiredColumns();
    List<IgniteLogicalIndexScan> indexes = igniteTable.indexes().keySet().stream().map(idxName -> igniteTable.toRel(cluster, optTable, idxName, proj, condition, requiredCols)).collect(Collectors.toList());
    if (indexes.isEmpty()) {
        return;
    }
    Map<RelNode, RelNode> equivMap = new HashMap<>(indexes.size());
    for (int i = 1; i < indexes.size(); i++) {
        equivMap.put(indexes.get(i), scan);
    }
    call.transformTo(indexes.get(0), equivMap);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelOptCluster(org.apache.calcite.plan.RelOptCluster) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) HashMap(java.util.HashMap) RelRule(org.apache.calcite.plan.RelRule) RelNode(org.apache.calcite.rel.RelNode) Collectors(java.util.stream.Collectors) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) RelOptTable(org.apache.calcite.plan.RelOptTable) RelOptRule(org.apache.calcite.plan.RelOptRule) List(java.util.List) IgniteLogicalIndexScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalIndexScan) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) IgniteLogicalTableScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan) RexNode(org.apache.calcite.rex.RexNode) Value(org.immutables.value.Value) Map(java.util.Map) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) HashMap(java.util.HashMap) IgniteLogicalTableScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan) RelNode(org.apache.calcite.rel.RelNode) IgniteLogicalIndexScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalIndexScan) RelOptTable(org.apache.calcite.plan.RelOptTable) RexNode(org.apache.calcite.rex.RexNode)

Example 5 with InternalIgniteTable

use of org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable in project ignite-3 by apache.

the class LogicalRelImplementor method visit.

/**
 * {@inheritDoc}
 */
@Override
public Node<RowT> visit(IgniteTableModify rel) {
    switch(rel.getOperation()) {
        case INSERT:
        case UPDATE:
        case DELETE:
        case MERGE:
            InternalIgniteTable tbl = rel.getTable().unwrap(InternalIgniteTable.class);
            assert tbl != null;
            ModifyNode<RowT> node = new ModifyNode<>(ctx, rel.getRowType(), tbl, rel.getOperation(), rel.getUpdateColumnList());
            Node<RowT> input = visit(rel.getInput());
            node.register(input);
            return node;
        default:
            throw new AssertionError("Unsupported operation: " + rel.getOperation());
    }
}
Also used : InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) ModifyNode(org.apache.ignite.internal.sql.engine.exec.rel.ModifyNode)

Aggregations

InternalIgniteTable (org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable)6 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)4 RexNode (org.apache.calcite.rex.RexNode)3 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)3 RelDataType (org.apache.calcite.rel.type.RelDataType)2 Mappings (org.apache.calcite.util.mapping.Mappings)2 ScanNode (org.apache.ignite.internal.sql.engine.exec.rel.ScanNode)2 TableScanNode (org.apache.ignite.internal.sql.engine.exec.rel.TableScanNode)2 IgniteLogicalTableScan (org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan)2 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelOptRule (org.apache.calcite.plan.RelOptRule)1 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelRule (org.apache.calcite.plan.RelRule)1 RelCollation (org.apache.calcite.rel.RelCollation)1