mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-13 14:16:54 +00:00
test(python): cover merge insert with schema metadata
Add a Python regression test for merging metadata-free data into a table whose target schema has metadata. The test calls the native `execute_merge_insert` binding directly so it exercises the native partial-schema comparison without the public merge path normalizing source metadata. The test verifies that merge insert succeeds with the expected rows and preserves the target schema metadata. Fixes #2058
This commit is contained in:
@@ -3509,6 +3509,40 @@ def test_merge_insert(mem_db: DBConnection):
|
||||
)
|
||||
|
||||
|
||||
def test_merge_insert_with_schema_metadata(mem_db: DBConnection):
|
||||
schema = pa.schema(
|
||||
[pa.field("id", pa.int64()), pa.field("value", pa.string())],
|
||||
metadata={b"schema_key": b"schema_value"},
|
||||
)
|
||||
table = mem_db.create_table("my_table", schema=schema)
|
||||
new_data = pa.table({"id": [1, 2], "value": ["one", "two"]})
|
||||
assert new_data.schema.metadata is None
|
||||
|
||||
async def do_merge_insert():
|
||||
return await table._inner.execute_merge_insert(
|
||||
new_data.to_reader(),
|
||||
{
|
||||
"on": ["id"],
|
||||
"when_matched_update_all": True,
|
||||
"when_matched_update_all_condition": None,
|
||||
"when_not_matched_insert_all": True,
|
||||
"when_not_matched_by_source_delete": False,
|
||||
"when_not_matched_by_source_condition": None,
|
||||
"when_not_matched_by_source_condition_expr": None,
|
||||
"timeout": None,
|
||||
"use_index": True,
|
||||
"use_rte": None,
|
||||
"validate_single_shard": None,
|
||||
},
|
||||
)
|
||||
|
||||
result = table_module.LOOP.run(do_merge_insert())
|
||||
|
||||
assert result.num_inserted_rows == 2
|
||||
assert table.to_arrow() == new_data
|
||||
assert table.schema.metadata == schema.metadata
|
||||
|
||||
|
||||
def test_merge_insert_composite_key(mem_db: DBConnection):
|
||||
table = mem_db.create_table(
|
||||
"my_table",
|
||||
|
||||
Reference in New Issue
Block a user