Repository navigation
[SPARK-53546][SQL][TESTS] Fix InMemoryDataSource to return default value or null for new fields - #52299
[SPARK-53546][SQL][TESTS] Fix InMemoryDataSource to return default value or null for new fields#52299szehon-ho wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
this method is used by alterTable and regular write, so we have a flag newData=false to preserve the original 'writeSchema' for the BufferedRows in the alterTable case instead of using the new schema. In the write case, we mark the new rows with the new schema.
There was a problem hiding this comment.
I end up, making another method for alterTable to not pollute existing logic with if-else. That version preserves the 'writeSchema' on the BufferedRows.
…lue or null for new fields
6f66699 to
616f350
Compare
There was a problem hiding this comment.
Note: Array[Column] is not serializable, so hence passing StructType to these BatchWriterFactory and BatchWriters
5357f86 to
a1dc29c
Compare
|
thanks, merging to master! |
| def alterTableWithData(data: Array[BufferedRows], | ||
| newSchema: StructType): InMemoryBaseTable = { |
There was a problem hiding this comment.
style nit:
| def alterTableWithData(data: Array[BufferedRows], | |
| newSchema: StructType): InMemoryBaseTable = { | |
| def alterTableWithData( | |
| data: Array[BufferedRows], | |
| newSchema: StructType): InMemoryBaseTable = { |
There was a problem hiding this comment.
You can fix them in your next PR.
… style for InMemoryBaseTable ### What changes were proposed in this pull request? Fix nested array struct schema evolution case for InMemoryDataSource, also style fixes. ### Why are the changes needed? Address style review comment (#52299 (comment)) and a small bug fix for #52299 (test-only) ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Ran affected unit test ### Was this patch authored or co-authored using generative AI tooling? No Closes #52359 from szehon-ho/in_memory_schema_evolution_fix. Authored-by: Szehon Ho <szehon.apache@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
…lue or null for new fields ### What changes were proposed in this pull request? InMemoryTable does not handle schema evolution properly. In particular, it always uses the current schema to read the in-memory rows. For newly-added columns that don't exist in the row, the InternalRow sometimes return some junk value. This fixes InMemoryDataSource to properly handle schema evolution. Like modern table format, it persists the 'writeSchema' used to write the BufferedRows (on the BufferedRows object here), and then at read time resolves it with the 'readSchema'. ### Why are the changes needed? While writing tests for MERGE INTO schema evolution, realized that in these cases InMemoryTable is returning junk values, unlike a real V2 data source. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Add a new test in AlterTableTests ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#52299 from szehon-ho/in_memory_schema_evolution. Authored-by: Szehon Ho <szehon.apache@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
… style for InMemoryBaseTable ### What changes were proposed in this pull request? Fix nested array struct schema evolution case for InMemoryDataSource, also style fixes. ### Why are the changes needed? Address style review comment (apache#52299 (comment)) and a small bug fix for apache#52299 (test-only) ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Ran affected unit test ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#52359 from szehon-ho/in_memory_schema_evolution_fix. Authored-by: Szehon Ho <szehon.apache@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
InMemoryTable does not handle schema evolution properly. In particular, it always uses the current schema to read the in-memory rows. For newly-added columns that don't exist in the row, the InternalRow sometimes return some junk value.
This fixes InMemoryDataSource to properly handle schema evolution. Like modern table format, it persists the 'writeSchema' used to write the BufferedRows (on the BufferedRows object here), and then at read time resolves it with the 'readSchema'.
Why are the changes needed?
While writing tests for MERGE INTO schema evolution, realized that in these cases InMemoryTable is returning junk values, unlike a real V2 data source.
Does this PR introduce any user-facing change?
No
How was this patch tested?
Add a new test in AlterTableTests
Was this patch authored or co-authored using generative AI tooling?
No