Skip to content

Add logic to generate a new snapshot-id#37

Merged
Fokko merged 3 commits intoapache:mainfrom
Fokko:fd-add-generate-snapshot
Oct 5, 2023
Merged

Add logic to generate a new snapshot-id#37
Fokko merged 3 commits intoapache:mainfrom
Fokko:fd-add-generate-snapshot

Conversation

@Fokko
Copy link
Copy Markdown
Contributor

@Fokko Fokko commented Oct 3, 2023

No description provided.

@Fokko Fokko force-pushed the fd-add-generate-snapshot branch from ad933c3 to 6fd84e2 Compare October 3, 2023 11:41
@Fokko Fokko force-pushed the fd-add-generate-snapshot branch from 6fd84e2 to bfa8143 Compare October 3, 2023 11:48
Comment thread pyiceberg/table/__init__.py Outdated

Returns: An 64 bit long
"""
return uuid.uuid4().int & (1 << 64) - 1
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.

Why not use the same approach as in Java, which will xor the most-significant int with the least-significant int and then make sure it's positive?

Copy link
Copy Markdown
Contributor Author

@Fokko Fokko Oct 3, 2023

Choose a reason for hiding this comment

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

Yes, this is actually not a great idea:

E       Caused by: java.lang.IllegalArgumentException: Cannot parse to a long value: snapshot-id: 9330031330511797673
E       	at org.apache.iceberg.relocated.com.google.common.base.Preconditions.checkArgument(Preconditions.java:435)
E       	at org.apache.iceberg.util.JsonUtil.getLong(JsonUtil.java:135)
E       	at org.apache.iceberg.SnapshotParser.fromJson(SnapshotParser.java:116)

A >64 bit int

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was because I read unsigned. Fixed that.

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

Looks okay to me. I think this works but it isn't quite what we do in Java and I don't see why we'd change it.

@Fokko
Copy link
Copy Markdown
Contributor Author

Fokko commented Oct 5, 2023

In Python, you cannot xor on ints/longs (probably because they are also unbound in terms of size :), so I had to deviate a bit there.

@Fokko Fokko force-pushed the fd-add-generate-snapshot branch from d0425b3 to 11b3c5d Compare October 5, 2023 08:20
@Fokko Fokko merged commit 6a77195 into apache:main Oct 5, 2023
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.

2 participants