mihaibudiu commented on code in PR #3883: URL: https://github.com/apache/calcite/pull/3883#discussion_r1708515891
########## core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAsofJoin.java: ########## @@ -0,0 +1,253 @@ +/* + * 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.adapter.enumerable; + +import org.apache.calcite.linq4j.tree.BlockBuilder; +import org.apache.calcite.linq4j.tree.Expression; +import org.apache.calcite.linq4j.tree.Expressions; +import org.apache.calcite.plan.DeriveMode; +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.RelCollation; +import org.apache.calcite.rel.RelCollationTraitDef; +import org.apache.calcite.rel.RelCollations; +import org.apache.calcite.rel.RelFieldCollation; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.core.CorrelationId; +import org.apache.calcite.rel.core.Join; +import org.apache.calcite.rel.core.JoinRelType; +import org.apache.calcite.rel.logical.LogicalAsofJoin; +import org.apache.calcite.rel.metadata.RelMdCollation; +import org.apache.calcite.rel.metadata.RelMetadataQuery; +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexInputRef; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.util.BuiltInMethod; +import org.apache.calcite.util.Pair; + +import com.google.common.collect.ImmutableList; + +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** Implementation of {@link LogicalAsofJoin} in + * {@link EnumerableConvention enumerable calling convention}. */ +public class EnumerableAsofJoin extends Join implements EnumerableRel { + // This implementation is based on {@link EnumerableHashJoin} + + /** Compared to standard joins, ASOF joins have an additional condition for comparing timestamps. + * This is the additional condition. */ + final RexNode matchCondition; + + /** Creates an EnumerableAsofJoin. + * + * <p>Use {@link #create} unless you know what you're doing. */ + protected EnumerableAsofJoin( + RelOptCluster cluster, + RelTraitSet traits, + RelNode left, + RelNode right, + RexNode condition, + RexNode matchCondition, + Set<CorrelationId> variablesSet, + JoinRelType joinType) { + super( + cluster, + traits, + ImmutableList.of(), + left, + right, + condition, + variablesSet, + joinType); + this.matchCondition = matchCondition; + } + + /** Creates an EnumerableAsofJoin. */ + public static EnumerableAsofJoin create( + RelNode left, + RelNode right, + RexNode condition, + RexNode matchCondition, + Set<CorrelationId> variablesSet, + JoinRelType joinType) { + final RelOptCluster cluster = left.getCluster(); + final RelMetadataQuery mq = cluster.getMetadataQuery(); + final RelTraitSet traitSet = + cluster.traitSetOf(EnumerableConvention.INSTANCE) + .replaceIfs(RelCollationTraitDef.INSTANCE, + () -> RelMdCollation.enumerableHashJoin(mq, left, right, joinType)); + return new EnumerableAsofJoin(cluster, traitSet, left, right, condition, matchCondition, + variablesSet, joinType); + } + + @Override public EnumerableAsofJoin copy(RelTraitSet traitSet, RexNode condition, + RelNode left, RelNode right, JoinRelType joinType, + boolean semiJoinDone) { + // This method does not know about the matchCondition, so it should not be called Review Comment: Certainly this method cannot be right, so it's better to catch attempts to call it. -- 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]
