Skip to content

Conversation

@jun-he
Copy link
Collaborator

@jun-he jun-he commented Aug 8, 2022

To split the PR #3450, open a new PR to add time (year, month, day, hour) transforms.

@github-actions github-actions bot added the python label Aug 8, 2022
@jun-he jun-he requested review from rdblue and samredai August 8, 2022 03:50
@jun-he
Copy link
Collaborator Author

jun-he commented Aug 8, 2022

@Fokko can you help to review it? Thanks.

Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

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

Some small comments, but this looks great @jun-he

assert TestType.parse_raw(json).__root__ == transform


@pytest.mark.parametrize(
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit of a nit, but I think this test both tests the str and repr, which I think makes sense to split into two tests (one for repr and one for str.

We haven't discussed this, but I'm not a fan of the whole parameterize functionality in pytest mostly because the decorator initializes before the actual tests ran. For example, if there is an error in the YearTransform() constructor, it will fail directly. This conflicts a bit with my personal TDD approach to development.

Therefore I just split everything into separate tests: https://github.com/apache/iceberg/blob/master/python/tests/test_types.py#L546
This way you don't have to check on which input the test is failing.

I've also added this to the list of Python topics for the next community sync.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for splitting out cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👌 Split it into two tests.
Let's chat in the sync meeting to see if we should avoid parameterize at all. I can have followup changes if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jun-he, when in doubt, do not parameterize. If you need to do anything special whatsoever, like updating an assert to use __root__ instead of isinstance(..., YearTransform) then parameters are not a good idea.

@rdblue rdblue changed the title [Python] add time (year, month, day, hour) transforms Python: Add year, month, day, and hour transforms Aug 10, 2022
@Fokko
Copy link
Contributor

Fokko commented Aug 18, 2022

Hey @jun-he We're thinking of doing a first Python release, and I would love to have this in as well. Would you have some time to dig into the comments? Thanks!

@jun-he jun-he requested review from Fokko and rdblue August 22, 2022 07:06
"""

__root__: Literal["year"] = Field(default="year")
_source_type: IcebergType = PrivateAttr()
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like these can all be removed because they aren't used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, removed _source_type from most of the transforms.

)
def test_datetime_transform_serde(transform, json):
assert transform.json() == json
assert TestType.parse_raw(json).__root__ == transform
Copy link
Contributor

Choose a reason for hiding this comment

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

This is too generic. Each class should be tested individual to validate that parsing the string results in an instance of the correct transform.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Split this into different serialize and deserialize tests.

SECOND = 0


class TimeTransform(Transform[S, int]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these also be Singleton?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@jun-he jun-he requested a review from rdblue August 29, 2022 04:52
@jun-he
Copy link
Collaborator Author

jun-he commented Aug 29, 2022

@Fokko @rdblue Updated the PR accordingly. Can you please take another look? Thanks.

@Fokko
Copy link
Contributor

Fokko commented Aug 29, 2022

Thanks @jun-he looks great! Thanks! 🚀

@Fokko Fokko merged commit 64e3168 into apache:master Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants