SavicStefan commented on code in PR #59134:
URL: https://github.com/apache/spark/pull/59134#discussion_r4165149985
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -2890,8 +2892,10 @@ object AsOfJoin {
(leftOperand.dataType, rightOperand.dataType) match {
case (leftStruct: StructType, rightStruct: StructType)
if MatchConditionTypes.usesIdenticalStructSort(leftStruct,
rightStruct) =>
- if (isSqlTupleStructOperand(leftOperand) ||
isSqlTupleStructOperand(rightOperand)) {
- val pairs = collectStructLeafPairs(leftOperand, rightOperand,
leftStruct)
+ if ((isSqlTupleStructOperand(leftOperand) ||
isSqlTupleStructOperand(rightOperand)) &&
+ !leftOperand.nullable && !rightOperand.nullable) {
Review Comment:
is there a reason SortMergeAsOfJoinExec requires the same number of sort
keys on both sides, because like If one operand is a SQL tuple and the other is
a STRUCT column, could we just return separate field expressions for that tuple
and one whole struct key for the column?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -3105,17 +3091,21 @@ object AsOfJoin {
wrapCompositeOrderExpression(leafDiffs)
}
+ /** `splitNullableStructs = false` keeps a struct pair whole when either
side can be NULL. */
private def collectStructLeafPairs(
leftOperand: Expression,
rightOperand: Expression,
- structType: StructType): Seq[(Expression, Expression)] = {
+ structType: StructType,
+ splitNullableStructs: Boolean = true): Seq[(Expression, Expression)] = {
structFieldExprs(leftOperand, structType)
.zip(structFieldExprs(rightOperand, structType))
.flatMap {
case (left, right) =>
- if (MatchConditionTypes.usesStructDecomposition(left.dataType,
right.dataType)) {
+ val canSplit = splitNullableStructs || (!left.nullable &&
!right.nullable)
+ if (canSplit &&
+ MatchConditionTypes.usesStructDecomposition(left.dataType,
right.dataType)) {
Review Comment:
I think this is the pattern and it looks better
```suggestion
if (splitNullableStructs || (!left.nullable && !right.nullable)) &&
MatchConditionTypes.usesStructDecomposition(left.dataType,
right.dataType) =>
```
--
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]