You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/10/01 08:57:28 UTC

[GitHub] [ignite-3] korlov42 commented on a change in pull request #295: IGNITE-15108 Integrate with actual data layer in Ignite 3.0

korlov42 commented on a change in pull request #295:
URL: https://github.com/apache/ignite-3/pull/295#discussion_r720071113



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/TableScanNode.java
##########
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.exec.rel;
+
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.Flow;
+import java.util.concurrent.Flow.Subscription;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.processors.query.calcite.exec.RowHandler;
+import org.apache.ignite.internal.processors.query.calcite.schema.TableDescriptor;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.table.TableImpl;
+import org.apache.ignite.internal.table.TableRow;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Scan node.
+ */
+public class TableScanNode<Row> extends AbstractNode<Row> {
+    /** Special value to highlights that all row were received and we are not waiting any more. */
+    private static final int NOT_WAITING = -1;
+
+    /** */
+    private final TableImpl table;
+
+    /** */
+    private final TableDescriptor desc;
+
+    /** */
+    private final RowHandler.RowFactory<Row> factory;
+
+    /** */
+    private final int[] parts;
+
+    /** */
+    private final Queue<Row> inBuff = new LinkedBlockingQueue<>(inBufSize);
+
+    /** */
+    private final @Nullable Predicate<Row> filters;
+
+    /** */
+    private final @Nullable Function<Row, Row> rowTransformer;
+
+    /** Participating columns. */
+    private final @Nullable ImmutableBitSet requiredColumns;
+
+    /** */
+    private int requested;
+
+    /** */
+    private int waiting;
+
+    /** */
+    private boolean inLoop;
+
+    /** */
+    private Subscription activeSubscription;
+
+    /** */
+    private int curPartIdx;
+
+    /**
+     * @param ctx Execution context.
+     * @param rowType Output type of the current node.
+     * @param desc Table descriptor this node should scan.
+     * @param parts Partition numbers to scan.
+     * @param filters Optional filter to filter out rows.
+     * @param rowTransformer Optional projection function.
+     * @param requiredColumns Optional set of column of interest.
+     */
+    public TableScanNode(

Review comment:
       done

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/ModifyNode.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.exec.rel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.calcite.rel.core.TableModify;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.processors.query.calcite.exec.RowHandler;
+import org.apache.ignite.internal.processors.query.calcite.schema.TableDescriptor;
+import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+
+import static org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty;
+
+/**
+ *
+ */
+public class ModifyNode<Row> extends AbstractNode<Row> implements SingleNode<Row>, Downstream<Row> {
+    /** */
+    protected final TableDescriptor desc;
+
+    /** */
+    private final TableModify.Operation op;
+
+    /** */
+    private final List<String> cols;
+
+    private final RecordView<Tuple> tableView;

Review comment:
       done

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/ModifyNode.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.exec.rel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.calcite.rel.core.TableModify;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.processors.query.calcite.exec.RowHandler;
+import org.apache.ignite.internal.processors.query.calcite.schema.TableDescriptor;
+import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+
+import static org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty;
+
+/**
+ *
+ */
+public class ModifyNode<Row> extends AbstractNode<Row> implements SingleNode<Row>, Downstream<Row> {
+    /** */
+    protected final TableDescriptor desc;
+
+    /** */
+    private final TableModify.Operation op;
+
+    /** */
+    private final List<String> cols;
+
+    private final RecordView<Tuple> tableView;
+
+    /** */
+    private List<Tuple> tuples = new ArrayList<>(MODIFY_BATCH_SIZE);
+
+    /** */
+    private long updatedRows;
+
+    /** */
+    private int waiting;
+
+    /** */
+    private int requested;
+
+    /** */
+    private boolean inLoop;
+
+    /** */
+    private State state = State.UPDATING;
+
+    /**
+     * @param ctx Execution context.
+     * @param desc Table descriptor.
+     * @param cols Update column list.
+     */
+    public ModifyNode(
+        ExecutionContext<Row> ctx,
+        RelDataType rowType,
+        TableDescriptor desc,
+        TableModify.Operation op,
+        List<String> cols
+    ) {
+        super(ctx, rowType);
+
+        this.desc = desc;
+        this.op = op;
+        this.cols = cols;
+
+        tableView = desc.table().recordView();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void request(int rowsCnt) throws Exception {
+        assert !nullOrEmpty(sources()) && sources().size() == 1;
+        assert rowsCnt > 0 && requested == 0;
+
+        checkState();
+
+        requested = rowsCnt;
+
+        if (!inLoop)
+            tryEnd();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void push(Row row) throws Exception {
+        assert downstream() != null;
+        assert waiting > 0;
+        assert state == State.UPDATING;
+
+        checkState();
+
+        waiting--;
+
+        switch (op) {
+            case DELETE:
+            case UPDATE:
+            case INSERT:
+                tuples.add(desc.toTuple(context(), row, op, cols));
+
+                flushTuples(false);
+
+                break;
+            default:
+                throw new UnsupportedOperationException(op.name());
+        }
+
+        if (waiting == 0)
+            source().request(waiting = MODIFY_BATCH_SIZE);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void end() throws Exception {
+        assert downstream() != null;
+        assert waiting > 0;
+
+        checkState();
+
+        waiting = -1;
+        state = State.UPDATED;
+
+        tryEnd();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void rewindInternal() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Downstream<Row> requestDownstream(int idx) {
+        if (idx != 0)
+            throw new IndexOutOfBoundsException();
+
+        return this;
+    }
+
+    /** */
+    private void tryEnd() throws Exception {
+        assert downstream() != null;
+
+        if (state == State.UPDATING && waiting == 0)
+            source().request(waiting = MODIFY_BATCH_SIZE);
+
+        if (state == State.UPDATED && requested > 0) {
+            flushTuples(true);
+
+            state = State.END;
+
+            inLoop = true;
+            try {
+                requested--;
+                downstream().push(context().rowHandler().factory(long.class).create(updatedRows));
+            }
+            finally {
+                inLoop = false;
+            }
+        }
+
+        if (state == State.END && requested > 0) {
+            requested = 0;
+            downstream().end();
+        }
+    }
+
+    /** */
+    private void flushTuples(boolean force) {
+        if (nullOrEmpty(tuples) || !force && tuples.size() < MODIFY_BATCH_SIZE)
+            return;
+
+        List<Tuple> tuples = this.tuples;
+        this.tuples = new ArrayList<>(MODIFY_BATCH_SIZE);
+
+        switch (op) {
+            case INSERT:
+                Collection<Tuple> duplicates = tableView.insertAll(tuples);
+
+                if (!duplicates.isEmpty()) {
+                    IgniteTypeFactory typeFactory = context().getTypeFactory();
+                    RowHandler.RowFactory<Row> rowFactory = context().rowHandler().factory(
+                        context().getTypeFactory(),
+                        desc.insertRowType(typeFactory)
+                    );
+
+                    throw new IgniteInternalException("Failed to INSERT some keys because they are already in cache. " +
+                        "[tuples=" + duplicates.stream().map(tup -> desc.toRow(context(), tup, rowFactory, null))

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org