3
3
import datetime as dt
4
4
import json
5
5
import logging
6
- import uuid
6
+ import os
7
7
from collections .abc import Callable , Sequence
8
8
from dataclasses import dataclass
9
9
from functools import cached_property
@@ -21,10 +21,10 @@ class HistoricalRecord:
21
21
workspace_id : int
22
22
"""The identifier of the workspace where this record was generated."""
23
23
24
- run_id : str
25
- """An identifier of the workflow run that generated this record."""
24
+ run_id : int
25
+ """The identifier of the workflow run that generated this record."""
26
26
27
- snapshot_id : str
27
+ snapshot_id : int
28
28
"""An identifier that is unique to the records produced for a given snapshot."""
29
29
30
30
run_start_time : dt .datetime
@@ -63,7 +63,7 @@ def __init__(
63
63
self ,
64
64
ws : WorkspaceClient ,
65
65
backend : SqlBackend ,
66
- run_id : str ,
66
+ run_id : int ,
67
67
catalog : str ,
68
68
schema : str ,
69
69
table : str ,
@@ -91,7 +91,7 @@ class Appender:
91
91
def __init__ (
92
92
self ,
93
93
ws : WorkspaceClient ,
94
- run_id : str ,
94
+ run_id : int ,
95
95
klass : type [Record ],
96
96
key_from : Callable [[Record ], str ],
97
97
persist : Callable [[str , list [HistoricalRecord ]], None ],
@@ -116,15 +116,20 @@ def _owner(self) -> str:
116
116
return owner
117
117
118
118
def append_snapshot (self , records : Sequence [Record ], * , run_start_time : dt .datetime ) -> None :
119
- snapshot_id = uuid .uuid4 ()
119
+ # Equivalent entropy to a type-4 UUID.
120
+ snapshot_id = int .from_bytes (os .urandom (16 ), byteorder = "big" )
120
121
historical_records = [
121
122
self ._inventory_record_to_historical (record , snapshot_id = snapshot_id , run_start_time = run_start_time )
122
123
for record in records
123
124
]
124
125
self ._persist (self ._object_type , historical_records )
125
126
126
127
def _inventory_record_to_historical (
127
- self , record : Record , * , snapshot_id : uuid .UUID , run_start_time : dt .datetime
128
+ self ,
129
+ record : Record ,
130
+ * ,
131
+ snapshot_id : int ,
132
+ run_start_time : dt .datetime ,
128
133
) -> HistoricalRecord :
129
134
object_id = self ._key_from (record )
130
135
object_as_dict = dataclasses .asdict (record )
@@ -134,7 +139,7 @@ def _inventory_record_to_historical(
134
139
return HistoricalRecord (
135
140
workspace_id = self ._workspace_id ,
136
141
run_id = self ._run_id ,
137
- snapshot_id = str ( snapshot_id ) ,
142
+ snapshot_id = snapshot_id ,
138
143
run_start_time = run_start_time ,
139
144
object_type = self ._object_type ,
140
145
object_type_version = self ._object_type_version ,
0 commit comments