korlov42 commented on code in PR #7959: URL: https://github.com/apache/ignite-3/pull/7959#discussion_r3078582235
########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/logical/PruneTableModifyRule.java: ########## @@ -0,0 +1,80 @@ +/* + * 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.sql.engine.rule.logical; + +import java.util.Collections; +import java.util.List; +import org.apache.calcite.plan.RelOptRule; +import org.apache.calcite.plan.RelOptRuleCall; +import org.apache.calcite.plan.RelRule; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.core.TableModify; +import org.apache.calcite.rel.core.Values; +import org.apache.calcite.rel.rules.SubstitutionRule; +import org.apache.calcite.rex.RexLiteral; +import org.apache.ignite.internal.sql.engine.rex.IgniteRexBuilder; +import org.apache.ignite.internal.sql.engine.rule.logical.PruneTableModifyRule.Config; +import org.immutables.value.Value; + +/** + * Rule that eliminates table modify node if it doesn't have any source rows. + */ [email protected] +public class PruneTableModifyRule extends RelRule<Config> implements SubstitutionRule { + public static final RelOptRule INSTANCE = Config.DEFAULT.toRule(); + + /** + * Constructor. + * + * @param config Rule configuration. + */ + private PruneTableModifyRule(PruneTableModifyRule.Config config) { + super(config); + } + + @Override public void onMatch(RelOptRuleCall call) { + TableModify singleRel = call.rel(0); + + // TODO https://issues.apache.org/jira/browse/IGNITE-23512: Default Calcite RexBuilder ignores field type and extract type from + // the given value. E.g. for zero value RexBuilder creates INT literal. Use simple way create `singleValue` after fixing the issue. + // RelNode singleValue = call.builder().values(singleRel.getRowType(), 0L).build(); + RexLiteral zeroLiteral = IgniteRexBuilder.INSTANCE.makeLiteral(0L, singleRel.getRowType().getFieldList().get(0).getType()); + RelNode singleValue = call.builder().values(List.of(List.of(zeroLiteral)), singleRel.getRowType()).build(); + + RelTraitSet traits = singleRel.getTraitSet(); + // propagate all traits (except convention) from the original singleRel Review Comment: why do we need this extra step of trait propagation? I think it's ok to emit logical node with default set of traits. Conversion to physical + trait propagation will do the job ########## modules/sql-engine/src/test/resources/mapping/test_partition_pruning.test: ########## @@ -164,57 +164,20 @@ Fragment#4 est: (rows=1) --- # Self join, different predicates that produce disjoint set of partitions -# TODO https://issues.apache.org/jira/browse/IGNITE-28389: Fix the test. We expect the mapper should eliminate all the disjoined parts. N1 SELECT /*+ DISABLE_RULE('NestedLoopJoinConverter', 'HashJoinConverter', 'CorrelatedNestedLoopJoin') */ * FROM t1_n1n2n3 as t1, t1_n1n2n3 as t2 WHERE t1.id = t2.id and t1.id IN (1, 3) and t2.id IN (42, 44) --- Review Comment: I think it's better to remove this test case completely because empty Values node doesn't bring much value for partition pruning test scenarios -- 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]
