Skip to content

WIP: first pass at UnboundTransform#209

Draft
jayceslesar wants to merge 5 commits intoapache:mainfrom
jayceslesar:feature/cast
Draft

WIP: first pass at UnboundTransform#209
jayceslesar wants to merge 5 commits intoapache:mainfrom
jayceslesar:feature/cast

Conversation

@jayceslesar
Copy link
Copy Markdown
Contributor

Resolves #198

@jayceslesar
Copy link
Copy Markdown
Contributor Author

@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
Copy link
Copy Markdown
Contributor Author

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

Comment on lines 824 to 826
def __init__(self, term: BoundTerm[L], transform: Transform[L, Any]):
self.term: BoundTerm[L] = term
self.transform = transform
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

raise ValueError("some better error message")

else:
return BoundTransform(bound_term, self.transform)
Copy link
Copy Markdown
Contributor

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:

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


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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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



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

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
Copy link
Copy Markdown
Contributor

Fokko commented Dec 21, 2023

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
Copy link
Copy Markdown
Contributor

nssalian commented Mar 5, 2026

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

@Fokko
Copy link
Copy Markdown
Contributor

Fokko commented Mar 5, 2026

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

@nssalian
Copy link
Copy Markdown
Contributor

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

@nssalian
Copy link
Copy Markdown
Contributor

@Fokko @jayceslesar , I'll take a stab at this and push a new PR if that's ok?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CAST to parser.py

3 participants