Skip to content

Commit 7df8617

Browse files
authored
fix(lancedb): unsupport Union types for lancedb target (#1035)
1 parent aa7b41d commit 7df8617

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

python/cocoindex/targets/lancedb.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def _convert_basic_type_to_pa_type(basic_type: BasicValueType) -> pa.DataType:
121121
"OffsetDateTime": pa.timestamp("us", tz="UTC"),
122122
"TimeDelta": pa.duration("us"),
123123
"Json": pa.json_(),
124-
"Union": pa.json_(),
125124
}
126125

127126
if kind in type_mapping:
@@ -142,7 +141,7 @@ def _convert_basic_type_to_pa_type(basic_type: BasicValueType) -> pa.DataType:
142141
# Range as a struct with start and end
143142
return pa.struct([pa.field("start", pa.int64()), pa.field("end", pa.int64())])
144143

145-
assert False, f"Unsupported type kind: {kind}"
144+
assert False, f"Unsupported type kind for LanceDB: {kind}"
146145

147146

148147
def _convert_key_value_to_sql(v: Any) -> str:
@@ -174,16 +173,19 @@ def _convert_fields_to_pyarrow(fields: list[FieldSchema], v: Any) -> Any:
174173
return {field.name: _convert_value_for_pyarrow(field.value_type.type, v)}
175174

176175

177-
def _convert_value_for_pyarrow(t: ValueType | None, v: Any) -> Any:
178-
if t is None or isinstance(t, BasicValueType):
176+
def _convert_value_for_pyarrow(t: ValueType, v: Any) -> Any:
177+
if v is None:
178+
return None
179+
180+
if isinstance(t, BasicValueType):
179181
if isinstance(v, uuid.UUID):
180182
return v.bytes
181183

182-
if isinstance(v, tuple) and len(v) == 2:
184+
if t.kind == "Range":
183185
return {"start": v[0], "end": v[1]}
184186

185-
if isinstance(v, list):
186-
return [_convert_value_for_pyarrow(None, value) for value in v]
187+
if t.vector is not None:
188+
return [_convert_value_for_pyarrow(t.vector.element_type, e) for e in v]
187189

188190
return v
189191

0 commit comments

Comments
 (0)