samredai commented on pull request #3450:
URL: https://github.com/apache/iceberg/pull/3450#issuecomment-962046571


   Can `year`, `month`, `day`, and `hour` be consolidated into a single 
function?:
   ```py
   from typing import Union, Literal
   
   def get_time_transform(
       transform: Type,
       interval: Union[
           Literal["year"],
           Literal["month"],
           Literal["day"],
           Literal["hour"]
       ],
   ):
   
       if interval not in _VALID_TIME_GRANULARITY[transform]:
           raise ValueError(f"Cannot partition type {transform} by {interval}")
   
       return _TIME_TRANSFORMS[transform][interval]
   ```
   
   Then a call to that function can be made in `from_string` which can be 
renamed to something like `get_transform_from_type` and be the single 
entrypoint function for getting a type of `Transform`. The other module level 
functions could then be changed to internal functions prefixed with an 
underscore.
   
   So usage would look like:
   ```py
   from iceberg.types import DateType, TimestampType
   from iceberg.transforms import get_transform_from_type
   
   transform_a = get_transform_from_type(DateType, "year")
   print(transform_a) # Time(transform_type=DateType, name="year")
   
   transform_b = get_transform_from_type(TimestampType, "day")
   print(transform_b)  # Time(transform_type=TimestampType, name="day")
   
   transform_c = get_transform_from_type(DateType, "identity")
   print(transform_c)  # Identity(transform_type=DateType)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to