Skip to content

Commit 941e38e

Browse files
mtyinaverikitsch
andauthored
fix(graph): Support DATE type (#150)
Co-authored-by: Averi Kitsch <akitsch@google.com>
1 parent 37f2324 commit 941e38e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/langchain_google_spanner/type_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def spanner_type_to_schema_str(
6262
return "TIMESTAMP"
6363
if t.code == param_types.TypeCode.JSON:
6464
return "JSON"
65+
if t.code == param_types.TypeCode.DATE:
66+
return "DATE"
6567
raise ValueError("Unsupported type: %s" % t)
6668

6769
@staticmethod
@@ -90,6 +92,8 @@ def schema_str_to_spanner_type(s: str) -> param_types.Type:
9092
return param_types.TIMESTAMP
9193
if s == "JSON":
9294
return param_types.JSON
95+
if s == "DATE":
96+
return param_types.DATE
9397
if s.startswith("ARRAY<") and s.endswith(">"):
9498
return param_types.Array(
9599
TypeUtility.schema_str_to_spanner_type(s[len("ARRAY<") : -len(">")])
@@ -118,6 +122,8 @@ def value_to_param_type(v: Any) -> param_types.Type:
118122
return param_types.FLOAT64
119123
if isinstance(v, datetime.datetime):
120124
return param_types.TIMESTAMP
125+
if isinstance(v, datetime.date):
126+
return param_types.DATE
121127
if isinstance(v, JsonObject):
122128
return param_types.JSON
123129
if isinstance(v, list):
@@ -145,6 +151,8 @@ def value_for_json(v: Any) -> Any:
145151
return base64.b64encode(v).decode("utf-8")
146152
if isinstance(v, datetime.datetime):
147153
return str(v)
154+
if isinstance(v, datetime.date):
155+
return str(v)
148156
if isinstance(v, JsonObject):
149157
return v
150158
if isinstance(v, list):

tests/integration/test_spanner_graph_store.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def random_timestamp():
6060
return datetime.datetime.fromtimestamp(random_int(0, 366 * 24 * 60 * 60 * 1000))
6161

6262

63+
def random_date():
64+
return datetime.date.fromtimestamp(random_int(0, 366 * 24 * 60 * 60 * 1000))
65+
66+
6367
def random_param():
6468
# None param is not supported.
6569
return random.choice(random_generators())() or random_param()
@@ -86,6 +90,7 @@ def random_primitive_generators():
8690
random_bool,
8791
random_float,
8892
random_timestamp,
93+
random_date,
8994
]
9095

9196

0 commit comments

Comments
 (0)