Skip to content

Commit 7976261

Browse files
committed
Move uuid version check into the db
1 parent bcfcab9 commit 7976261

File tree

2 files changed

+6
-36
lines changed

2 files changed

+6
-36
lines changed

nbs/00_vector.ipynb

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@
326326
" bytes bytea;\n",
327327
" BEGIN\n",
328328
" bytes := uuid_send(uuid);\n",
329+
" if (get_byte(bytes, 6) >> 4)::int2 != 1 then\n",
330+
" RAISE EXCEPTION 'UUID version is not 1';\n",
331+
" end if;\n",
329332
" RETURN to_timestamp(\n",
330333
" (\n",
331334
" (\n",
@@ -647,12 +650,6 @@
647650
" return rec == None\n",
648651
"\n",
649652
" def munge_record(self, records) -> Iterable[Tuple[uuid.UUID, str, str, List[float]]]:\n",
650-
" if self.time_partition_interval is not None:\n",
651-
" for record in records:\n",
652-
" id = record[0]\n",
653-
" if id.variant != uuid.RFC_4122 or id.version != 1:\n",
654-
" raise ValueError(\"When using time partitioning, id must be a v1 uuid\")\n",
655-
"\n",
656653
" metadata_is_dict = isinstance(records[0][1], dict)\n",
657654
" if metadata_is_dict:\n",
658655
" records = map(lambda item: Async._convert_record_meta_to_json(item), records)\n",
@@ -895,18 +892,6 @@
895892
"execution_count": null,
896893
"metadata": {},
897894
"outputs": [
898-
{
899-
"name": "stderr",
900-
"output_type": "stream",
901-
"text": [
902-
"/Users/cevian/.pyenv/versions/3.11.4/envs/nbdev_env/lib/python3.11/site-packages/fastcore/docscrape.py:225: UserWarning: potentially wrong underline length... \n",
903-
"Returns \n",
904-
"-------- in \n",
905-
"Retrieves similar records using a similarity query.\n",
906-
"...\n",
907-
" else: warn(msg)\n"
908-
]
909-
},
910895
{
911896
"data": {
912897
"text/markdown": [
@@ -1319,12 +1304,6 @@
13191304
" return rec == None\n",
13201305
" \n",
13211306
" def munge_record(self, records) -> Iterable[Tuple[uuid.UUID, str, str, List[float]]]:\n",
1322-
" if self.time_partition_interval is not None:\n",
1323-
" for record in records:\n",
1324-
" id = record[0]\n",
1325-
" if id.variant != uuid.RFC_4122 or id.version != 1:\n",
1326-
" raise ValueError(\"When using time partitioning, id must be a v1 uuid\")\n",
1327-
"\n",
13281307
" metadata_is_dict = isinstance(records[0][1], dict)\n",
13291308
" if metadata_is_dict:\n",
13301309
" records = map(lambda item: Sync._convert_record_meta_to_json(item), records)\n",

timescale_vector/client.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ def get_create_query(self):
243243
bytes bytea;
244244
BEGIN
245245
bytes := uuid_send(uuid);
246+
if (get_byte(bytes, 6) >> 4)::int2 != 1 then
247+
RAISE EXCEPTION 'UUID version is not 1';
248+
end if;
246249
RETURN to_timestamp(
247250
(
248251
(
@@ -510,12 +513,6 @@ async def table_is_empty(self):
510513
return rec == None
511514

512515
def munge_record(self, records) -> Iterable[Tuple[uuid.UUID, str, str, List[float]]]:
513-
if self.time_partition_interval is not None:
514-
for record in records:
515-
id = record[0]
516-
if id.variant != uuid.RFC_4122 or id.version != 1:
517-
raise ValueError("When using time partitioning, id must be a v1 uuid")
518-
519516
metadata_is_dict = isinstance(records[0][1], dict)
520517
if metadata_is_dict:
521518
records = map(lambda item: Async._convert_record_meta_to_json(item), records)
@@ -813,12 +810,6 @@ def table_is_empty(self):
813810
return rec == None
814811

815812
def munge_record(self, records) -> Iterable[Tuple[uuid.UUID, str, str, List[float]]]:
816-
if self.time_partition_interval is not None:
817-
for record in records:
818-
id = record[0]
819-
if id.variant != uuid.RFC_4122 or id.version != 1:
820-
raise ValueError("When using time partitioning, id must be a v1 uuid")
821-
822813
metadata_is_dict = isinstance(records[0][1], dict)
823814
if metadata_is_dict:
824815
records = map(lambda item: Sync._convert_record_meta_to_json(item), records)

0 commit comments

Comments
 (0)