-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-9054] [SQL] Rename RowOrdering to InterpretedOrdering; use newOrdering in SMJ #7973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,9 +48,6 @@ case class SortMergeJoin( | |
| override def requiredChildDistribution: Seq[Distribution] = | ||
| ClusteredDistribution(leftKeys) :: ClusteredDistribution(rightKeys) :: Nil | ||
|
|
||
| // this is to manually construct an ordering that can be used to compare keys from both sides | ||
| private val keyOrdering: RowOrdering = RowOrdering.forSchema(leftKeys.map(_.dataType)) | ||
|
|
||
| override def outputOrdering: Seq[SortOrder] = requiredOrders(leftKeys) | ||
|
|
||
| override def requiredChildOrdering: Seq[Seq[SortOrder]] = | ||
|
|
@@ -59,15 +56,19 @@ case class SortMergeJoin( | |
| @transient protected lazy val leftKeyGenerator = newProjection(leftKeys, left.output) | ||
| @transient protected lazy val rightKeyGenerator = newProjection(rightKeys, right.output) | ||
|
|
||
| private def requiredOrders(keys: Seq[Expression]): Seq[SortOrder] = | ||
| private def requiredOrders(keys: Seq[Expression]): Seq[SortOrder] = { | ||
| // This must be ascending in order to agree with the `keyOrdering` defined in `doExecute()`. | ||
| keys.map(SortOrder(_, Ascending)) | ||
| } | ||
|
|
||
| protected override def doExecute(): RDD[InternalRow] = { | ||
| val leftResults = left.execute().map(_.copy()) | ||
| val rightResults = right.execute().map(_.copy()) | ||
|
|
||
| leftResults.zipPartitions(rightResults) { (leftIter, rightIter) => | ||
| new Iterator[InternalRow] { | ||
| // An ordering that can be used to compare keys from both sides. | ||
| private[this] val keyOrdering = newNaturalAscendingOrdering(leftKeys.map(_.dataType)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we at a comment at https://github.com/apache/spark/pull/7973/files#diff-b669f8cf35f1d2d786582f4d8c49ed14R59 to explain the direction must be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| // Mutable per row objects. | ||
| private[this] val joinRow = new JoinedRow | ||
| private[this] var leftElement: InternalRow = _ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ import scala.util.Random | |
| import org.apache.spark._ | ||
| import org.apache.spark.sql.{RandomDataGenerator, Row} | ||
| import org.apache.spark.sql.catalyst.{CatalystTypeConverters, InternalRow} | ||
| import org.apache.spark.sql.catalyst.expressions.{UnsafeRow, RowOrdering, UnsafeProjection} | ||
| import org.apache.spark.sql.catalyst.expressions.{InterpretedOrdering, UnsafeRow, UnsafeProjection} | ||
| import org.apache.spark.sql.test.TestSQLContext | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.unsafe.memory.{ExecutorMemoryManager, MemoryAllocator, TaskMemoryManager} | ||
|
|
@@ -144,8 +144,8 @@ class UnsafeKVExternalSorterSuite extends SparkFunSuite { | |
| } | ||
| sorter.cleanupResources() | ||
|
|
||
| val keyOrdering = RowOrdering.forSchema(keySchema.map(_.dataType)) | ||
| val valueOrdering = RowOrdering.forSchema(valueSchema.map(_.dataType)) | ||
| val keyOrdering = InterpretedOrdering.forSchema(keySchema.map(_.dataType)) | ||
| val valueOrdering = InterpretedOrdering.forSchema(valueSchema.map(_.dataType)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use interpreted version because we do not have access to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. It shouldn't matter here in this test code, though.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, right. |
||
| val kvOrdering = new Ordering[(InternalRow, InternalRow)] { | ||
| override def compare(x: (InternalRow, InternalRow), y: (InternalRow, InternalRow)): Int = { | ||
| keyOrdering.compare(x._1, y._1) match { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this name also reflect its using
Ascending?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(super minor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh, it could. I only left it as-is out of a desire to minimize changes. Can fix later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it is totally fine to leave it as-is.