Skip to content

Commit f855ad2

Browse files
cutoutsyfengxiaochuanfranciscojavierarceo
authored
fix: Improve trino to feast type mapping with (real,varchar,timestamp,decimal) (#5691)
* fix: improve trino to feast type mapping with (real,varchar,timestamp,decimal) Signed-off-by: fengxiaochuan <[email protected]> * Remove whitespace from blank line Signed-off-by: fengxiaochuan <[email protected]> --------- Signed-off-by: fengxiaochuan <[email protected]> Co-authored-by: fengxiaochuan <[email protected]> Co-authored-by: Francisco Arceo <[email protected]>
1 parent 4563e80 commit f855ad2

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

sdk/python/feast/infra/offline_stores/contrib/trino_offline_store/trino_type_map.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,37 @@ def trino_to_feast_value_type(trino_type_as_str: str) -> ValueType:
1414
"integer": ValueType.INT32,
1515
"bigint": ValueType.INT64,
1616
"double": ValueType.DOUBLE,
17-
"decimal": ValueType.FLOAT,
17+
"decimal32": ValueType.FLOAT,
18+
"decimal64": ValueType.DOUBLE,
1819
"timestamp": ValueType.UNIX_TIMESTAMP,
1920
"char": ValueType.STRING,
2021
"varchar": ValueType.STRING,
2122
"boolean": ValueType.BOOL,
23+
"real": ValueType.FLOAT,
2224
}
23-
return type_map[trino_type_as_str.lower()]
25+
_trino_type_as_str: str = trino_type_as_str
26+
trino_type_as_str = trino_type_as_str.lower()
27+
28+
if trino_type_as_str.startswith("decimal"):
29+
search_precision = re.search(
30+
r"^decimal\((\d+)(?>,\s?\d+)?\)$", trino_type_as_str
31+
)
32+
if search_precision:
33+
precision = int(search_precision.group(1))
34+
if precision > 32:
35+
trino_type_as_str = "decimal64"
36+
else:
37+
trino_type_as_str = "decimal32"
38+
39+
elif trino_type_as_str.startswith("timestamp"):
40+
trino_type_as_str = "timestamp"
41+
42+
elif trino_type_as_str.startswith("varchar"):
43+
trino_type_as_str = "varchar"
44+
45+
if trino_type_as_str not in type_map:
46+
raise ValueError(f"Trino type not supported by feast {_trino_type_as_str}")
47+
return type_map[trino_type_as_str]
2448

2549

2650
def pa_to_trino_value_type(pa_type_as_str: str) -> str:

0 commit comments

Comments
 (0)