Search in sources :

Example 1 with RowHandler

use of org.apache.ignite.internal.sql.engine.exec.RowHandler in project ignite-3 by apache.

the class ModifyNode method flushTuples.

private void flushTuples(boolean force) {
    if (nullOrEmpty(rows) || !force && rows.size() < MODIFY_BATCH_SIZE) {
        return;
    }
    List<ModifyRow> rows = this.rows;
    this.rows = new ArrayList<>(MODIFY_BATCH_SIZE);
    Map<ModifyRow.Operation, Collection<BinaryRow>> operations = getOperationsPerAction(rows);
    // TODO: IGNITE-15087 Implement support for transactional SQL
    for (Map.Entry<ModifyRow.Operation, Collection<BinaryRow>> op : operations.entrySet()) {
        switch(op.getKey()) {
            case INSERT_ROW:
                Collection<BinaryRow> conflictKeys = tableView.insertAll(op.getValue(), null).join();
                if (!conflictKeys.isEmpty()) {
                    IgniteTypeFactory typeFactory = context().getTypeFactory();
                    RowHandler.RowFactory<RowT> rowFactory = context().rowHandler().factory(context().getTypeFactory(), table.descriptor().insertRowType(typeFactory));
                    List<String> conflictKeys0 = conflictKeys.stream().map(binRow -> table.toRow(context(), binRow, rowFactory, null)).map(context().rowHandler()::toString).collect(Collectors.toList());
                    throw conflictKeysException(conflictKeys0);
                }
                break;
            case UPDATE_ROW:
                tableView.upsertAll(op.getValue(), null).join();
                break;
            case DELETE_ROW:
                tableView.deleteAll(op.getValue(), null).join();
                break;
            default:
                throw new UnsupportedOperationException(op.getKey().name());
        }
    }
    updatedRows += rows.size();
}
Also used : IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) ModifyRow(org.apache.ignite.internal.sql.engine.schema.ModifyRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) RowHandler(org.apache.ignite.internal.sql.engine.exec.RowHandler) Collection(java.util.Collection) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 2 with RowHandler

use of org.apache.ignite.internal.sql.engine.exec.RowHandler in project ignite-3 by apache.

the class NestedLoopJoinExecutionTest method verifyJoin.

/**
 * Creates execution tree and executes it. Then compares the result of the execution with the given one.
 *
 * @param left     Data for left table.
 * @param right    Data for right table.
 * @param joinType Join type.
 * @param expRes   Expected result.
 */
private void verifyJoin(Object[][] left, Object[][] right, JoinRelType joinType, Object[][] expRes) {
    ExecutionContext<Object[]> ctx = executionContext(true);
    RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
    ScanNode<Object[]> leftNode = new ScanNode<>(ctx, leftType, Arrays.asList(left));
    RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
    ScanNode<Object[]> rightNode = new ScanNode<>(ctx, rightType, Arrays.asList(right));
    RelDataType outType;
    if (setOf(SEMI, ANTI).contains(joinType)) {
        outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class);
    } else {
        outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, Integer.class, int.class, String.class);
    }
    RowHandler<Object[]> hnd = ctx.rowHandler();
    NestedLoopJoinNode<Object[]> join = NestedLoopJoinNode.create(ctx, outType, leftType, rightType, joinType, (r1, r2) -> getFieldFromBiRows(hnd, 2, r1, r2) == getFieldFromBiRows(hnd, 3, r1, r2));
    join.register(asList(leftNode, rightNode));
    RelDataType rowType;
    ProjectNode<Object[]> project;
    if (setOf(SEMI, ANTI).contains(joinType)) {
        rowType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class);
        project = new ProjectNode<>(ctx, rowType, r -> new Object[] { r[0], r[1] });
    } else {
        rowType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, String.class, String.class);
        project = new ProjectNode<>(ctx, rowType, r -> new Object[] { r[0], r[1], r[4] });
    }
    project.register(join);
    RootNode<Object[]> node = new RootNode<>(ctx, rowType);
    node.register(project);
    ArrayList<Object[]> rows = new ArrayList<>();
    while (node.hasNext()) {
        rows.add(node.next());
    }
    assertArrayEquals(expRes, rows.toArray(EMPTY));
}
Also used : ArrayUtils.asList(org.apache.ignite.internal.util.ArrayUtils.asList) RelDataType(org.apache.calcite.rel.type.RelDataType) LEFT(org.apache.calcite.rel.core.JoinRelType.LEFT) Arrays(java.util.Arrays) ANTI(org.apache.calcite.rel.core.JoinRelType.ANTI) INNER(org.apache.calcite.rel.core.JoinRelType.INNER) RowHandler(org.apache.ignite.internal.sql.engine.exec.RowHandler) SEMI(org.apache.calcite.rel.core.JoinRelType.SEMI) Set(java.util.Set) TypeUtils(org.apache.ignite.internal.sql.engine.util.TypeUtils) FULL(org.apache.calcite.rel.core.JoinRelType.FULL) ArrayList(java.util.ArrayList) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) RIGHT(org.apache.calcite.rel.core.JoinRelType.RIGHT) Commons.getFieldFromBiRows(org.apache.ignite.internal.sql.engine.util.Commons.getFieldFromBiRows) JoinRelType(org.apache.calcite.rel.core.JoinRelType) ExecutionContext(org.apache.ignite.internal.sql.engine.exec.ExecutionContext) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

RowHandler (org.apache.ignite.internal.sql.engine.exec.RowHandler)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 EnumMap (java.util.EnumMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 JoinRelType (org.apache.calcite.rel.core.JoinRelType)1 ANTI (org.apache.calcite.rel.core.JoinRelType.ANTI)1 FULL (org.apache.calcite.rel.core.JoinRelType.FULL)1 INNER (org.apache.calcite.rel.core.JoinRelType.INNER)1 LEFT (org.apache.calcite.rel.core.JoinRelType.LEFT)1 RIGHT (org.apache.calcite.rel.core.JoinRelType.RIGHT)1 SEMI (org.apache.calcite.rel.core.JoinRelType.SEMI)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)1 ExecutionContext (org.apache.ignite.internal.sql.engine.exec.ExecutionContext)1 ModifyRow (org.apache.ignite.internal.sql.engine.schema.ModifyRow)1 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)1