15
15
from enum import Enum
16
16
from typing import Dict , Union
17
17
18
- from feast .protos . feast . types . Value_pb2 import ValueType as ValueTypeProto
18
+ from feast .value_type import ValueType
19
19
20
20
PRIMITIVE_FEAST_TYPES_TO_VALUE_TYPES = {
21
- "INVALID" : "INVALID" ,
22
- "STRING" : "STRING" ,
21
+ "INVALID" : "UNKNOWN" ,
23
22
"BYTES" : "BYTES" ,
24
- "BOOL " : "BOOL " ,
23
+ "STRING " : "STRING " ,
25
24
"INT32" : "INT32" ,
26
25
"INT64" : "INT64" ,
27
- "FLOAT32" : "FLOAT" ,
28
26
"FLOAT64" : "DOUBLE" ,
27
+ "FLOAT32" : "FLOAT" ,
28
+ "BOOL" : "BOOL" ,
29
29
"UNIX_TIMESTAMP" : "UNIX_TIMESTAMP" ,
30
30
}
31
31
@@ -40,14 +40,14 @@ def __init__(self):
40
40
pass
41
41
42
42
@abstractmethod
43
- def to_value_type (self ) -> ValueTypeProto . Enum :
43
+ def to_value_type (self ) -> ValueType :
44
44
"""
45
- Converts a ComplexFeastType object to the corresponding ValueTypeProto.Enum value .
45
+ Converts a ComplexFeastType object to the corresponding ValueType enum .
46
46
"""
47
47
raise NotImplementedError
48
48
49
49
def __hash__ (self ):
50
- return hash (self .to_value_type ())
50
+ return hash (self .to_value_type (). value )
51
51
52
52
def __eq__ (self , other ):
53
53
return self .to_value_type () == other .to_value_type ()
@@ -57,8 +57,7 @@ class PrimitiveFeastType(Enum):
57
57
"""
58
58
A PrimitiveFeastType represents a primitive type in Feast.
59
59
60
- Note that these values must match the values in ValueTypeProto.Enum. See
61
- /feast/protos/types/Value.proto for the exact values.
60
+ Note that these values must match the values in /feast/protos/types/Value.proto.
62
61
"""
63
62
64
63
INVALID = 0
@@ -71,12 +70,12 @@ class PrimitiveFeastType(Enum):
71
70
BOOL = 7
72
71
UNIX_TIMESTAMP = 8
73
72
74
- def to_value_type (self ) -> ValueTypeProto . Enum :
73
+ def to_value_type (self ) -> ValueType :
75
74
"""
76
- Converts a PrimitiveFeastType object to the corresponding ValueTypeProto.Enum value .
75
+ Converts a PrimitiveFeastType object to the corresponding ValueType enum .
77
76
"""
78
77
value_type_name = PRIMITIVE_FEAST_TYPES_TO_VALUE_TYPES [self .name ]
79
- return ValueTypeProto . Enum . Value ( value_type_name )
78
+ return ValueType [ value_type_name ]
80
79
81
80
def __str__ (self ):
82
81
return PRIMITIVE_FEAST_TYPES_TO_STRING [self .name ]
@@ -136,11 +135,11 @@ def __init__(self, base_type: Union[PrimitiveFeastType, ComplexFeastType]):
136
135
137
136
self .base_type = base_type
138
137
139
- def to_value_type (self ) -> int :
138
+ def to_value_type (self ) -> ValueType :
140
139
assert isinstance (self .base_type , PrimitiveFeastType )
141
140
value_type_name = PRIMITIVE_FEAST_TYPES_TO_VALUE_TYPES [self .base_type .name ]
142
141
value_type_list_name = value_type_name + "_LIST"
143
- return ValueTypeProto . Enum . Value ( value_type_list_name )
142
+ return ValueType [ value_type_list_name ]
144
143
145
144
def __str__ (self ):
146
145
return f"Array({ self .base_type } )"
@@ -149,33 +148,33 @@ def __str__(self):
149
148
FeastType = Union [ComplexFeastType , PrimitiveFeastType ]
150
149
151
150
152
- VALUE_TYPES_TO_FEAST_TYPES : Dict ["ValueTypeProto.Enum " , FeastType ] = {
153
- ValueTypeProto . Enum . INVALID : Invalid ,
154
- ValueTypeProto . Enum .BYTES : Bytes ,
155
- ValueTypeProto . Enum .STRING : String ,
156
- ValueTypeProto . Enum .INT32 : Int32 ,
157
- ValueTypeProto . Enum .INT64 : Int64 ,
158
- ValueTypeProto . Enum .DOUBLE : Float64 ,
159
- ValueTypeProto . Enum .FLOAT : Float32 ,
160
- ValueTypeProto . Enum .BOOL : Bool ,
161
- ValueTypeProto . Enum .UNIX_TIMESTAMP : UnixTimestamp ,
162
- ValueTypeProto . Enum .BYTES_LIST : Array (Bytes ),
163
- ValueTypeProto . Enum .STRING_LIST : Array (String ),
164
- ValueTypeProto . Enum .INT32_LIST : Array (Int32 ),
165
- ValueTypeProto . Enum .INT64_LIST : Array (Int64 ),
166
- ValueTypeProto . Enum .DOUBLE_LIST : Array (Float64 ),
167
- ValueTypeProto . Enum .FLOAT_LIST : Array (Float32 ),
168
- ValueTypeProto . Enum .BOOL_LIST : Array (Bool ),
169
- ValueTypeProto . Enum .UNIX_TIMESTAMP_LIST : Array (UnixTimestamp ),
151
+ VALUE_TYPES_TO_FEAST_TYPES : Dict ["ValueType " , FeastType ] = {
152
+ ValueType . UNKNOWN : Invalid ,
153
+ ValueType .BYTES : Bytes ,
154
+ ValueType .STRING : String ,
155
+ ValueType .INT32 : Int32 ,
156
+ ValueType .INT64 : Int64 ,
157
+ ValueType .DOUBLE : Float64 ,
158
+ ValueType .FLOAT : Float32 ,
159
+ ValueType .BOOL : Bool ,
160
+ ValueType .UNIX_TIMESTAMP : UnixTimestamp ,
161
+ ValueType .BYTES_LIST : Array (Bytes ),
162
+ ValueType .STRING_LIST : Array (String ),
163
+ ValueType .INT32_LIST : Array (Int32 ),
164
+ ValueType .INT64_LIST : Array (Int64 ),
165
+ ValueType .DOUBLE_LIST : Array (Float64 ),
166
+ ValueType .FLOAT_LIST : Array (Float32 ),
167
+ ValueType .BOOL_LIST : Array (Bool ),
168
+ ValueType .UNIX_TIMESTAMP_LIST : Array (UnixTimestamp ),
170
169
}
171
170
172
171
173
- def from_value_type (value_type : ValueTypeProto . Enum ,) -> FeastType :
172
+ def from_value_type (value_type : ValueType ,) -> FeastType :
174
173
"""
175
- Converts a ValueTypeProto.Enum to a Feast type.
174
+ Converts a ValueType enum to a Feast type.
176
175
177
176
Args:
178
- value_type: The ValueTypeProto.Enum to be converted.
177
+ value_type: The ValueType to be converted.
179
178
180
179
Raises:
181
180
ValueError: The conversion could not be performed.
0 commit comments