Skip to content

Conversation

@jun-he
Copy link
Collaborator

@jun-he jun-he commented May 30, 2022

To split the PR #3450, open a new PR for identity transform here.

@jun-he jun-he force-pushed the jun/add-identity-transform branch 2 times, most recently from 61b9690 to 47820bf Compare May 30, 2022 21:32
@jun-he jun-he requested review from kbendick and rdblue May 30, 2022 21:34

@_human_string.register(bytes)
def _(self, value: bytes) -> str:
if type(self._type) in {FixedType, BinaryType}:
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need for an if here. The only way to handle binary is to base64 encode it. It doesn't depend on the type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👌

(LongType(), None, "null"),
(DateType(), 17501, "2017-12-01"),
(TimeType(), 36775038194, "10:12:55.038194"),
(TimestamptzType(), 1512151975038194, "2017-12-01T18:12:55.038194Z"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Timestamptz literals must always include a valid zone offset that matches this regex: [+-]\d\d:\d\d$

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👌 Fixed.


def to_human_time(micros_from_midnight: int) -> str:
"""Converts a TimeType value to human string"""
to_day = EPOCH_TIMESTAMP + timedelta(microseconds=micros_from_midnight)
Copy link
Contributor

Choose a reason for hiding this comment

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

Time shouldn't use epoch. There's no need to mix dates into this.

Getting a time is actually straightforward:

def time_from_micros(micros: int) -> time:
    seconds = micros // 1_000_000
    minutes = seconds // 60
    hours = minutes // 60
    time(hour=hours, minute=minutes % 60, second=seconds % 60, microsecond=micros % 1_000_000)

Copy link
Contributor

Choose a reason for hiding this comment

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

This should use the code provided here, rather than creating a datetime and converting it to a time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👌 Updated.

def to_human_time(micros_from_midnight: int) -> str:
"""Converts a TimeType value to human string"""
to_day = EPOCH_TIMESTAMP + timedelta(microseconds=micros_from_midnight)
return f"{to_day.time()}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this just str(to_day.time())?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should also use .isoformat() after constructing a time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@rdblue
Copy link
Contributor

rdblue commented Jun 5, 2022

@jun-he do you have time to update this? If not, we can probably find someone to pick it up.

@jun-he jun-he force-pushed the jun/add-identity-transform branch from 47820bf to 3ef5cb6 Compare June 6, 2022 00:25
@jun-he
Copy link
Collaborator Author

jun-he commented Jun 6, 2022

@rdblue Yep, just addressed the comments accordingly. Can you take a look? Thanks.

return self._human_string(value)

@singledispatchmethod
def _human_string(self, value: Optional[S]) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: There's no need for these to be in the class, and it's actually faster if they are simple methods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean moving them out of the class?

Wondering if we can save _human_string but only keeps _int_to_human_string.
like

    def to_human_string(self, value: Optional[S]) -> str:
        if value is None:
            return "null"
        elif isinstance(value, bytes):
            return _base64encode(value)
        elif isinstance(value, int):
            return self._int_to_human_string(self._type, value)
        else:
            return str(value)

python/tox.ini Outdated
# specific language governing permissions and limitations
# under the License.

[tox]
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we no longer use tox, can you remove this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👌

@rdblue
Copy link
Contributor

rdblue commented Jun 12, 2022

@jun-he, this is about ready to go. The main problem is that it reintroduces tox.ini.

Copy link
Contributor

@rdblue rdblue left a comment

Choose a reason for hiding this comment

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

This looks correct, but needs to remove tox.ini.

@jun-he jun-he force-pushed the jun/add-identity-transform branch from 8e8d849 to 3b63567 Compare June 13, 2022 00:39
@jun-he
Copy link
Collaborator Author

jun-he commented Jun 13, 2022

@rdblue updated the PR and removed tox.ini

@rdblue rdblue merged commit c7d758c into apache:master Jun 13, 2022
@rdblue
Copy link
Contributor

rdblue commented Jun 13, 2022

Thanks, @jun-he!

@jun-he jun-he deleted the jun/add-identity-transform branch June 14, 2022 06:48
namrathamyske pushed a commit to namrathamyske/iceberg that referenced this pull request Jul 10, 2022
namrathamyske pushed a commit to namrathamyske/iceberg that referenced this pull request Jul 10, 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.

2 participants