-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Snowflake IDs for nodes and edges
Co-Authored-By: João Gonçalves <jsvgoncalves@gmail.com>
- Loading branch information
1 parent
610f8af
commit f160f82
Showing
10 changed files
with
127 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from snowflake import SnowflakeGenerator | ||
import uuid | ||
|
||
# Jan 1, 2024 | ||
# from datetime import datetime | ||
# (datetime(2024, 1, 1) - datetime.utcfromtimestamp(0)).total_seconds() * 1000.0 | ||
EPOCH_START_MS = 1704067200000 | ||
|
||
# From https://softwaremind.com/blog/the-unique-features-of-snowflake-id-and-its-comparison-to-uuid/ | ||
# Snowflake bits: | ||
# Sign bit: 1 bit. It will always be 0. This is reserved for future uses. It can potentially be used | ||
# to distinguish between signed and unsigned numbers. | ||
# Timestamp: 41 bits. Milliseconds since the epoch or custom epoch. | ||
# Datacenter ID: 5 bits, which gives us 2 ^ 5 = 32 datacenters. | ||
# Machine ID: 5 bits, which gives us 2 ^ 5 = 32 machines per datacenter. | ||
# However, `snowflake-id` lumps the two datacenter and machine id values together into an | ||
# `instance` parameter with 2 ^ 10 = 1024 possible values. | ||
# Sequence number: 12 bits. For every ID generated on that machine/process, the sequence number is | ||
# incremented by 1. The number is reset to 0 every millisecond. | ||
snowflake_id_generator = SnowflakeGenerator(instance=uuid.getnode() % 1024, epoch=EPOCH_START_MS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.