-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24991][SQL] use InternalRow in DataSourceWriter #21948
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 1 commit
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 |
|---|---|---|
|
|
@@ -89,7 +89,8 @@ class RateStreamContinuousReader(options: DataSourceOptions) extends ContinuousR | |
| start.runTimeMs, | ||
| i, | ||
| numPartitions, | ||
| perPartitionRate): InputPartition[InternalRow] | ||
| perPartitionRate) | ||
| .asInstanceOf[InputPartition[InternalRow]] | ||
|
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. Why is this cast necessary?
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. This is to address your comments: do not mix read-side changes. So I reverted it.
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. Okay, sorry about that. I should have looked at the whole diff. |
||
| }.asJava | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package org.apache.spark.sql.execution.streaming | |
|
|
||
| import org.scalatest.BeforeAndAfter | ||
|
|
||
| import org.apache.spark.sql.Row | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.execution.streaming.sources._ | ||
| import org.apache.spark.sql.streaming.{OutputMode, StreamTest} | ||
|
|
@@ -27,7 +28,8 @@ import org.apache.spark.sql.types.StructType | |
| class MemorySinkV2Suite extends StreamTest with BeforeAndAfter { | ||
| test("data writer") { | ||
| val partition = 1234 | ||
| val writer = new MemoryDataWriter(partition, OutputMode.Append()) | ||
| val writer = new MemoryDataWriter( | ||
| partition, OutputMode.Append(), new StructType().add("i", "int")) | ||
| writer.write(InternalRow(1)) | ||
| writer.write(InternalRow(2)) | ||
| writer.write(InternalRow(44)) | ||
|
|
@@ -44,16 +46,16 @@ class MemorySinkV2Suite extends StreamTest with BeforeAndAfter { | |
| val writer = new MemoryStreamWriter(sink, OutputMode.Append(), new StructType().add("i", "int")) | ||
| writer.commit(0, | ||
| Array( | ||
| MemoryWriterCommitMessage(0, Seq(InternalRow(1), InternalRow(2))), | ||
| MemoryWriterCommitMessage(1, Seq(InternalRow(3), InternalRow(4))), | ||
| MemoryWriterCommitMessage(2, Seq(InternalRow(6), InternalRow(7))) | ||
| MemoryWriterCommitMessage(0, Seq(Row(1), Row(2))), | ||
|
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. Why was this changed back to Row?
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. Now the
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. Why not use InternalRow.copy? I'd rather keep the update to InternalRow, but as long as the tests pass I wouldn't block this.
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. because the memory sink needs
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. Sounds good. Thanks for explaining your rationale. |
||
| MemoryWriterCommitMessage(1, Seq(Row(3), Row(4))), | ||
| MemoryWriterCommitMessage(2, Seq(Row(6), Row(7))) | ||
| )) | ||
| assert(sink.latestBatchId.contains(0)) | ||
| assert(sink.latestBatchData.map(_.getInt(0)).sorted == Seq(1, 2, 3, 4, 6, 7)) | ||
| writer.commit(19, | ||
| Array( | ||
| MemoryWriterCommitMessage(3, Seq(InternalRow(11), InternalRow(22))), | ||
| MemoryWriterCommitMessage(0, Seq(InternalRow(33))) | ||
| MemoryWriterCommitMessage(3, Seq(Row(11), Row(22))), | ||
| MemoryWriterCommitMessage(0, Seq(Row(33))) | ||
| )) | ||
| assert(sink.latestBatchId.contains(19)) | ||
| assert(sink.latestBatchData.map(_.getInt(0)).sorted == Seq(11, 22, 33)) | ||
|
|
@@ -66,16 +68,16 @@ class MemorySinkV2Suite extends StreamTest with BeforeAndAfter { | |
| val schema = new StructType().add("i", "int") | ||
| new MemoryWriter(sink, 0, OutputMode.Append(), schema).commit( | ||
| Array( | ||
| MemoryWriterCommitMessage(0, Seq(InternalRow(1), InternalRow(2))), | ||
| MemoryWriterCommitMessage(1, Seq(InternalRow(3), InternalRow(4))), | ||
| MemoryWriterCommitMessage(2, Seq(InternalRow(6), InternalRow(7))) | ||
| MemoryWriterCommitMessage(0, Seq(Row(1), Row(2))), | ||
| MemoryWriterCommitMessage(1, Seq(Row(3), Row(4))), | ||
| MemoryWriterCommitMessage(2, Seq(Row(6), Row(7))) | ||
| )) | ||
| assert(sink.latestBatchId.contains(0)) | ||
| assert(sink.latestBatchData.map(_.getInt(0)).sorted == Seq(1, 2, 3, 4, 6, 7)) | ||
| new MemoryWriter(sink, 19, OutputMode.Append(), schema).commit( | ||
| Array( | ||
| MemoryWriterCommitMessage(3, Seq(InternalRow(11), InternalRow(22))), | ||
| MemoryWriterCommitMessage(0, Seq(InternalRow(33))) | ||
| MemoryWriterCommitMessage(3, Seq(Row(11), Row(22))), | ||
| MemoryWriterCommitMessage(0, Seq(Row(33))) | ||
| )) | ||
| assert(sink.latestBatchId.contains(19)) | ||
| assert(sink.latestBatchData.map(_.getInt(0)).sorted == Seq(11, 22, 33)) | ||
|
|
||
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.
nit: the description about defensive copied in data writers, may be put in
DataWriter.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.
I'll fix it in my next PR, thanks!