korlov42 commented on a change in pull request #9095:
URL: https://github.com/apache/ignite/pull/9095#discussion_r640448648



##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/set/IgniteMapSetOp.java
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.rel.set;
+
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.core.CorrelationId;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.util.Pair;
+import 
org.apache.ignite.internal.processors.query.calcite.exec.exp.agg.AggregateType;
+import 
org.apache.ignite.internal.processors.query.calcite.exec.exp.agg.GroupKey;
+import 
org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait;
+import 
org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions;
+import 
org.apache.ignite.internal.processors.query.calcite.trait.RewindabilityTrait;
+import org.apache.ignite.internal.processors.query.calcite.trait.TraitUtils;
+import 
org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
+import org.apache.ignite.internal.processors.query.calcite.util.Commons;
+
+/**
+ * Physical node for MAP phase of set op (MINUS, INTERSECT).
+ */
+public interface IgniteMapSetOp extends IgniteSetOp {
+    /** {@inheritDoc} */
+    @Override public default List<Pair<RelTraitSet, List<RelTraitSet>>> 
deriveRewindability(
+        RelTraitSet nodeTraits,
+        List<RelTraitSet> inputTraits
+    ) {
+        boolean rewindable = inputTraits.stream()
+            .map(TraitUtils::rewindability)
+            .allMatch(RewindabilityTrait::rewindable);
+
+        if (rewindable)
+            return 
ImmutableList.of(Pair.of(nodeTraits.replace(RewindabilityTrait.REWINDABLE), 
inputTraits));
+
+        return 
ImmutableList.of(Pair.of(nodeTraits.replace(RewindabilityTrait.ONE_WAY),
+            Commons.transform(inputTraits, t -> 
t.replace(RewindabilityTrait.ONE_WAY))));
+    }
+
+    /** {@inheritDoc} */
+    @Override public default List<Pair<RelTraitSet, List<RelTraitSet>>> 
deriveDistribution(
+        RelTraitSet nodeTraits,
+        List<RelTraitSet> inputTraits
+    ) {
+        if (inputTraits.stream().allMatch(t -> 
TraitUtils.distribution(t).satisfies(IgniteDistributions.single())))
+            return ImmutableList.of(); // If all distributions are single or 
broadcast IgniteSingleMinus should be used.
+
+        if (inputTraits.stream().anyMatch(t -> TraitUtils.distribution(t) == 
IgniteDistributions.single()))
+            return ImmutableList.of(); // Mixing of single and random is 
prohibited.

Review comment:
       Probably it would be better to convert those single rels as well as 
broadcasted to a hash distributed

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/set/IgniteSetOp.java
##########
@@ -97,4 +73,7 @@ protected IgniteMinusBase(RelInput input) {
 
         return costFactory.makeCost(rows, inputRows * 
IgniteCost.ROW_PASS_THROUGH_COST, 0, mem, 0);

Review comment:
       ```suggestion
           return costFactory.makeCost(inputRows, inputRows * 
IgniteCost.ROW_PASS_THROUGH_COST, 0, mem, 0);
   ```
   
   

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/set/IgniteSetOp.java
##########
@@ -19,71 +19,47 @@
 
 import java.util.List;
 import com.google.common.collect.ImmutableList;
-import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptCost;
 import org.apache.calcite.plan.RelOptPlanner;
 import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.RelCollations;
-import org.apache.calcite.rel.RelInput;
 import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.core.Minus;
 import org.apache.calcite.rel.metadata.RelMetadataQuery;
 import org.apache.calcite.util.Pair;
+import 
org.apache.ignite.internal.processors.query.calcite.exec.exp.agg.AggregateType;
 import 
org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCost;
 import 
org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCostFactory;
-import 
org.apache.ignite.internal.processors.query.calcite.rel.IgniteConvention;
-import org.apache.ignite.internal.processors.query.calcite.trait.TraitUtils;
 import 
org.apache.ignite.internal.processors.query.calcite.trait.TraitsAwareIgniteRel;
 import org.apache.ignite.internal.processors.query.calcite.util.Commons;
 
 /**
- * Base class for physical MINUS (EXCEPT) set op.
+ * Base interface for physical set op node (MINUS, INTERSECT).
  */
-public abstract class IgniteMinusBase extends Minus implements 
TraitsAwareIgniteRel {
-    /** Count of counter fields used to aggregate results. */
-    protected static final int COUNTER_FIELDS_CNT = 2;
-
-    /** */
-    IgniteMinusBase(RelOptCluster cluster, RelTraitSet traits, List<RelNode> 
inputs, boolean all) {
-        super(cluster, traits, inputs, all);
-    }
-
-    /** {@inheritDoc} */
-    protected IgniteMinusBase(RelInput input) {
-        super(TraitUtils.changeTraits(input, IgniteConvention.INSTANCE));
-    }
+public interface IgniteSetOp extends TraitsAwareIgniteRel {
+    /** ALL flag of set op. */
+    public boolean all();
 
     /** {@inheritDoc} */
-    @Override public Pair<RelTraitSet, List<RelTraitSet>> 
passThroughCollation(RelTraitSet nodeTraits, List<RelTraitSet> inputTraits) {
+    @Override public default Pair<RelTraitSet, List<RelTraitSet>> 
passThroughCollation(RelTraitSet nodeTraits,
+        List<RelTraitSet> inputTraits) {
         // Operation erases collation.
         return Pair.of(nodeTraits.replace(RelCollations.EMPTY),
             Commons.transform(inputTraits, t -> 
t.replace(RelCollations.EMPTY)));
     }
 
     /** {@inheritDoc} */
-    @Override public List<Pair<RelTraitSet, List<RelTraitSet>>> 
deriveCollation(RelTraitSet nodeTraits, List<RelTraitSet> inputTraits) {
+    @Override public default List<Pair<RelTraitSet, List<RelTraitSet>>> 
deriveCollation(RelTraitSet nodeTraits,
+        List<RelTraitSet> inputTraits) {
         // Operation erases collation.
         return 
ImmutableList.of(Pair.of(nodeTraits.replace(RelCollations.EMPTY),
             Commons.transform(inputTraits, t -> 
t.replace(RelCollations.EMPTY))));
     }
 
     /** Gets count of fields for aggregation for this node. Required for 
memory consumption calculation. */
-    protected abstract int aggregateFieldsCount();
-
-    /** {@inheritDoc} */
-    @Override public double estimateRowCount(RelMetadataQuery mq) {
-        final List<RelNode> inputs = getInputs();
-
-        double rows = mq.getRowCount(inputs.get(0));
-
-        for (int i = 1; i < inputs.size(); i++)
-            rows -= 0.5 * Math.min(rows, mq.getRowCount(inputs.get(i)));
-
-        return rows;
-    }
+    public int aggregateFieldsCount();
 
     /** {@inheritDoc} */
-    @Override public RelOptCost computeSelfCost(RelOptPlanner planner, 
RelMetadataQuery mq) {
+    @Override public default RelOptCost computeSelfCost(RelOptPlanner planner, 
RelMetadataQuery mq) {

Review comment:
       the problem with default method is there should be no implementation 
within the whole class hierarchy, but all ignite rels is actually descendants 
of AbstractRelNode




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to