WIP: first pass at `UnboundTransform` by jayceslesar · Pull Request #209 · apache/iceberg-python

@jayceslesar

@jayceslesar

@Fokko this isnt completely done, but would appreciate a review + some guidance on next steps once you run linting and see whats up haha

@jayceslesar

No worries on the speed of this one, I know you are heads down on getting write support

Fokko

Comment on lines 824 to 826

def __init__(self, term: BoundTerm[L], transform: Transform[L, Any]):
self.term: BoundTerm[L] = term
self.transform = transform

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def __init__(self, term: BoundTerm[L], transform: Transform[L, Any]):
self.term: BoundTerm[L] = term
self.transform = transform
def __init__(self, term: BoundTerm[L], transform_func: Callable[Optional[L], Optional[Any]]):
self.term: BoundTerm[L] = term
self.transform = transform

Fokko

raise ValueError("some better error message")

else:
return BoundTransform(bound_term, self.transform)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should actually instantiate the callable of the transform:

return BoundTransform(bound_term, self.transform)
return BoundTransform(bound_term, self.transform.transform(bound_term.ref().field.field_type))

Fokko


def eval(self, struct: StructProtocol) -> L:
"""Return the value at the referenced field's position in an object that abides by the StructProtocol."""
return self.term.eval(struct)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return self.term.eval(struct)
return self.transform(self.term.eval(struct))

Fokko



def test_cast() -> None:
cast = parser.parse("CAST(created_at as date)")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see some more tests here. The most important part that's missing here is converting date to a DayTransform. Other options such as year, month etc should be added as well.

@Fokko

Hey @jayceslesar thanks for working on this, and I think you're already halfway there. The most important part is to make sure that we convert as date to a DayTransform.

@nssalian

@jayceslesar #198 seems to be closed; do you mind closing this PR so the backlog is cleared?

@Fokko

@nssalian The issue hasn't been solved unfortunally. I've reopened the issue, but this PR needs a bit more TLD

@nssalian

Thanks for clarifying @Fokko . @jayceslesar , do you want to pick this back up again and clean it up if you have the bandwidth?

@nssalian