Skip to content

Commit ed58ce1

Browse files
feat: Add decimal datatype to spark mapping to feast data type
Signed-off-by: tanlocnguyen <tanlocnguyen296@gmail.com>
1 parent 21e5434 commit ed58ce1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sdk/python/feast/type_map.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import json
16+
import re
1617
from collections import defaultdict
1718
from datetime import datetime, timezone
1819
from typing import (
@@ -752,7 +753,7 @@ def _non_empty_value(value: Any) -> bool:
752753

753754
def spark_to_feast_value_type(spark_type_as_str: str) -> ValueType:
754755
# TODO not all spark types are convertible
755-
# Current non-convertible types: interval, map, struct, structfield, decimal, binary
756+
# Current non-convertible types: interval, map, struct, structfield, binary
756757
type_map: Dict[str, ValueType] = {
757758
"null": ValueType.UNKNOWN,
758759
"byte": ValueType.BYTES,
@@ -762,6 +763,7 @@ def spark_to_feast_value_type(spark_type_as_str: str) -> ValueType:
762763
"bigint": ValueType.INT64,
763764
"long": ValueType.INT64,
764765
"double": ValueType.DOUBLE,
766+
"decimal": ValueType.DOUBLE,
765767
"float": ValueType.FLOAT,
766768
"boolean": ValueType.BOOL,
767769
"timestamp": ValueType.UNIX_TIMESTAMP,
@@ -774,6 +776,10 @@ def spark_to_feast_value_type(spark_type_as_str: str) -> ValueType:
774776
"array<boolean>": ValueType.BOOL_LIST,
775777
"array<timestamp>": ValueType.UNIX_TIMESTAMP_LIST,
776778
}
779+
decimal_regex_pattern = r"^decimal\([0-9]{1,2},[0-9]{1,2}\)$"
780+
if re.match(decimal_regex_pattern, spark_type_as_str):
781+
spark_type_as_str = "decimal"
782+
777783
# TODO: Find better way of doing this.
778784
if not isinstance(spark_type_as_str, str) or spark_type_as_str not in type_map:
779785
return ValueType.NULL

0 commit comments

Comments
 (0)