Skip to content

Commit b7b610e

Browse files
JeetuSK0808claude
andauthored
fix: Pass plain values to Arrow for list columns (#438)
Fixes cloudquery/cloudquery#23799. @marianogappa looked it over on my fork first (JeetuSK0808#1) and asked me to open it here. `Resource.to_list_of_arr` passes `List.value`, which is a `Vector` of scalars, straight to pyarrow, so any row with a non-empty list column raises `ArrowTypeError` and the rest of the table is dropped. A null list also goes out as `[]`. - `resource.py`: a list column goes to pyarrow as a plain list of its items' values, or `None` when it's null. - `list.py`: an empty list is valid. This is the same line #423 changes. The new `tests/schema/test_resource.py` fails on `main` and passes here. pytest: 88 passed with the fix and 87 on `main`, and the one failure both times is `test_plugin_package`, which needs Docker. black is clean. I used Claude Code to find and check this. Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 60aca91 commit b7b610e

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎cloudquery/sdk/scalar/list.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def set(self, value: Any):
4242
scalar = self._type()
4343
scalar.set(item)
4444
self._value.append(scalar)
45-
self._valid = True
45+
self._valid = True
4646
return
4747

4848
raise ScalarInvalidTypeError(f"Invalid type {type(value)} for List")

‎cloudquery/sdk/schema/resource.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .table import Table
22
from typing import Any
33
import pyarrow as pa
4-
from cloudquery.sdk.scalar import ScalarFactory
4+
from cloudquery.sdk.scalar import List, Scalar, ScalarFactory
55

66

77
class Resource:
@@ -21,9 +21,19 @@ def set(self, column_name: str, value: Any):
2121
self._data[index_column].set(value)
2222

2323
def to_list_of_arr(self):
24-
return [[self._data[i].value] for i, _ in enumerate(self._table.columns)]
24+
return [
25+
[_arrow_value(self._data[i])] for i, _ in enumerate(self._table.columns)
26+
]
2527

2628
def to_arrow_record(self):
2729
return pa.record_batch(
2830
self.to_list_of_arr(), schema=self._table.to_arrow_schema()
2931
)
32+
33+
34+
def _arrow_value(scalar: Scalar):
35+
if not isinstance(scalar, List):
36+
return scalar.value
37+
if not scalar.is_valid:
38+
return None
39+
return [_arrow_value(item) for item in scalar.value]

‎tests/schema/test_resource.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pyarrow as pa
2+
3+
from cloudquery.sdk.schema import Column, Table
4+
from cloudquery.sdk.schema.resource import Resource
5+
6+
7+
def test_resource_to_arrow_record_with_list_columns():
8+
table = Table(
9+
"test_table",
10+
[
11+
Column("strings", pa.list_(pa.string())),
12+
Column("ints", pa.list_(pa.int64())),
13+
Column("empty", pa.list_(pa.string())),
14+
Column("null", pa.list_(pa.string())),
15+
Column("unset", pa.list_(pa.string())),
16+
],
17+
)
18+
resource = Resource(table, None, None)
19+
resource.set("strings", ["a", None, "b"])
20+
resource.set("ints", [1, 2])
21+
resource.set("empty", [])
22+
resource.set("null", None)
23+
assert resource.to_arrow_record() == pa.record_batch(
24+
[[["a", None, "b"]], [[1, 2]], [[]], [None], [None]],
25+
schema=table.to_arrow_schema(),
26+
)

0 commit comments

Comments
 (0)