Repository navigation
fix: preserve overwrite schema changes - #5161
Open
LuciferYang wants to merge 6 commits into
Open
LuciferYang wants to merge 6 commits into
LuciferYang wants to merge 6 commits into
Conversation
Distributed create/overwrite writes assign Lance field ids positionally, so blocks whose columns arrive in a different order (e.g. a union of differently ordered sources) were committed under a single schema and read back transposed. Add a guard in LanceDatasink.on_write_complete that raises on inconsistent column order, and align Arrow blocks by name in pd_to_arrow so an explicit schema writes correctly. Also harden the schema-evolution mode plumbing: document per-mode schema behaviour (append validates/drops; create and overwrite evolve the schema), fix the LanceDatasink default-mode docstring, document the write_fragment mode parameter and the writer/committer mode-pairing requirement, and add regression tests for multi-fragment overwrite, schema drop/type-change, streaming overwrite resume, streaming-append rejection, and the column-order guard.
Author
|
cc @jackye1995 FYI |
…ema-evolution # Conflicts: # lance_ray/fragment.py # lance_ray/io.py # tests/test_basic_read_write.py # tests/test_fragment.py
…ema-evolution # Conflicts: # lance_ray/fragment.py
Author
|
@yanghua @ddupg when you have a moment, could you approve the pending PR Checks run and comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
write_lance(ds, uri, mode="overwrite")failed whenever the new data had a different schema from the existing dataset, for example afterds.with_column("id_2", ...)as in #95:The cause is that lance-ray called pylance's
write_fragmentswithoutmode, so every fragment was validated as an append against the existing schema, even when the commit that followed was anOverwrite.stream=Truefailed the same way.What changed
write_fragmentandLanceFragmentWritertake amodeand pass it towrite_fragments. They default to"append", so direct callers keep the old validation.LanceDatasinkpasses its own mode, socreateandoverwritewrite fragments under the incoming schema and an overwrite can add, drop or retype columns."append", since those append to the dataset the first batch just created or overwrote.Need at least 16 bytes in buffers[0]on read).on_write_completenow merges the block schemas before committing: types must be equal (solist<item>andlist<element>match), a column that is all null in some blocks takes the type from the other blocks, and a column is nullable if any block allows nulls. Any other difference raises before committing and suggests passingschema=.schema,pd_to_arrowreorders an Arrow block to the schema's column order before casting, so differently ordered blocks line up by name. Blocks whose column names differ from the schema still fail as before.LanceFragmentWriterandLanceFragmentCommitterselect the mode separately. The writer docstring says to pass the same mode to both when overwriting with a new schema.Tests
New tests in
tests/test_basic_read_write.pycover overwrite with an added, dropped or retyped column, both non-streaming and withstream=True(includingresume_rows), across multiple fragments, and through a directory namespace. They also cover:tests/test_fragment.pyadds the writer + committer overwrite case. The overwrite and column-order tests fail on main.Closes #95
🤖 Generated with Claude Opus