Skip to content

Commit

Permalink
feat: Add decimal datatype to spark mapping to feast data type
Browse files Browse the repository at this point in the history
Signed-off-by: tanlocnguyen <[email protected]>
  • Loading branch information
ElliotNguyen68 committed Apr 4, 2024
1 parent 21e5434 commit ed58ce1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import json
import re
from collections import defaultdict
from datetime import datetime, timezone
from typing import (
Expand Down Expand Up @@ -752,7 +753,7 @@ def _non_empty_value(value: Any) -> bool:

def spark_to_feast_value_type(spark_type_as_str: str) -> ValueType:
# TODO not all spark types are convertible
# Current non-convertible types: interval, map, struct, structfield, decimal, binary
# Current non-convertible types: interval, map, struct, structfield, binary
type_map: Dict[str, ValueType] = {
"null": ValueType.UNKNOWN,
"byte": ValueType.BYTES,
Expand All @@ -762,6 +763,7 @@ def spark_to_feast_value_type(spark_type_as_str: str) -> ValueType:
"bigint": ValueType.INT64,
"long": ValueType.INT64,
"double": ValueType.DOUBLE,
"decimal": ValueType.DOUBLE,
"float": ValueType.FLOAT,
"boolean": ValueType.BOOL,
"timestamp": ValueType.UNIX_TIMESTAMP,
Expand All @@ -774,6 +776,10 @@ def spark_to_feast_value_type(spark_type_as_str: str) -> ValueType:
"array<boolean>": ValueType.BOOL_LIST,
"array<timestamp>": ValueType.UNIX_TIMESTAMP_LIST,
}
decimal_regex_pattern = r"^decimal\([0-9]{1,2},[0-9]{1,2}\)$"
if re.match(decimal_regex_pattern, spark_type_as_str):
spark_type_as_str = "decimal"

# TODO: Find better way of doing this.
if not isinstance(spark_type_as_str, str) or spark_type_as_str not in type_map:
return ValueType.NULL
Expand Down

0 comments on commit ed58ce1

Please sign in to comment.