Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,8 +102,8 @@ object V1Writes extends Rule[LogicalPlan] with SQLConfHelper {
val requiredOrdering = write.requiredOrdering.map(_.transform {
case a: Attribute => attrMap.getOrElse(a, a)
}.asInstanceOf[SortOrder])
val outputOrdering = query.outputOrdering
val orderingMatched = isOrderingMatched(requiredOrdering, outputOrdering)
val outputOrdering = empty2NullPlan.outputOrdering

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rough remember before we did not support preserve ordering through empty2null so use the query.outputOrdering. I think use empty2NullPlan.outputOrdering is the expected behavior

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea Project is an OrderPreservingUnaryNode so it should be fine.

val orderingMatched = isOrderingMatched(requiredOrdering.map(_.child), outputOrdering)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what def isOrderingMatched does is outputOrder.satisfies(outputOrder.copy(child = requiredOrder)), so it's completely wrong to pass requiredOrdering as a Seq[SortOrder]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, so it was never matched before...

if (orderingMatched) {
empty2NullPlan
} else {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -223,24 +223,15 @@ class V1WriteCommandSuite extends QueryTest with SharedSparkSession with V1Write
}

// assert the outer most sort in the executed plan
val sort = plan.collectFirst { case s: SortExec => s }
if (enabled) {
// With planned write, optimizer is more efficient and can eliminate the `SORT BY`.
assert(sort.exists {
case SortExec(Seq(
SortOrder(AttributeReference("key", IntegerType, _, _), Ascending, NullsFirst, _)
), false, _, _) => true
case _ => false
}, plan)
} else {
assert(sort.exists {
case SortExec(Seq(
SortOrder(AttributeReference("key", IntegerType, _, _), Ascending, NullsFirst, _),
SortOrder(AttributeReference("value", StringType, _, _), Ascending, NullsFirst, _)
), false, _, _) => true
case _ => false
}, plan)
}
assert(plan.collectFirst {
case s: SortExec => s
}.exists {
case SortExec(Seq(
SortOrder(AttributeReference("key", IntegerType, _, _), Ascending, NullsFirst, _),
SortOrder(AttributeReference("value", StringType, _, _), Ascending, NullsFirst, _)
), false, _, _) => true
case _ => false
}, plan)
}
}
}
Expand DownExpand Up@@ -279,24 +270,15 @@ class V1WriteCommandSuite extends QueryTest with SharedSparkSession with V1Write
}

// assert the outer most sort in the executed plan
val sort = plan.collectFirst { case s: SortExec => s }
if (enabled) {
// With planned write, optimizer is more efficient and can eliminate the `SORT BY`.
assert(sort.exists {
case SortExec(Seq(
SortOrder(AttributeReference("value", StringType, _, _), Ascending, NullsFirst, _)
), false, _, _) => true
case _ => false
}, plan)
} else {
assert(sort.exists {
case SortExec(Seq(
SortOrder(AttributeReference("value", StringType, _, _), Ascending, NullsFirst, _),
SortOrder(AttributeReference("key", IntegerType, _, _), Ascending, NullsFirst, _)
), false, _, _) => true
case _ => false
}, plan)
}
assert(plan.collectFirst {
case s: SortExec => s
}.exists {
case SortExec(Seq(
SortOrder(AttributeReference("value", StringType, _, _), Ascending, NullsFirst, _),
SortOrder(AttributeReference("key", IntegerType, _, _), Ascending, NullsFirst, _)
), false, _, _) => true
case _ => false
}, plan)
}
}
}
Expand Down