Skip to content

Commit e809a09

Browse files
committed
fixes
1 parent f71abca commit e809a09

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/query_farm_server_base/duckdb_serialized_expression.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
import codecs
3+
import uuid
34
from typing import Any
45

56

@@ -32,6 +33,25 @@ def decode_bitstring(data: bytes) -> str:
3233
return bits
3334

3435

36+
def decode_uuid(value: dict[str, int]) -> str:
37+
assert "upper" in value and "lower" in value, "Invalid GUID format"
38+
39+
# Handle the two's complement for the signed upper 64 bits
40+
upper = value["upper"] & ((1 << 64) - 1) # Convert to unsigned if needed
41+
lower = value["lower"]
42+
43+
# Combine into 128-bit integer
44+
combined = (upper << 64) | lower
45+
46+
# Convert to 16 bytes (big-endian)
47+
bytes_ = combined.to_bytes(16, byteorder="big")
48+
49+
# Create UUID from bytes
50+
u = uuid.UUID(bytes=bytes_)
51+
52+
return str(u)
53+
54+
3555
def varint_get_byte_array(blob: bytes) -> tuple[list[int], bool]:
3656
if len(blob) < 4:
3757
raise ValueError("Invalid blob size.")
@@ -212,10 +232,11 @@ def e_to_s(expr: dict[str, Any]) -> str:
212232
)
213233

214234
return varint_to_varchar(varint_bytes)
235+
elif expression["value"]["type"]["id"] == "UUID":
236+
return decode_uuid(expression["value"]["value"])
215237
elif expression["value"]["type"]["id"] in (
216238
"VARCHAR",
217239
"BLOB",
218-
"UUID",
219240
):
220241
return _quote_string(expression["value"]["value"])
221242
elif expression["value"]["type"]["id"] == "BIT":

0 commit comments

Comments
 (0)