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/07/19 13:57:11 UTC

[GitHub] [ignite] alex-plekhanov commented on a change in pull request #9264: IGNITE-13136 Calcite. Improve join predicate calculation.

alex-plekhanov commented on a change in pull request #9264:
URL: https://github.com/apache/ignite/pull/9264#discussion_r672286902



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactory.java
##########
@@ -104,22 +113,42 @@
     <T> Supplier<T> execute(RexNode node);
 
     /**
-     * Creates {@link Scalar}, a code-generated expressions evaluator.
+     * Creates {@link SingleScalar}, a code-generated expressions evaluator.
      *
      * @param node Expression.
      * @param type Row type.
-     * @return Scalar.
+     * @return SingleScalar.
      */
-    default Scalar scalar(RexNode node, RelDataType type) {
+    default SingleScalar scalar(RexNode node, RelDataType type) {
         return scalar(ImmutableList.of(node), type);
     }
 
     /**
-     * Creates {@link Scalar}, a code-generated expressions evaluator.
+     * Creates {@link BiScalar}, a code-generated expressions evaluator.
+     *
+     * @param node Expression.
+     * @param type Row type.
+     * @return BiScalar.
+     */
+    default BiScalar biScalar(RexNode node, RelDataType type) {
+        return biScalar(ImmutableList.of(node), type);
+    }
+
+    /**
+     * Creates {@link SingleScalar}, a code-generated expressions evaluator.
+     *
+     * @param nodes Expressions.
+     * @param type Row type.
+     * @return SingleScalar.
+     */
+    SingleScalar scalar(List<RexNode> nodes, RelDataType type);
+
+    /**
+     * Creates {@link BiScalar}, a code-generated expressions evaluator.
      *
      * @param nodes Expressions.
      * @param type Row type.
-     * @return Scalar.
+     * @return BiScalar.
      */
-    Scalar scalar(List<RexNode> nodes, RelDataType type);
+    BiScalar biScalar(List<RexNode> nodes, RelDataType type);

Review comment:
       Looks like this method is redundant and never will be used, it's enough just `biScalar(RexNode node, RelDataType type)` with single node.

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/BiScalar.java
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.exp;
+
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+
+/** */
+public interface BiScalar extends Scalar {
+    /** */
+    void execute(ExecutionContext ctx, Object in1, Object in2, Object out);

Review comment:
       `public` modifier for method.

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/RowHandler.java
##########
@@ -31,6 +31,9 @@
     /** */
     Object get(int field, Row row);
 
+    /** */
+    Object getBiRows(int field, Object row1, Object row2);

Review comment:
       I think row handler is not the right place for such a method. Everything this method does can be done by some external utility class using `get()` and `columnCount()` methods. 

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
##########
@@ -445,6 +500,52 @@ private ValueImpl(Scalar scalar, RowFactory<Row> factory) {
         }
     }
 
+    /** */
+    private class BiFieldGetter implements InputGetter {
+        /** */
+        private final Expression hnd_;
+
+        /** */
+        private final Expression row1_;
+
+        /** */
+        private final Expression row2_;
+
+        /** */
+        private final RelDataType rowType;
+
+        /** */
+        private BiFieldGetter(Expression hnd_, Expression row1_, Expression row2_, RelDataType rowType) {
+            this.hnd_ = hnd_;
+            this.row1_ = row1_;
+            this.row2_ = row2_;
+            this.rowType = rowType;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Expression field(BlockBuilder list, int index, Type desiredType) {
+            Expression row1_ = list.append("row1", this.row1_);
+            Expression row2_ = list.append("row2", this.row2_);
+
+            Expression field = Expressions.call(hnd_,
+                IgniteMethod.ROW_HANDLER_BI_GET.method(),
+                Expressions.constant(index), row1_, row2_);
+
+            Type fieldType = typeFactory.getJavaClass(rowType.getFieldList().get(index).getType());
+
+            if (desiredType == null) {
+                desiredType = fieldType;
+                fieldType = Object.class;
+            } else if (fieldType != java.sql.Date.class

Review comment:
       Let's also reformat this block according to code-style rules.

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/SingleScalar.java
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.exp;
+
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+
+/**
+ *
+ */
+public interface SingleScalar extends Scalar {
+    void execute(ExecutionContext ctx, Object in, Object out);

Review comment:
       Comment and `public` modifier.

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
##########
@@ -445,6 +500,52 @@ private ValueImpl(Scalar scalar, RowFactory<Row> factory) {
         }
     }
 
+    /** */
+    private class BiFieldGetter implements InputGetter {
+        /** */
+        private final Expression hnd_;
+
+        /** */
+        private final Expression row1_;
+
+        /** */
+        private final Expression row2_;
+
+        /** */
+        private final RelDataType rowType;
+
+        /** */
+        private BiFieldGetter(Expression hnd_, Expression row1_, Expression row2_, RelDataType rowType) {
+            this.hnd_ = hnd_;
+            this.row1_ = row1_;
+            this.row2_ = row2_;
+            this.rowType = rowType;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Expression field(BlockBuilder list, int index, Type desiredType) {
+            Expression row1_ = list.append("row1", this.row1_);
+            Expression row2_ = list.append("row2", this.row2_);
+
+            Expression field = Expressions.call(hnd_,
+                IgniteMethod.ROW_HANDLER_BI_GET.method(),
+                Expressions.constant(index), row1_, row2_);
+
+            Type fieldType = typeFactory.getJavaClass(rowType.getFieldList().get(index).getType());

Review comment:
       Can we deduplicate at least this part (move to a separate method)?

##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ExpressionFactoryImpl.java
##########
@@ -373,10 +400,38 @@ private PredicateImpl(Scalar scalar) {
         }
     }
 
+    /** */
+    private class BiPredicateImpl implements BiPredicate<Row, Row> {

Review comment:
       Can we use common parent to deduplicate code?




-- 
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