|
24 | 24 | Optional, |
25 | 25 | Set, |
26 | 26 | Tuple, |
| 27 | + Union, |
27 | 28 | ) |
28 | 29 |
|
29 | 30 | from pyiceberg.expressions import ( |
|
47 | 48 | UpdatesAndRequirements, |
48 | 49 | UpdateTableMetadata, |
49 | 50 | ) |
50 | | -from pyiceberg.transforms import IdentityTransform, TimeTransform, Transform, VoidTransform |
| 51 | +from pyiceberg.transforms import IdentityTransform, TimeTransform, Transform, VoidTransform, parse_transform |
51 | 52 |
|
52 | 53 | if TYPE_CHECKING: |
53 | 54 | from pyiceberg.table import Transaction |
@@ -85,12 +86,16 @@ def __init__(self, transaction: Transaction, case_sensitive: bool = True) -> Non |
85 | 86 | def add_field( |
86 | 87 | self, |
87 | 88 | source_column_name: str, |
88 | | - transform: Transform[Any, Any], |
| 89 | + transform: Union[str, Transform[Any, Any]], # Aceptamos strings o Transform |
89 | 90 | partition_field_name: Optional[str] = None, |
90 | 91 | ) -> UpdateSpec: |
| 92 | + |
| 93 | + if isinstance(transform, str): |
| 94 | + transform = parse_transform(transform) |
| 95 | + |
91 | 96 | ref = Reference(source_column_name) |
92 | 97 | bound_ref = ref.bind(self._transaction.table_metadata.schema(), self._case_sensitive) |
93 | | - # verify transform can actually bind it |
| 98 | + |
94 | 99 | output_type = bound_ref.field.field_type |
95 | 100 | if not transform.can_transform(output_type): |
96 | 101 | raise ValueError(f"{transform} cannot transform {output_type} values from {bound_ref.field.name}") |
@@ -128,6 +133,7 @@ def add_field( |
128 | 133 | self._adds.append(new_field) |
129 | 134 | return self |
130 | 135 |
|
| 136 | + |
131 | 137 | def add_identity(self, source_column_name: str) -> UpdateSpec: |
132 | 138 | return self.add_field(source_column_name, IdentityTransform(), None) |
133 | 139 |
|
|
0 commit comments