Skip to content

Commit 8b0f8a4

Browse files
committed
A GIFT THAT KEEPS ON GIVING
1 parent 8dab08e commit 8b0f8a4

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

pyiceberg/expressions/literals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def literal(value: L) -> Literal[L]:
154154
elif isinstance(value, date):
155155
return DateLiteral(date_to_days(value)) # type: ignore
156156
elif isinstance(value, time):
157-
return TimeLiteral(time_to_micros(value))
157+
return TimeLiteral(time_to_micros(value)) # type: ignore
158158
else:
159159
raise TypeError(f"Invalid literal value: {repr(value)}")
160160

pyiceberg/table/update/schema.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
UpdatesAndRequirements,
4949
UpdateTableMetadata,
5050
)
51+
from pyiceberg.typedef import L
5152
from pyiceberg.types import IcebergType, ListType, MapType, NestedField, PrimitiveType, StructType
5253

5354
if TYPE_CHECKING:
@@ -159,7 +160,7 @@ def add_column(
159160
field_type: IcebergType,
160161
doc: Optional[str] = None,
161162
required: bool = False,
162-
default_value: Optional[Any] = None,
163+
default_value: Optional[L] = None,
163164
) -> UpdateSchema:
164165
"""Add a new column to a nested struct or Add a new top-level column.
165166
@@ -224,7 +225,7 @@ def add_column(
224225
except ValueError as e:
225226
raise ValueError(f"Invalid default value: {e}") from e
226227
else:
227-
initial_default = default_value
228+
initial_default = default_value # type: ignore
228229

229230
if (required and initial_default is None) and not self._allow_incompatible_changes:
230231
# Table format version 1 and 2 cannot add required column because there is no initial value
@@ -274,7 +275,7 @@ def delete_column(self, path: Union[str, Tuple[str, ...]]) -> UpdateSchema:
274275

275276
return self
276277

277-
def set_default_value(self, path: Union[str, Tuple[str, ...]], default_value: Any) -> UpdateSchema:
278+
def set_default_value(self, path: Union[str, Tuple[str, ...]], default_value: Optional[L]) -> UpdateSchema:
278279
"""Set the default value of a column.
279280
280281
Args:

pyiceberg/typedef.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from __future__ import annotations
1818

1919
from abc import abstractmethod
20-
from datetime import date, datetime
20+
from datetime import date, datetime, time
2121
from decimal import Decimal
2222
from functools import lru_cache
2323
from typing import (
@@ -94,7 +94,7 @@ def __missing__(self, key: K) -> V:
9494
"""A recursive dictionary type for nested structures in PyIceberg."""
9595

9696
# Represents the literal value
97-
L = TypeVar("L", str, bool, int, float, bytes, UUID, Decimal, datetime, date, covariant=True)
97+
L = TypeVar("L", str, bool, int, float, bytes, UUID, Decimal, datetime, date, time, covariant=True)
9898

9999

100100
@runtime_checkable

tests/integration/test_rest_schema.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,26 +1145,20 @@ def test_initial_default_all_columns(
11451145
@pytest.mark.integration
11461146
def test_add_required_column_initial_default(catalog: Catalog) -> None:
11471147
schema_ = Schema(NestedField(field_id=1, name="a", field_type=BooleanType(), required=False))
1148-
table = _create_table_with_schema(catalog, schema_)
1149-
new_schema = (
1150-
UpdateSchema(transaction=table.transaction())
1151-
.add_column(path="data", field_type=IntegerType(), required=True, default_value=22)
1152-
._apply()
1153-
)
1154-
assert new_schema == Schema(
1155-
NestedField(field_id=1, name="a", field_type=BooleanType(), required=True, initial_default=True),
1148+
table = _create_table_with_schema(catalog, schema_, properties={TableProperties.FORMAT_VERSION: 3})
1149+
1150+
table.update_schema().add_column(path="data", field_type=IntegerType(), required=True, default_value=22).commit()
1151+
1152+
assert table.schema() == Schema(
1153+
NestedField(field_id=1, name="a", field_type=BooleanType(), required=False),
11561154
NestedField(field_id=2, name="data", field_type=IntegerType(), required=True, initial_default=22, write_default=22),
11571155
schema_id=1,
11581156
)
11591157

11601158
# Update
1161-
new_schema = (
1162-
UpdateSchema(transaction=table.transaction())
1163-
.update_column(path="data", field_type=LongType())
1164-
.rename_column("a", "bool")
1165-
._apply()
1166-
)
1167-
assert new_schema == Schema(
1159+
table.update_schema().update_column(path="data", field_type=LongType()).rename_column("a", "bool").commit()
1160+
1161+
assert table.schema() == Schema(
11681162
NestedField(field_id=1, name="bool", field_type=BooleanType(), required=False),
11691163
NestedField(field_id=2, name="data", field_type=LongType(), required=True, initial_default=22, write_default=22),
11701164
schema_id=1,

0 commit comments

Comments
 (0)