albertobastos commented on code in PR #15630: URL: https://github.com/apache/pinot/pull/15630#discussion_r2063684134
########## pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/AsofJoinOperator.java: ########## @@ -0,0 +1,183 @@ +/** + * 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.pinot.query.runtime.operator; + +import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.TreeMap; +import javax.annotation.Nullable; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.query.planner.logical.RexExpression; +import org.apache.pinot.query.planner.partitioning.KeySelector; +import org.apache.pinot.query.planner.partitioning.KeySelectorFactory; +import org.apache.pinot.query.planner.plannode.JoinNode; +import org.apache.pinot.query.runtime.blocks.MseBlock; +import org.apache.pinot.query.runtime.plan.OpChainExecutionContext; + + +public class AsofJoinOperator extends BaseJoinOperator { + private static final String EXPLAIN_NAME = "ASOF_JOIN"; + + private final Map<Object, NavigableMap<Comparable<?>, Object[]>> _rightTable; + private final KeySelector<?> _leftKeySelector; + private final KeySelector<?> _rightKeySelector; + private final MatchConditionType _matchConditionType; + private final int _leftMatchKeyIndex; + private final int _rightMatchKeyIndex; + + public AsofJoinOperator(OpChainExecutionContext context, MultiStageOperator leftInput, DataSchema leftSchema, + MultiStageOperator rightInput, JoinNode node) { + super(context, leftInput, leftSchema, rightInput, node); + Preconditions.checkState(node.getNonEquiConditions().isEmpty(), + "ASOF_JOIN operator cannot have non-equi join keys"); + Preconditions.checkState(node.getMatchCondition() != null, "ASOF_JOIN operator must have a match condition"); + _rightTable = new HashMap<>(); + List<Integer> leftKeys = node.getLeftKeys(); + + _leftKeySelector = KeySelectorFactory.getKeySelector(leftKeys); + _rightKeySelector = KeySelectorFactory.getKeySelector(node.getRightKeys()); + + RexExpression matchCondition = node.getMatchCondition(); + Preconditions.checkState(matchCondition instanceof RexExpression.FunctionCall, + "ASOF_JOIN operator only supports function call match condition"); + + try { + _matchConditionType = + MatchConditionType.valueOf(((RexExpression.FunctionCall) matchCondition).getFunctionName().toUpperCase()); + } catch (IllegalArgumentException e) { + throw new UnsupportedOperationException("Unsupported match condition: " + matchCondition); + } + List<RexExpression> matchKeys = ((RexExpression.FunctionCall) matchCondition).getFunctionOperands(); + // TODO: Add support for MATCH_CONDITION containing two columns of different types. In that case, there would be + // a CAST RexExpression.FunctionCall on top of the RexExpression.InputRef, and we'd need to add the + // appropriate type casts to make sure that the Comparable based comparisons in this class don't throw + // ClassCastException. + Preconditions.checkState( + matchKeys.size() == 2 && matchKeys.get(0) instanceof RexExpression.InputRef + && matchKeys.get(1) instanceof RexExpression.InputRef, + "ASOF_JOIN operator only supports match conditions with a comparison between two columns of the same type"); Review Comment: How is this checking that both columns are of the same type? I'm only seeing it checking they are instances of type `InputRef`, but maybe I'm missing something. -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org