1515import decimal
1616import json
1717import logging
18+ import uuid as uuid_module
1819from collections import defaultdict
1920from datetime import datetime , timezone
2021from typing import (
6061logger = logging .getLogger (__name__ )
6162
6263
63- def feast_value_type_to_python_type (field_value_proto : ProtoValue ) -> Any :
64+ def feast_value_type_to_python_type (
65+ field_value_proto : ProtoValue ,
66+ feature_type : Optional [ValueType ] = None ,
67+ ) -> Any :
6468 """
6569 Converts field value Proto to Dict and returns each field's Feast Value Type value
6670 in their respective Python value.
@@ -103,6 +107,9 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
103107 else None
104108 )
105109
110+ if feature_type in (ValueType .UUID , ValueType .TIME_UUID ) and isinstance (val , str ):
111+ return uuid_module .UUID (val )
112+
106113 return val
107114
108115
@@ -139,6 +146,8 @@ def feast_value_type_to_pandas_type(value_type: ValueType) -> Any:
139146 ValueType .BYTES : "bytes" ,
140147 ValueType .BOOL : "bool" ,
141148 ValueType .UNIX_TIMESTAMP : "datetime64[ns]" ,
149+ ValueType .UUID : "str" ,
150+ ValueType .TIME_UUID : "str" ,
142151 }
143152 if value_type .name == "MAP" or value_type .name .endswith ("_LIST" ):
144153 return "object"
@@ -198,6 +207,7 @@ def python_type_to_feast_value_type(
198207 "datetime64[ns, utc]" : ValueType .UNIX_TIMESTAMP ,
199208 "date" : ValueType .UNIX_TIMESTAMP ,
200209 "category" : ValueType .STRING ,
210+ "uuid" : ValueType .UUID ,
201211 }
202212
203213 if type_name in type_map :
@@ -316,6 +326,10 @@ def _convert_value_type_str_to_value_type(type_str: str) -> ValueType:
316326 "FLOAT_LIST" : ValueType .FLOAT_LIST ,
317327 "BOOL_LIST" : ValueType .BOOL_LIST ,
318328 "UNIX_TIMESTAMP_LIST" : ValueType .UNIX_TIMESTAMP_LIST ,
329+ "UUID" : ValueType .UUID ,
330+ "TIME_UUID" : ValueType .TIME_UUID ,
331+ "UUID_LIST" : ValueType .UUID_LIST ,
332+ "TIME_UUID_LIST" : ValueType .TIME_UUID_LIST ,
319333 }
320334 return type_map .get (type_str , ValueType .STRING )
321335
@@ -347,6 +361,8 @@ def _type_err(item, dtype):
347361 ValueType .STRING_LIST : (StringList , "string_list_val" , [np .str_ , str ]),
348362 ValueType .BOOL_LIST : (BoolList , "bool_list_val" , [np .bool_ , bool ]),
349363 ValueType .BYTES_LIST : (BytesList , "bytes_list_val" , [np .bytes_ , bytes ]),
364+ ValueType .UUID_LIST : (StringList , "string_list_val" , [np .str_ , str , uuid_module .UUID ]),
365+ ValueType .TIME_UUID_LIST : (StringList , "string_list_val" , [np .str_ , str , uuid_module .UUID ]),
350366}
351367
352368PYTHON_SCALAR_VALUE_TYPE_TO_PROTO_VALUE : Dict [
@@ -372,6 +388,8 @@ def _type_err(item, dtype):
372388 ValueType .BYTES : ("bytes_val" , lambda x : x , {bytes }),
373389 ValueType .IMAGE_BYTES : ("bytes_val" , lambda x : x , {bytes }),
374390 ValueType .BOOL : ("bool_val" , lambda x : x , {bool , np .bool_ , int , np .int_ }),
391+ ValueType .UUID : ("string_val" , lambda x : str (x ), {str , uuid_module .UUID }),
392+ ValueType .TIME_UUID : ("string_val" , lambda x : str (x ), {str , uuid_module .UUID }),
375393}
376394
377395
@@ -868,6 +886,8 @@ def _convert_value_name_to_snowflake_udf(value_name: str, project_name: str) ->
868886 "FLOAT_LIST" : f"feast_{ project_name } _snowflake_array_float_to_list_double_proto" ,
869887 "BOOL_LIST" : f"feast_{ project_name } _snowflake_array_boolean_to_list_bool_proto" ,
870888 "UNIX_TIMESTAMP_LIST" : f"feast_{ project_name } _snowflake_array_timestamp_to_list_unix_timestamp_proto" ,
889+ "UUID" : f"feast_{ project_name } _snowflake_varchar_to_string_proto" ,
890+ "TIME_UUID" : f"feast_{ project_name } _snowflake_varchar_to_string_proto" ,
871891 }
872892 return name_map [value_name ].upper ()
873893
@@ -1047,8 +1067,8 @@ def pg_type_to_feast_value_type(type_str: str) -> ValueType:
10471067 "timestamp with time zone[]" : ValueType .UNIX_TIMESTAMP_LIST ,
10481068 "numeric[]" : ValueType .DOUBLE_LIST ,
10491069 "numeric" : ValueType .DOUBLE ,
1050- "uuid" : ValueType .STRING ,
1051- "uuid[]" : ValueType .STRING_LIST ,
1070+ "uuid" : ValueType .UUID ,
1071+ "uuid[]" : ValueType .UUID_LIST ,
10521072 }
10531073 value = (
10541074 type_map [type_str .lower ()]
@@ -1083,6 +1103,10 @@ def feast_value_type_to_pa(
10831103 ValueType .BOOL_LIST : pyarrow .list_ (pyarrow .bool_ ()),
10841104 ValueType .UNIX_TIMESTAMP_LIST : pyarrow .list_ (pyarrow .timestamp (timestamp_unit )),
10851105 ValueType .NULL : pyarrow .null (),
1106+ ValueType .UUID : pyarrow .string (),
1107+ ValueType .TIME_UUID : pyarrow .string (),
1108+ ValueType .UUID_LIST : pyarrow .list_ (pyarrow .string ()),
1109+ ValueType .TIME_UUID_LIST : pyarrow .list_ (pyarrow .string ()),
10861110 }
10871111 return type_map [feast_type ]
10881112
@@ -1221,7 +1245,7 @@ def cb_columnar_type_to_feast_value_type(type_str: str) -> ValueType:
12211245 "object" : ValueType .UNKNOWN ,
12221246 "array" : ValueType .UNKNOWN ,
12231247 "multiset" : ValueType .UNKNOWN ,
1224- "uuid" : ValueType .STRING ,
1248+ "uuid" : ValueType .UUID ,
12251249 }
12261250 value = (
12271251 type_map [type_str .lower ()]
@@ -1247,6 +1271,8 @@ def convert_scalar_column(
12471271 return series .astype ("boolean" )
12481272 elif value_type == ValueType .STRING :
12491273 return series .astype ("string" )
1274+ elif value_type in [ValueType .UUID , ValueType .TIME_UUID ]:
1275+ return series .astype ("string" )
12501276 elif value_type == ValueType .UNIX_TIMESTAMP :
12511277 return pd .to_datetime (series , unit = "s" , errors = "coerce" )
12521278 else :
0 commit comments