Skip to content

Commit da3d638

Browse files
vuanhphungIsaac
andcommitted
test(kernel): pin schema-mismatch handling on the kernel-rows path
Review feedback: a batch whose types differ from the declared schema still fails as before when the kernel has fetch_all_rows (the kernel declines it, then Table.from_batches raises), the real kernel's conversion declines such batches, and SchemaKey tells apart schemas that differ in nullability, name or type. Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 0fca9d7 commit da3d638

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎tests/unit/test_kernel_result_set.py‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,13 @@ def batch(lo, hi):
626626
to_table.assert_called_once()
627627

628628

629-
def test_a_batch_whose_schema_differs_still_fails_as_before():
629+
@pytest.mark.parametrize("handle_type", ["_FakeKernelHandle", "_FakeRowsHandle"])
630+
def test_a_batch_whose_schema_differs_still_fails_as_before(handle_type):
630631
schema = pa.schema([("n", pa.int64())])
631632
other = pa.RecordBatch.from_arrays([pa.array(["x"])], names=["n"])
633+
handle = globals()[handle_type](schema, [other])
632634
with pytest.raises(pa.ArrowInvalid):
633-
_make_rs(_FakeKernelHandle(schema, [other])).fetchall()
635+
_make_rs(handle).fetchall()
634636

635637

636638
def test_the_cost_budget_is_computed_once_per_schema_not_per_fetch():
@@ -699,6 +701,9 @@ def fetch_all_rows(self, max_rows, nan_ok=False):
699701
return None
700702
if sum(b.num_rows for b in self._pending) > max_rows:
701703
return None
704+
# The kernel declines batches whose column types differ.
705+
if any(b.schema.types != self._schema.types for b in self._pending):
706+
return None
702707
columns = [[] for _ in self._schema]
703708
for batch in self._pending:
704709
for values, column in zip(columns, batch.columns):
@@ -1015,6 +1020,20 @@ def test_handles_take_the_arguments_this_module_passes(self):
10151020
key = kernel.SchemaKey(schema)
10161021
assert key == kernel.SchemaKey(_reimported(schema))
10171022
assert key != kernel.SchemaKey(pa.schema([pa.field("n", pa.int64())]))
1023+
# Keys tell apart everything Schema.equals(check_metadata=True) does.
1024+
for other in (
1025+
schema.field(0).with_nullable(False),
1026+
schema.field(0).with_name("m"),
1027+
schema.field(0).with_type(pa.int32()),
1028+
):
1029+
assert not schema.equals(pa.schema([other]), check_metadata=True)
1030+
assert key != kernel.SchemaKey(pa.schema([other]))
1031+
# The conversion declines a batch whose column types differ.
1032+
batches = [
1033+
pa.record_batch([pa.array([1])], names=["n"]),
1034+
pa.record_batch([pa.array(["x"])], names=["n"]),
1035+
]
1036+
assert self._rows_from_arrow()(batches) is None
10181037
cache = kernel_result_set._SchemaCache()
10191038
cache.get(schema, key)
10201039
assert cache.get_by_key(kernel.SchemaKey(_reimported(schema))) is not None

0 commit comments

Comments
 (0)