xuzifu666 commented on code in PR #4369: URL: https://github.com/apache/calcite/pull/4369#discussion_r2086209091
########## core/src/main/java/org/apache/calcite/rel/rules/AggregateValueReduceRule.java: ########## @@ -0,0 +1,104 @@ +/* + * 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.calcite.rel.rules; + +import org.apache.calcite.plan.RelOptRuleCall; +import org.apache.calcite.plan.RelRule; +import org.apache.calcite.rel.core.Aggregate; +import org.apache.calcite.rel.core.Values; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.tools.RelBuilder; +import org.apache.calcite.tools.RelBuilderFactory; + +import com.google.common.collect.ImmutableList; + +import org.immutables.value.Value; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Rule that applies an {@link Aggregate} to a distinct {@link Values}. + * + * <p>This is useful because such as {@link SubQueryRemoveRule} + * doesn't distinct values for IN filter values. + * + * <p>Sample query where this matters: + * + * <blockquote><code> + * LogicalAggregate(group=[{0}]) + * LogicalValues(tuples=[[{ 1 }, { 1 }, { 3 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, + * { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }, { 1 }]]) + * </code></blockquote> + * + * <p>should be converted to: + * + * <blockquote><code> + * LogicalValues(tuples=[[{ 1 }, { 3 }]]) + * </code></blockquote> + * + * @see CoreRules#AGGREGATE_VALUES_REDUCE + */ [email protected] +public class AggregateValueReduceRule + extends RelRule<AggregateValueReduceRule.Config> + implements SubstitutionRule { + + /** Creates an AggregateValuesRule. */ + protected AggregateValueReduceRule(Config config) { + super(config); + } + + public AggregateValueReduceRule(RelBuilderFactory relBuilderFactory) { Review Comment: Yes, not need it, had removed~ ########## core/src/main/java/org/apache/calcite/rel/rules/AggregateValueReduceRule.java: ########## @@ -0,0 +1,104 @@ +/* + * 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.calcite.rel.rules; + +import org.apache.calcite.plan.RelOptRuleCall; +import org.apache.calcite.plan.RelRule; +import org.apache.calcite.rel.core.Aggregate; +import org.apache.calcite.rel.core.Values; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.tools.RelBuilder; +import org.apache.calcite.tools.RelBuilderFactory; + +import com.google.common.collect.ImmutableList; + +import org.immutables.value.Value; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Rule that applies an {@link Aggregate} to a distinct {@link Values}. 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
