korlov42 commented on a change in pull request #9009:
URL: https://github.com/apache/ignite/pull/9009#discussion_r615911217
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/RowHandler.java
##########
@@ -40,6 +40,9 @@
/** */
int columnCount(Row row);
+ /** */
+ Object[] getColumns(Row row);
Review comment:
This interface already provides a sufficient set of methods to work with
a row. So if you need a shortcut for some operation, it's better to implement
it locally. But personally I prefer to create GroupKey via builder (the fact
that GroupKey's constructor is public is accident IMO).
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MinusNode.java
##########
@@ -0,0 +1,341 @@
+/*
+ * 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.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+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.exec.RowHandler.RowFactory;
+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.util.typedef.F;
+
+/**
+ * Execution node for MINUS (EXCEPT) operator.
+ */
+public class MinusNode<Row> extends AbstractNode<Row> {
Review comment:
I have doubts regarding current implementation of MinusNode. Let's
consider two cases:
1. Currently both EXCEPT, if I'm not mistaken, load all rows (all distinct
rows for EXCEPT[all=false]) from every source. Let's assume that there are 3
sources, the first one is empty and the last two has a million rows each. We
will handle 2kk rows, although in fact we could give an answer right away . So,
probably, it would be better to switch to a tree structure for execution node
and process only two sources at the time.
2. There are a few more optimizations for EXCEPT[all=false]: a streaming
mode and correlations. And both of them are already implemented for joins.
Perhaps, it's worth to consider simple rewriting rule EXCEPT[all=false] =>
AntiJoin. Honestly speaking, AntiJoin is not implemented for
CorrelatedNestedLoop, but it seems not so difficult anyway. So WDYT?
##########
File path:
modules/calcite/src/test/java/org/apache/ignite/testsuites/PlannerTestSuite.java
##########
@@ -20,13 +20,15 @@
import
org.apache.ignite.internal.processors.query.calcite.planner.AggregateDistinctPlannerTest;
import
org.apache.ignite.internal.processors.query.calcite.planner.AggregatePlannerTest;
import
org.apache.ignite.internal.processors.query.calcite.planner.CorrelatedNestedLoopJoinPlannerTest;
+import
org.apache.ignite.internal.processors.query.calcite.planner.ExceptPlannerTest;
import
org.apache.ignite.internal.processors.query.calcite.planner.HashAggregatePlannerTest;
import
org.apache.ignite.internal.processors.query.calcite.planner.HashIndexSpoolPlannerTest;
import
org.apache.ignite.internal.processors.query.calcite.planner.JoinColocationPlannerTest;
import org.apache.ignite.internal.processors.query.calcite.planner.PlannerTest;
import
org.apache.ignite.internal.processors.query.calcite.planner.SortAggregatePlannerTest;
import
org.apache.ignite.internal.processors.query.calcite.planner.SortedIndexSpoolPlannerTest;
import
org.apache.ignite.internal.processors.query.calcite.planner.TableSpoolPlannerTest;
+import
org.apache.ignite.internal.processors.query.calcite.planner.UnionPlannerTest;
Review comment:
worth to add this to suite too
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/set/IgniteMapMinus.java
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.RelOptCluster;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelInput;
+import org.apache.calcite.rel.RelNode;
+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.GroupKey;
+import org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel;
+import
org.apache.ignite.internal.processors.query.calcite.rel.IgniteRelVisitor;
+import
org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait;
+import
org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistribution;
+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 MINUS (EXCEPT) operator.
+ */
+public class IgniteMapMinus extends IgniteMinusBase {
+ /** */
+ public IgniteMapMinus(
+ RelOptCluster cluster,
+ RelTraitSet traitSet,
+ List<RelNode> inputs,
+ boolean all
+ ) {
+ super(cluster, traitSet, inputs, all);
+ }
+
+ /** */
+ public IgniteMapMinus(RelInput input) {
+ super(input);
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteMapMinus copy(RelTraitSet traitSet, List<RelNode>
inputs, boolean all) {
+ return new IgniteMapMinus(getCluster(), traitSet, inputs, all);
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteRel clone(RelOptCluster cluster, List<IgniteRel>
inputs) {
+ return new IgniteMapMinus(cluster, getTraitSet(),
Commons.cast(inputs), all);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> T accept(IgniteRelVisitor<T> visitor) {
+ return visitor.visit(this);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected RelDataType deriveRowType() {
+ RelDataTypeFactory typeFactory = Commons.typeFactory(getCluster());
+
+ assert typeFactory instanceof IgniteTypeFactory;
+
+ RelDataTypeFactory.Builder builder = new
RelDataTypeFactory.Builder(typeFactory);
+
+ builder.add("GROUP_KEY", typeFactory.createJavaType(GroupKey.class));
+ builder.add("COUNTERS", typeFactory.createJavaType(int[].class));
+
+ return builder.build();
+ }
+
+ /** {@inheritDoc} */
+ @Override public 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 List<Pair<RelTraitSet, List<RelTraitSet>>>
deriveDistribution(
+ RelTraitSet nodeTraits,
+ List<RelTraitSet> inputTraits
+ ) {
+ Set<IgniteDistribution> distributions = inputTraits.stream()
+ .map(TraitUtils::distribution)
+ .collect(Collectors.toSet());
+
+ ImmutableList.Builder<Pair<RelTraitSet, List<RelTraitSet>>> b =
ImmutableList.builder();
+
+ for (IgniteDistribution distribution : distributions) {
Review comment:
For map node it doesn't make any sense to provide particular
distribution. Hence, following should work fine for us:
`Pair.of(nodeTraits.replace(RANDOM), Commons.transform(inputTraits, t ->
t.replace(ANY)))`
--
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]