xumingming commented on code in PR #57162: URL: https://github.com/apache/spark/pull/57162#discussion_r3623205815
########## sql/core/src/main/scala/org/apache/spark/sql/execution/joins/StreamedSideJoinCondition.scala: ########## @@ -0,0 +1,58 @@ +/* + * 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.spark.sql.execution.joins + +import org.apache.spark.sql.catalyst.expressions.{And, Expression, PredicateHelper} +import org.apache.spark.sql.catalyst.plans.{ExistenceJoin, JoinType, LeftAnti, LeftOuter, RightOuter} +import org.apache.spark.sql.execution.SparkPlan + +/** + * Helper for splitting a join condition into a streamed-side-only part and the remaining part, + * for join types that preserve all streamed rows. + * + * The split is valid because for these join types, if a streamed-only predicate S is FALSE/NULL + * for a streamed row, the full join condition S AND other(S, B) is FALSE/NULL for ANY buffered + * row B. The streamed row outcome is therefore already determined before any probe: it is + * emitted for outer/existence joins, and emitted for left anti joins when no match exists. + */ +private[joins] object StreamedSideJoinCondition extends PredicateHelper { + + /** + * Splits `condition` into conjuncts that reference only the streamed side and the remaining + * conjuncts, when `splitEnabled` is true and the join type preserves all streamed rows. + * The streamed-only part can be evaluated once per streamed row before probing/walking the + * buffered matches. Returns `(None, condition)` unchanged otherwise. + */ + def split( + condition: Option[Expression], + joinType: JoinType, + streamedPlan: SparkPlan, + splitEnabled: Boolean): (Option[Expression], Option[Expression]) = { + val supported = joinType match { + case LeftAnti | LeftOuter | RightOuter | _: ExistenceJoin => true + case _ => false + } + if (condition.isDefined && splitEnabled && supported) { + val conjuncts = splitConjunctivePredicates(condition.get) + val (streamedOnly, rest) = conjuncts.partition(_.references.subsetOf(streamedPlan.outputSet)) Review Comment: Made the changes, created a testing udf: TestThrowableUDF to test the throwable behavior. BTW: the `throwable` property seems not widely adopted, only one usage in the Sequence expression. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
