Search in sources :

Example 1 with ModifyRow

use of org.apache.ignite.internal.sql.engine.schema.ModifyRow 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)

Aggregations

Collection (java.util.Collection)1 EnumMap (java.util.EnumMap)1 Map (java.util.Map)1 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)1 RowHandler (org.apache.ignite.internal.sql.engine.exec.RowHandler)1 ModifyRow (org.apache.ignite.internal.sql.engine.schema.ModifyRow)1 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)1