Skip to content

Commit

Permalink
Closer to the Java way of doing it
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Oct 5, 2023
1 parent a5d56c0 commit d0425b3
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@
ALWAYS_TRUE = AlwaysTrue()
TABLE_ROOT_ID = -1

_JAVA_LONG_MAX = 9223372036854775807


class Transaction:
_table: Table
Expand Down Expand Up @@ -1585,13 +1583,7 @@ def _generate_snapshot_id() -> int:
Returns: An 64 bit long
"""
rnd_uuid = uuid.uuid4()
snapshot_id = int.from_bytes(
bytes(lhs ^ rhs for lhs, rhs in zip(rnd_uuid.bytes[0:8], rnd_uuid.bytes[8:16])), byteorder='little', signed=True
)

if snapshot_id < 0:
raise ValueError(f"Snapshot ID should not be negative: {snapshot_id}")
if snapshot_id > _JAVA_LONG_MAX:
raise ValueError(f"Snapshot ID should not be larger than signed 63 bit ({_JAVA_LONG_MAX}): {snapshot_id}")
snapshot_id = int.from_bytes(bytes(lhs ^ rhs for lhs, rhs in zip(rnd_uuid.bytes[0:8], rnd_uuid.bytes[8:16])), signed=True)
snapshot_id = snapshot_id if snapshot_id >= 0 else snapshot_id * -1

return snapshot_id

0 comments on commit d0425b3

Please sign in to comment.