Skip to content

Commit d7bec72

Browse files
committed
fixes
1 parent bc66462 commit d7bec72

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "query-farm-duckdb-json-serialization"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = "Integrate with DuckDB's JSON serialization of expressions and values"
55
authors = [
66
{ name = "Rusty Conover", email = "[email protected]" }

requirements-dev.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-e file:.
1313
annotated-types==0.7.0
1414
# via pydantic
15-
coverage==7.9.1
15+
coverage==7.9.2
1616
# via pytest-cov
1717
filelock==3.18.0
1818
# via pytest-mypy
@@ -43,8 +43,8 @@ pytest==8.4.1
4343
pytest-cov==6.2.1
4444
pytest-env==1.1.5
4545
pytest-mypy==1.0.1
46-
ruff==0.12.1
47-
typing-extensions==4.14.0
46+
ruff==0.12.2
47+
typing-extensions==4.14.1
4848
# via mypy
4949
# via pydantic
5050
# via pydantic-core

requirements.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pydantic==2.11.7
1616
# via query-farm-duckdb-json-serialization
1717
pydantic-core==2.33.2
1818
# via pydantic
19-
typing-extensions==4.14.0
19+
typing-extensions==4.14.1
2020
# via pydantic
2121
# via pydantic-core
2222
# via typing-inspection

src/query_farm_duckdb_json_serialization/value.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ def sql(self) -> str:
102102
return "null"
103103
assert self.value
104104

105-
data = self.value.base64 if isinstance(self.value, ValueValue_base64) else self.value
105+
data = (
106+
self.value.base64
107+
if isinstance(self.value, ValueValue_base64)
108+
else self.value
109+
)
106110

107111
if not data or len(data) < 2:
108112
return ""
@@ -421,7 +425,9 @@ def sql(self) -> str:
421425

422426
return (
423427
"TIME '"
424-
+ time(hours, minutes, seconds, microsecond=t.microseconds).strftime("%H:%M:%S.%f")
428+
+ time(hours, minutes, seconds, microsecond=t.microseconds).strftime(
429+
"%H:%M:%S.%f"
430+
)
425431
+ "'"
426432
)
427433

@@ -449,7 +455,9 @@ def sql(self) -> str:
449455

450456
return (
451457
"TIMETZ '"
452-
+ time(hours, minutes, seconds, microsecond=t.microseconds).strftime("%H:%M:%S.%f")
458+
+ time(hours, minutes, seconds, microsecond=t.microseconds).strftime(
459+
"%H:%M:%S.%f"
460+
)
453461
+ "'"
454462
)
455463

@@ -542,8 +550,13 @@ class Value_timestamp_ns(ValueBase):
542550
def sql(self) -> str:
543551
if self.is_null:
544552
return "null"
553+
assert self.value
554+
ns_since_epoch = self.value
555+
seconds, nanoseconds = divmod(ns_since_epoch, 10**9)
545556

546-
return f"make_timestamp_ns({self.value}::bigint)"
557+
dt = datetime.fromtimestamp(seconds, tz=UTC)
558+
formatted = dt.strftime("%Y-%m-%dT%H:%M:%S") + f".{nanoseconds:09d}"
559+
return f"TIMESTAMP_NS '{formatted}'"
547560

548561

549562
class ValueType_timestamp_s(BaseModel):
@@ -841,7 +854,10 @@ def sql(self) -> str:
841854
return (
842855
"STRUCT("
843856
+ ",".join(
844-
[f'"{child.first}" {child.second.sql()}' for child in self.type_info.child_types]
857+
[
858+
f'"{child.first}" {child.second.sql()}'
859+
for child in self.type_info.child_types
860+
]
845861
)
846862
+ ")"
847863
)
@@ -861,7 +877,10 @@ def sql(self) -> str:
861877
return (
862878
"{"
863879
+ ",".join(
864-
[f"'{name}':" + value.sql() for name, value in zip(names, values, strict=True)]
880+
[
881+
f"'{name}':" + value.sql()
882+
for name, value in zip(names, values, strict=True)
883+
]
865884
)
866885
+ "}"
867886
)

0 commit comments

Comments
 (0)