1515import decimal
1616import json
1717import logging
18+ import uuid as uuid_module
1819from collections import defaultdict
1920from datetime import datetime , timezone
2021from typing import (
6768logger = logging .getLogger (__name__ )
6869
6970
70- def feast_value_type_to_python_type (field_value_proto : ProtoValue ) -> Any :
71+ def feast_value_type_to_python_type (
72+ field_value_proto : ProtoValue ,
73+ feature_type : Optional [ValueType ] = None ,
74+ ) -> Any :
7175 """
7276 Converts field value Proto to Dict and returns each field's Feast Value Type value
7377 in their respective Python value.
@@ -148,6 +152,9 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
148152 elif val_attr .endswith ("_set_val" ) and val_attr != "unix_timestamp_set_val" :
149153 val = set (val )
150154
155+ if feature_type in (ValueType .UUID , ValueType .TIME_UUID ) and isinstance (val , str ):
156+ return uuid_module .UUID (val )
157+
151158 return val
152159
153160
@@ -184,6 +191,8 @@ def feast_value_type_to_pandas_type(value_type: ValueType) -> Any:
184191 ValueType .BYTES : "bytes" ,
185192 ValueType .BOOL : "bool" ,
186193 ValueType .UNIX_TIMESTAMP : "datetime64[ns]" ,
194+ ValueType .UUID : "str" ,
195+ ValueType .TIME_UUID : "str" ,
187196 }
188197 if (
189198 value_type .name in ("MAP" , "JSON" , "STRUCT" )
@@ -247,6 +256,7 @@ def python_type_to_feast_value_type(
247256 "datetime64[ns, utc]" : ValueType .UNIX_TIMESTAMP ,
248257 "date" : ValueType .UNIX_TIMESTAMP ,
249258 "category" : ValueType .STRING ,
259+ "uuid" : ValueType .UUID ,
250260 }
251261
252262 if type_name in type_map :
@@ -405,6 +415,10 @@ def _convert_value_type_str_to_value_type(type_str: str) -> ValueType:
405415 "JSON_LIST" : ValueType .JSON_LIST ,
406416 "STRUCT" : ValueType .STRUCT ,
407417 "STRUCT_LIST" : ValueType .STRUCT_LIST ,
418+ "UUID" : ValueType .UUID ,
419+ "TIME_UUID" : ValueType .TIME_UUID ,
420+ "UUID_LIST" : ValueType .UUID_LIST ,
421+ "TIME_UUID_LIST" : ValueType .TIME_UUID_LIST ,
408422 }
409423 return type_map .get (type_str , ValueType .STRING )
410424
@@ -436,6 +450,8 @@ def _type_err(item, dtype):
436450 ValueType .STRING_LIST : (StringList , "string_list_val" , [np .str_ , str ]),
437451 ValueType .BOOL_LIST : (BoolList , "bool_list_val" , [np .bool_ , bool ]),
438452 ValueType .BYTES_LIST : (BytesList , "bytes_list_val" , [np .bytes_ , bytes ]),
453+ ValueType .UUID_LIST : (StringList , "string_list_val" , [np .str_ , str , uuid_module .UUID ]),
454+ ValueType .TIME_UUID_LIST : (StringList , "string_list_val" , [np .str_ , str , uuid_module .UUID ]),
439455}
440456
441457PYTHON_SET_VALUE_TYPE_TO_PROTO_VALUE : Dict [
@@ -486,6 +502,8 @@ def _type_err(item, dtype):
486502 ValueType .BYTES : ("bytes_val" , lambda x : x , {bytes }),
487503 ValueType .IMAGE_BYTES : ("bytes_val" , lambda x : x , {bytes }),
488504 ValueType .BOOL : ("bool_val" , lambda x : x , {bool , np .bool_ , int , np .int_ }),
505+ ValueType .UUID : ("string_val" , lambda x : str (x ), {str , uuid_module .UUID }),
506+ ValueType .TIME_UUID : ("string_val" , lambda x : str (x ), {str , uuid_module .UUID }),
489507}
490508
491509
@@ -1347,6 +1365,8 @@ def _convert_value_name_to_snowflake_udf(value_name: str, project_name: str) ->
13471365 "FLOAT_LIST" : f"feast_{ project_name } _snowflake_array_float_to_list_double_proto" ,
13481366 "BOOL_LIST" : f"feast_{ project_name } _snowflake_array_boolean_to_list_bool_proto" ,
13491367 "UNIX_TIMESTAMP_LIST" : f"feast_{ project_name } _snowflake_array_timestamp_to_list_unix_timestamp_proto" ,
1368+ "UUID" : f"feast_{ project_name } _snowflake_varchar_to_string_proto" ,
1369+ "TIME_UUID" : f"feast_{ project_name } _snowflake_varchar_to_string_proto" ,
13501370 }
13511371 return name_map [value_name ].upper ()
13521372
@@ -1550,8 +1570,8 @@ def pg_type_to_feast_value_type(type_str: str) -> ValueType:
15501570 "timestamp with time zone[]" : ValueType .UNIX_TIMESTAMP_LIST ,
15511571 "numeric[]" : ValueType .DOUBLE_LIST ,
15521572 "numeric" : ValueType .DOUBLE ,
1553- "uuid" : ValueType .STRING ,
1554- "uuid[]" : ValueType .STRING_LIST ,
1573+ "uuid" : ValueType .UUID ,
1574+ "uuid[]" : ValueType .UUID_LIST ,
15551575 "json" : ValueType .MAP ,
15561576 "jsonb" : ValueType .MAP ,
15571577 "json[]" : ValueType .MAP_LIST ,
@@ -1598,6 +1618,10 @@ def feast_value_type_to_pa(
15981618 ValueType .STRUCT : pyarrow .struct ([]),
15991619 ValueType .STRUCT_LIST : pyarrow .list_ (pyarrow .struct ([])),
16001620 ValueType .NULL : pyarrow .null (),
1621+ ValueType .UUID : pyarrow .string (),
1622+ ValueType .TIME_UUID : pyarrow .string (),
1623+ ValueType .UUID_LIST : pyarrow .list_ (pyarrow .string ()),
1624+ ValueType .TIME_UUID_LIST : pyarrow .list_ (pyarrow .string ()),
16011625 }
16021626 return type_map [feast_type ]
16031627
@@ -1750,7 +1774,7 @@ def cb_columnar_type_to_feast_value_type(type_str: str) -> ValueType:
17501774 "object" : ValueType .UNKNOWN ,
17511775 "array" : ValueType .UNKNOWN ,
17521776 "multiset" : ValueType .UNKNOWN ,
1753- "uuid" : ValueType .STRING ,
1777+ "uuid" : ValueType .UUID ,
17541778 }
17551779 value = (
17561780 type_map [type_str .lower ()]
@@ -1776,6 +1800,8 @@ def convert_scalar_column(
17761800 return series .astype ("boolean" )
17771801 elif value_type == ValueType .STRING :
17781802 return series .astype ("string" )
1803+ elif value_type in [ValueType .UUID , ValueType .TIME_UUID ]:
1804+ return series .astype ("string" )
17791805 elif value_type == ValueType .UNIX_TIMESTAMP :
17801806 return pd .to_datetime (series , unit = "s" , errors = "coerce" )
17811807 elif value_type in (ValueType .JSON , ValueType .STRUCT , ValueType .MAP ):
0 commit comments