Skip to content

Commit 549c183

Browse files
committed
rebased: from main
1 parent 382e0ea commit 549c183

File tree

7 files changed

+63
-8
lines changed

7 files changed

+63
-8
lines changed

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ pyiceberg-core = { version = "^0.4.0", optional = true }
8484
polars = { version = "^1.21.0", optional = true }
8585
thrift-sasl = { version = ">=0.4.3", optional = true }
8686

87-
8887
[tool.poetry.group.dev.dependencies]
89-
pytest = ">=8.3.5,<9.0.0"
88+
pytest = "7.4.4"
9089
pytest-checkdocs = "2.13.0"
9190
pytest-lazy-fixture = "0.6.3"
9291
pre-commit = "4.2.0"

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,7 @@ def table_v2_with_extensive_snapshots(example_table_metadata_v2_with_extensive_s
23652365
identifier=("database", "table"),
23662366
metadata=table_metadata,
23672367
metadata_location=f"{table_metadata.location}/uuid.metadata.json",
2368-
io=load_file_io(location=metadata_location),
2368+
io=load_file_io(),
23692369
catalog=NoopCatalog("NoopCatalog"),
23702370
)
23712371

tests/expressions/test_literals.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,22 @@ def test_string_to_boolean_literal() -> None:
393393
assert literal("FALSE").to(BooleanType()) == literal(False)
394394

395395

396+
def test_string_to_float_literal() -> None:
397+
assert literal("3.141").to(FloatType()) == literal(3.141).to(FloatType())
398+
399+
400+
def test_string_to_float_outside_bound() -> None:
401+
big_lit_str = literal(str(FloatType.max + 1.0e37))
402+
assert big_lit_str.to(FloatType()) == FloatAboveMax()
403+
404+
small_lit_str = literal(str(FloatType.min - 1.0e37))
405+
assert small_lit_str.to(FloatType()) == FloatBelowMin()
406+
407+
408+
def test_string_to_double_literal() -> None:
409+
assert literal("3.141").to(DoubleType()) == literal(3.141)
410+
411+
396412
@pytest.mark.parametrize(
397413
"val",
398414
["unknown", "off", "on", "0", "1", "y", "yes", "n", "no", "t", "f"],
@@ -744,7 +760,7 @@ def test_invalid_decimal_conversions() -> None:
744760
def test_invalid_string_conversions() -> None:
745761
assert_invalid_conversions(
746762
literal("abc"),
747-
[FloatType(), DoubleType(), FixedType(1), BinaryType()],
763+
[FixedType(1), BinaryType()],
748764
)
749765

750766

tests/integration/test_partition_evolution.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ def test_add_hour(catalog: Catalog) -> None:
140140
_validate_new_partition_fields(table, 1000, 1, 1000, PartitionField(2, 1000, HourTransform(), "hour_transform"))
141141

142142

143+
@pytest.mark.integration
144+
@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("session_catalog")])
145+
def test_add_hour_string_transform(catalog: Catalog) -> None:
146+
table = _table(catalog)
147+
table.update_spec().add_field("event_ts", "hour", "str_hour_transform").commit()
148+
_validate_new_partition_fields(table, 1000, 1, 1000, PartitionField(2, 1000, HourTransform(), "str_hour_transform"))
149+
150+
143151
@pytest.mark.integration
144152
@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("session_catalog")])
145153
def test_add_hour_generates_default_name(catalog: Catalog) -> None:

tests/integration/test_rest_schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_schema_evolution_via_transaction(catalog: Catalog) -> None:
154154
NestedField(field_id=4, name="col_integer", field_type=IntegerType(), required=False),
155155
)
156156

157-
with pytest.raises(CommitFailedException) as exc_info:
157+
with pytest.raises(CommitFailedException, match="Requirement failed: current schema id has changed: expected 2, found 3"):
158158
with tbl.transaction() as tx:
159159
# Start a new update
160160
schema_update = tx.update_schema()
@@ -165,8 +165,6 @@ def test_schema_evolution_via_transaction(catalog: Catalog) -> None:
165165
# stage another update in the transaction
166166
schema_update.add_column("col_double", DoubleType()).commit()
167167

168-
assert "Requirement failed: current schema changed: expected id 2 != 3" in str(exc_info.value)
169-
170168
assert tbl.schema() == Schema(
171169
NestedField(field_id=1, name="col_uuid", field_type=UUIDType(), required=False),
172170
NestedField(field_id=2, name="col_fixed", field_type=FixedType(25), required=False),

tests/integration/test_writes/test_writes.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,3 +1776,37 @@ def test_write_optional_list(session_catalog: Catalog) -> None:
17761776
session_catalog.load_table(identifier).append(df_2)
17771777

17781778
assert len(session_catalog.load_table(identifier).scan().to_arrow()) == 4
1779+
1780+
1781+
@pytest.mark.integration
1782+
@pytest.mark.parametrize("format_version", [1, 2])
1783+
def test_evolve_and_write(
1784+
spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int
1785+
) -> None:
1786+
identifier = "default.test_evolve_and_write"
1787+
tbl = _create_table(session_catalog, identifier, properties={"format-version": format_version}, schema=Schema())
1788+
other_table = session_catalog.load_table(identifier)
1789+
1790+
numbers = pa.array([1, 2, 3, 4], type=pa.int32())
1791+
1792+
with tbl.update_schema() as upd:
1793+
# This is not known by other_table
1794+
upd.add_column("id", IntegerType())
1795+
1796+
with other_table.transaction() as tx:
1797+
# Refreshes the underlying metadata, and the schema
1798+
other_table.refresh()
1799+
tx.append(
1800+
pa.Table.from_arrays(
1801+
[
1802+
numbers,
1803+
],
1804+
schema=pa.schema(
1805+
[
1806+
pa.field("id", pa.int32(), nullable=True),
1807+
]
1808+
),
1809+
)
1810+
)
1811+
1812+
assert session_catalog.load_table(identifier).scan().to_arrow().column(0).combine_chunks() == numbers

0 commit comments

Comments
 (0)