You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Wei-hao-Li (via GitHub)" <gi...@apache.org> on 2025/01/20 02:50:14 UTC
[PR] Add optimizers for distinct in AggFunction [iotdb]
Wei-hao-Li opened a new pull request, #14729:
URL: https://github.com/apache/iotdb/pull/14729
1. SingleDistinctAggregationToGroupBy
2. MultipleDistinctAggregationToMarkDistinct
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add optimizers for distinct in AggFunction [iotdb]
Posted by "lancelly (via GitHub)" <gi...@apache.org>.
lancelly commented on code in PR #14729:
URL: https://github.com/apache/iotdb/pull/14729#discussion_r1924616707
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/MultipleDistinctAggregationToMarkDistinct.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.iotdb.db.queryengine.plan.relational.planner.iterative.rule;
+
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.Symbol;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.iterative.Rule;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.node.AggregationNode;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.node.MarkDistinctNode;
+import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Captures;
+import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Pattern;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.Patterns.aggregation;
+import static org.apache.tsfile.read.common.type.BooleanType.BOOLEAN;
+
+/**
+ * Implements distinct aggregations with different inputs by transforming plans of the following
+ * shape:
+ *
+ * <pre>
+ * - Aggregation
+ * GROUP BY (k)
+ * F1(DISTINCT a0, a1, ...)
+ * F2(DISTINCT b0, b1, ...)
+ * F3(c0, c1, ...)
+ * - X
+ * </pre>
+ *
+ * into
+ *
+ * <pre>
+ * - Aggregation
+ * GROUP BY (k)
+ * F1(a0, a1, ...) mask ($0)
+ * F2(b0, b1, ...) mask ($1)
+ * F3(c0, c1, ...)
+ * - MarkDistinct (k, a0, a1, ...) -> $0
+ * - MarkDistinct (k, b0, b1, ...) -> $1
+ * - X
+ * </pre>
+ */
+public class MultipleDistinctAggregationToMarkDistinct implements Rule<AggregationNode> {
+ private static final Pattern<AggregationNode> PATTERN =
+ aggregation()
+ .matching(
+ Predicates.and(
+ MultipleDistinctAggregationToMarkDistinct::hasNoDistinctWithFilterOrMask,
+ Predicates.or(
+ MultipleDistinctAggregationToMarkDistinct::hasMultipleDistincts,
+ MultipleDistinctAggregationToMarkDistinct::hasMixedDistinctAndNonDistincts)));
+
+ private static boolean hasNoDistinctWithFilterOrMask(AggregationNode aggregationNode) {
+ return aggregationNode.getAggregations().values().stream()
+ .noneMatch(
+ aggregation ->
+ aggregation.isDistinct()
+ && (aggregation.getFilter().isPresent() || aggregation.getMask().isPresent()));
Review Comment:
Will filter in Aggregation be Introduced in the future?
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add optimizers for distinct in AggFunction [iotdb]
Posted by "Wei-hao-Li (via GitHub)" <gi...@apache.org>.
Wei-hao-Li commented on code in PR #14729:
URL: https://github.com/apache/iotdb/pull/14729#discussion_r1924596156
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/MultipleDistinctAggregationToMarkDistinct.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.iotdb.db.queryengine.plan.relational.planner.iterative.rule;
+
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.Symbol;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.iterative.Rule;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.node.AggregationNode;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.node.MarkDistinctNode;
+import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Captures;
+import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Pattern;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.Patterns.aggregation;
+import static org.apache.tsfile.read.common.type.BooleanType.BOOLEAN;
+
+/**
+ * Implements distinct aggregations with different inputs by transforming plans of the following
+ * shape:
+ *
+ * <pre>
+ * - Aggregation
+ * GROUP BY (k)
+ * F1(DISTINCT a0, a1, ...)
+ * F2(DISTINCT b0, b1, ...)
+ * F3(c0, c1, ...)
+ * - X
+ * </pre>
+ *
+ * into
+ *
+ * <pre>
+ * - Aggregation
+ * GROUP BY (k)
+ * F1(a0, a1, ...) mask ($0)
+ * F2(b0, b1, ...) mask ($1)
+ * F3(c0, c1, ...)
+ * - MarkDistinct (k, a0, a1, ...) -> $0
+ * - MarkDistinct (k, b0, b1, ...) -> $1
+ * - X
+ * </pre>
+ */
+public class MultipleDistinctAggregationToMarkDistinct implements Rule<AggregationNode> {
+ private static final Pattern<AggregationNode> PATTERN =
+ aggregation()
+ .matching(
+ Predicates.and(
+ MultipleDistinctAggregationToMarkDistinct::hasNoDistinctWithFilterOrMask,
+ Predicates.or(
+ MultipleDistinctAggregationToMarkDistinct::hasMultipleDistincts,
+ MultipleDistinctAggregationToMarkDistinct::hasMixedDistinctAndNonDistincts)));
+
+ private static boolean hasNoDistinctWithFilterOrMask(AggregationNode aggregationNode) {
+ return aggregationNode.getAggregations().values().stream()
+ .noneMatch(
+ aggregation ->
+ aggregation.isDistinct()
+ && (aggregation.getFilter().isPresent() || aggregation.getMask().isPresent()));
Review Comment:
Filter is an another feature of AggFunction, it hasn't been supported in our project, so `aggregation.getFilter().isPresent()` will always be false.
<img width="683" alt="image" src="https://github.com/user-attachments/assets/7d8bc07a-1328-4985-a7a6-c27e6d7ad1ae" />
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add optimizers for distinct in AggFunction [iotdb]
Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 commented on code in PR #14729:
URL: https://github.com/apache/iotdb/pull/14729#discussion_r1924663691
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/MultipleDistinctAggregationToMarkDistinct.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.iotdb.db.queryengine.plan.relational.planner.iterative.rule;
+
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.Symbol;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.iterative.Rule;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.node.AggregationNode;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.node.MarkDistinctNode;
+import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Captures;
+import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Pattern;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.Patterns.aggregation;
+import static org.apache.tsfile.read.common.type.BooleanType.BOOLEAN;
+
+/**
+ * Implements distinct aggregations with different inputs by transforming plans of the following
+ * shape:
+ *
+ * <pre>
+ * - Aggregation
+ * GROUP BY (k)
+ * F1(DISTINCT a0, a1, ...)
+ * F2(DISTINCT b0, b1, ...)
+ * F3(c0, c1, ...)
+ * - X
+ * </pre>
+ *
+ * into
+ *
+ * <pre>
+ * - Aggregation
+ * GROUP BY (k)
+ * F1(a0, a1, ...) mask ($0)
+ * F2(b0, b1, ...) mask ($1)
+ * F3(c0, c1, ...)
+ * - MarkDistinct (k, a0, a1, ...) -> $0
+ * - MarkDistinct (k, b0, b1, ...) -> $1
+ * - X
+ * </pre>
+ */
+public class MultipleDistinctAggregationToMarkDistinct implements Rule<AggregationNode> {
+ private static final Pattern<AggregationNode> PATTERN =
+ aggregation()
+ .matching(
+ Predicates.and(
+ MultipleDistinctAggregationToMarkDistinct::hasNoDistinctWithFilterOrMask,
+ Predicates.or(
+ MultipleDistinctAggregationToMarkDistinct::hasMultipleDistincts,
+ MultipleDistinctAggregationToMarkDistinct::hasMixedDistinctAndNonDistincts)));
+
+ private static boolean hasNoDistinctWithFilterOrMask(AggregationNode aggregationNode) {
+ return aggregationNode.getAggregations().values().stream()
+ .noneMatch(
+ aggregation ->
+ aggregation.isDistinct()
+ && (aggregation.getFilter().isPresent() || aggregation.getMask().isPresent()));
Review Comment:
may be, hhhhhh, in far away future.
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add optimizers for distinct in AggFunction [iotdb]
Posted by "lancelly (via GitHub)" <gi...@apache.org>.
lancelly commented on code in PR #14729:
URL: https://github.com/apache/iotdb/pull/14729#discussion_r1924589183
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/MultipleDistinctAggregationToMarkDistinct.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.iotdb.db.queryengine.plan.relational.planner.iterative.rule;
+
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.Symbol;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.iterative.Rule;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.node.AggregationNode;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.node.MarkDistinctNode;
+import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Captures;
+import org.apache.iotdb.db.queryengine.plan.relational.utils.matching.Pattern;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.iotdb.db.queryengine.plan.relational.planner.node.Patterns.aggregation;
+import static org.apache.tsfile.read.common.type.BooleanType.BOOLEAN;
+
+/**
+ * Implements distinct aggregations with different inputs by transforming plans of the following
+ * shape:
+ *
+ * <pre>
+ * - Aggregation
+ * GROUP BY (k)
+ * F1(DISTINCT a0, a1, ...)
+ * F2(DISTINCT b0, b1, ...)
+ * F3(c0, c1, ...)
+ * - X
+ * </pre>
+ *
+ * into
+ *
+ * <pre>
+ * - Aggregation
+ * GROUP BY (k)
+ * F1(a0, a1, ...) mask ($0)
+ * F2(b0, b1, ...) mask ($1)
+ * F3(c0, c1, ...)
+ * - MarkDistinct (k, a0, a1, ...) -> $0
+ * - MarkDistinct (k, b0, b1, ...) -> $1
+ * - X
+ * </pre>
+ */
+public class MultipleDistinctAggregationToMarkDistinct implements Rule<AggregationNode> {
+ private static final Pattern<AggregationNode> PATTERN =
+ aggregation()
+ .matching(
+ Predicates.and(
+ MultipleDistinctAggregationToMarkDistinct::hasNoDistinctWithFilterOrMask,
+ Predicates.or(
+ MultipleDistinctAggregationToMarkDistinct::hasMultipleDistincts,
+ MultipleDistinctAggregationToMarkDistinct::hasMixedDistinctAndNonDistincts)));
+
+ private static boolean hasNoDistinctWithFilterOrMask(AggregationNode aggregationNode) {
+ return aggregationNode.getAggregations().values().stream()
+ .noneMatch(
+ aggregation ->
+ aggregation.isDistinct()
+ && (aggregation.getFilter().isPresent() || aggregation.getMask().isPresent()));
Review Comment:
What is the difference between filter and mask? Perhaps you need to deal with filter Using the Rule `ImplementFilteredAggregations`
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add optimizers for distinct in AggFunction [iotdb]
Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 merged PR #14729:
URL: https://github.com/apache/iotdb/pull/14729
--
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: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org