You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "Fokko (via GitHub)" <gi...@apache.org> on 2023/10/03 11:36:06 UTC
[PR] Add logic to generate a new snapshot-id [iceberg-python]
Fokko opened a new pull request, #37:
URL: https://github.com/apache/iceberg-python/pull/37
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Add logic to generate a new snapshot-id [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #37:
URL: https://github.com/apache/iceberg-python/pull/37#discussion_r1346999502
##########
pyiceberg/table/__init__.py:
##########
@@ -1566,3 +1575,15 @@ def _add_and_move_fields(
elif len(moves) > 0:
return _move_fields(fields, moves)
return None if len(adds) == 0 else tuple(*fields, *adds)
+
+
+def _generate_snapshot_id() -> int:
+ """Generate a new Snapshot ID from a UUID.
+
+ Right shifting the 64 bits removes the MAC address and time
+ leaving only the part that's based on the clock (and has the
+ highest entropy).
+
+ Returns: An 64 bit long
+ """
+ return uuid.uuid4().int & (1 << 64) - 1
Review Comment:
It was because I read unsigned. Fixed that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Add logic to generate a new snapshot-id [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #37:
URL: https://github.com/apache/iceberg-python/pull/37#discussion_r1344387785
##########
pyiceberg/table/__init__.py:
##########
@@ -1566,3 +1575,15 @@ def _add_and_move_fields(
elif len(moves) > 0:
return _move_fields(fields, moves)
return None if len(adds) == 0 else tuple(*fields, *adds)
+
+
+def _generate_snapshot_id() -> int:
+ """Generate a new Snapshot ID from a UUID.
+
+ Right shifting the 64 bits removes the MAC address and time
+ leaving only the part that's based on the clock (and has the
+ highest entropy).
+
+ Returns: An 64 bit long
+ """
+ return uuid.uuid4().int & (1 << 64) - 1
Review Comment:
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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Add logic to generate a new snapshot-id [iceberg-python]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #37:
URL: https://github.com/apache/iceberg-python/pull/37#discussion_r1344356017
##########
pyiceberg/table/__init__.py:
##########
@@ -1566,3 +1575,15 @@ def _add_and_move_fields(
elif len(moves) > 0:
return _move_fields(fields, moves)
return None if len(adds) == 0 else tuple(*fields, *adds)
+
+
+def _generate_snapshot_id() -> int:
+ """Generate a new Snapshot ID from a UUID.
+
+ Right shifting the 64 bits removes the MAC address and time
+ leaving only the part that's based on the clock (and has the
+ highest entropy).
+
+ Returns: An 64 bit long
+ """
+ return uuid.uuid4().int & (1 << 64) - 1
Review Comment:
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?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Add logic to generate a new snapshot-id [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #37:
URL: https://github.com/apache/iceberg-python/pull/37#discussion_r1344387785
##########
pyiceberg/table/__init__.py:
##########
@@ -1566,3 +1575,15 @@ def _add_and_move_fields(
elif len(moves) > 0:
return _move_fields(fields, moves)
return None if len(adds) == 0 else tuple(*fields, *adds)
+
+
+def _generate_snapshot_id() -> int:
+ """Generate a new Snapshot ID from a UUID.
+
+ Right shifting the 64 bits removes the MAC address and time
+ leaving only the part that's based on the clock (and has the
+ highest entropy).
+
+ Returns: An 64 bit long
+ """
+ return uuid.uuid4().int & (1 << 64) - 1
Review Comment:
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 128 bit int
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Add logic to generate a new snapshot-id [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #37:
URL: https://github.com/apache/iceberg-python/pull/37#issuecomment-1748353368
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Add logic to generate a new snapshot-id [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko merged PR #37:
URL: https://github.com/apache/iceberg-python/pull/37
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org