Skip to content

Commit 5c68ad8

Browse files
authored
Support string_view and binary_view (#1748)
Resolves #1745
1 parent 5ccbfc3 commit 5c68ad8

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pyiceberg/io/pyarrow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ def primitive(self, primitive: pa.DataType) -> PrimitiveType:
11891189
elif isinstance(primitive, pa.Decimal128Type):
11901190
primitive = cast(pa.Decimal128Type, primitive)
11911191
return DecimalType(primitive.precision, primitive.scale)
1192-
elif pa.types.is_string(primitive) or pa.types.is_large_string(primitive):
1192+
elif pa.types.is_string(primitive) or pa.types.is_large_string(primitive) or pa.types.is_string_view(primitive):
11931193
return StringType()
11941194
elif pa.types.is_date32(primitive):
11951195
return DateType()
@@ -1215,7 +1215,7 @@ def primitive(self, primitive: pa.DataType) -> PrimitiveType:
12151215
elif primitive.tz is None:
12161216
return TimestampType()
12171217

1218-
elif pa.types.is_binary(primitive) or pa.types.is_large_binary(primitive):
1218+
elif pa.types.is_binary(primitive) or pa.types.is_large_binary(primitive) or pa.types.is_binary_view(primitive):
12191219
return BinaryType()
12201220
elif pa.types.is_fixed_size_binary(primitive):
12211221
primitive = cast(pa.FixedSizeBinaryType, primitive)

tests/io/test_pyarrow_visitor.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,18 @@ def test_pyarrow_timestamp_tz_invalid_tz() -> None:
225225
visit_pyarrow(pyarrow_type, _ConvertToIceberg())
226226

227227

228-
def test_pyarrow_string_to_iceberg() -> None:
229-
pyarrow_type = pa.large_string()
228+
@pytest.mark.parametrize("pyarrow_type", [pa.string(), pa.large_string(), pa.string_view()])
229+
def test_pyarrow_string_to_iceberg(pyarrow_type: pa.DataType) -> None:
230230
converted_iceberg_type = visit_pyarrow(pyarrow_type, _ConvertToIceberg())
231231
assert converted_iceberg_type == StringType()
232-
assert visit(converted_iceberg_type, _ConvertToArrowSchema()) == pyarrow_type
232+
assert visit(converted_iceberg_type, _ConvertToArrowSchema()) == pa.large_string()
233233

234234

235-
def test_pyarrow_variable_binary_to_iceberg() -> None:
236-
pyarrow_type = pa.large_binary()
235+
@pytest.mark.parametrize("pyarrow_type", [pa.binary(), pa.large_binary(), pa.binary_view()])
236+
def test_pyarrow_variable_binary_to_iceberg(pyarrow_type: pa.DataType) -> None:
237237
converted_iceberg_type = visit_pyarrow(pyarrow_type, _ConvertToIceberg())
238238
assert converted_iceberg_type == BinaryType()
239-
assert visit(converted_iceberg_type, _ConvertToArrowSchema()) == pyarrow_type
239+
assert visit(converted_iceberg_type, _ConvertToArrowSchema()) == pa.large_binary()
240240

241241

242242
def test_pyarrow_struct_to_iceberg() -> None:

0 commit comments

Comments
 (0)