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.
@@ -124,6 +128,9 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
124128 elif val_attr .endswith ("_set_val" ) and val_attr != "unix_timestamp_set_val" :
125129 val = set (val )
126130
131+ if feature_type in (ValueType .UUID , ValueType .TIME_UUID ) and isinstance (val , str ):
132+ return uuid_module .UUID (val )
133+
127134 return val
128135
129136
@@ -160,6 +167,8 @@ def feast_value_type_to_pandas_type(value_type: ValueType) -> Any:
160167 ValueType .BYTES : "bytes" ,
161168 ValueType .BOOL : "bool" ,
162169 ValueType .UNIX_TIMESTAMP : "datetime64[ns]" ,
170+ ValueType .UUID : "str" ,
171+ ValueType .TIME_UUID : "str" ,
163172 }
164173 if (
165174 value_type .name == "MAP"
@@ -223,6 +232,7 @@ def python_type_to_feast_value_type(
223232 "datetime64[ns, utc]" : ValueType .UNIX_TIMESTAMP ,
224233 "date" : ValueType .UNIX_TIMESTAMP ,
225234 "category" : ValueType .STRING ,
235+ "uuid" : ValueType .UUID ,
226236 }
227237
228238 if type_name in type_map :
@@ -375,6 +385,10 @@ def _convert_value_type_str_to_value_type(type_str: str) -> ValueType:
375385 "FLOAT_LIST" : ValueType .FLOAT_LIST ,
376386 "BOOL_LIST" : ValueType .BOOL_LIST ,
377387 "UNIX_TIMESTAMP_LIST" : ValueType .UNIX_TIMESTAMP_LIST ,
388+ "UUID" : ValueType .UUID ,
389+ "TIME_UUID" : ValueType .TIME_UUID ,
390+ "UUID_LIST" : ValueType .UUID_LIST ,
391+ "TIME_UUID_LIST" : ValueType .TIME_UUID_LIST ,
378392 }
379393 return type_map .get (type_str , ValueType .STRING )
380394
@@ -406,6 +420,8 @@ def _type_err(item, dtype):
406420 ValueType .STRING_LIST : (StringList , "string_list_val" , [np .str_ , str ]),
407421 ValueType .BOOL_LIST : (BoolList , "bool_list_val" , [np .bool_ , bool ]),
408422 ValueType .BYTES_LIST : (BytesList , "bytes_list_val" , [np .bytes_ , bytes ]),
423+ ValueType .UUID_LIST : (StringList , "string_list_val" , [np .str_ , str , uuid_module .UUID ]),
424+ ValueType .TIME_UUID_LIST : (StringList , "string_list_val" , [np .str_ , str , uuid_module .UUID ]),
409425}
410426
411427PYTHON_SET_VALUE_TYPE_TO_PROTO_VALUE : Dict [
@@ -456,6 +472,8 @@ def _type_err(item, dtype):
456472 ValueType .BYTES : ("bytes_val" , lambda x : x , {bytes }),
457473 ValueType .IMAGE_BYTES : ("bytes_val" , lambda x : x , {bytes }),
458474 ValueType .BOOL : ("bool_val" , lambda x : x , {bool , np .bool_ , int , np .int_ }),
475+ ValueType .UUID : ("string_val" , lambda x : str (x ), {str , uuid_module .UUID }),
476+ ValueType .TIME_UUID : ("string_val" , lambda x : str (x ), {str , uuid_module .UUID }),
459477}
460478
461479
@@ -1086,6 +1104,8 @@ def _convert_value_name_to_snowflake_udf(value_name: str, project_name: str) ->
10861104 "FLOAT_LIST" : f"feast_{ project_name } _snowflake_array_float_to_list_double_proto" ,
10871105 "BOOL_LIST" : f"feast_{ project_name } _snowflake_array_boolean_to_list_bool_proto" ,
10881106 "UNIX_TIMESTAMP_LIST" : f"feast_{ project_name } _snowflake_array_timestamp_to_list_unix_timestamp_proto" ,
1107+ "UUID" : f"feast_{ project_name } _snowflake_varchar_to_string_proto" ,
1108+ "TIME_UUID" : f"feast_{ project_name } _snowflake_varchar_to_string_proto" ,
10891109 }
10901110 return name_map [value_name ].upper ()
10911111
@@ -1265,8 +1285,8 @@ def pg_type_to_feast_value_type(type_str: str) -> ValueType:
12651285 "timestamp with time zone[]" : ValueType .UNIX_TIMESTAMP_LIST ,
12661286 "numeric[]" : ValueType .DOUBLE_LIST ,
12671287 "numeric" : ValueType .DOUBLE ,
1268- "uuid" : ValueType .STRING ,
1269- "uuid[]" : ValueType .STRING_LIST ,
1288+ "uuid" : ValueType .UUID ,
1289+ "uuid[]" : ValueType .UUID_LIST ,
12701290 }
12711291 value = (
12721292 type_map [type_str .lower ()]
@@ -1301,6 +1321,10 @@ def feast_value_type_to_pa(
13011321 ValueType .BOOL_LIST : pyarrow .list_ (pyarrow .bool_ ()),
13021322 ValueType .UNIX_TIMESTAMP_LIST : pyarrow .list_ (pyarrow .timestamp (timestamp_unit )),
13031323 ValueType .NULL : pyarrow .null (),
1324+ ValueType .UUID : pyarrow .string (),
1325+ ValueType .TIME_UUID : pyarrow .string (),
1326+ ValueType .UUID_LIST : pyarrow .list_ (pyarrow .string ()),
1327+ ValueType .TIME_UUID_LIST : pyarrow .list_ (pyarrow .string ()),
13041328 }
13051329 return type_map [feast_type ]
13061330
@@ -1439,7 +1463,7 @@ def cb_columnar_type_to_feast_value_type(type_str: str) -> ValueType:
14391463 "object" : ValueType .UNKNOWN ,
14401464 "array" : ValueType .UNKNOWN ,
14411465 "multiset" : ValueType .UNKNOWN ,
1442- "uuid" : ValueType .STRING ,
1466+ "uuid" : ValueType .UUID ,
14431467 }
14441468 value = (
14451469 type_map [type_str .lower ()]
@@ -1465,6 +1489,8 @@ def convert_scalar_column(
14651489 return series .astype ("boolean" )
14661490 elif value_type == ValueType .STRING :
14671491 return series .astype ("string" )
1492+ elif value_type in [ValueType .UUID , ValueType .TIME_UUID ]:
1493+ return series .astype ("string" )
14681494 elif value_type == ValueType .UNIX_TIMESTAMP :
14691495 return pd .to_datetime (series , unit = "s" , errors = "coerce" )
14701496 else :
0 commit comments