Skip to content

Commit

Permalink
Refactor pa_to_feast_value_type
Browse files Browse the repository at this point in the history
This refactoring is intented to make it more difficult
to forget to add conversion for LIST versions of
non-LIST types.

Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
  • Loading branch information
judahrand committed Feb 1, 2022
1 parent 53539cf commit 65cfa84
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from datetime import datetime, timezone
from typing import (
Any,
Expand Down Expand Up @@ -416,27 +415,30 @@ def _proto_value_to_value_type(proto_value: ProtoValue) -> ValueType:


def pa_to_feast_value_type(pa_type_as_str: str) -> ValueType:
if re.match(r"^timestamp", pa_type_as_str):
return ValueType.INT64
is_list = False
if pa_type_as_str.startswith("list<item: "):
is_list = True
pa_type_as_str = pa_type_as_str.replace("list<item: ", "").replace(">", "")

type_map = {
"int32": ValueType.INT32,
"int64": ValueType.INT64,
"double": ValueType.DOUBLE,
"float": ValueType.FLOAT,
"string": ValueType.STRING,
"binary": ValueType.BYTES,
"bool": ValueType.BOOL,
"list<item: int32>": ValueType.INT32_LIST,
"list<item: int64>": ValueType.INT64_LIST,
"list<item: double>": ValueType.DOUBLE_LIST,
"list<item: float>": ValueType.FLOAT_LIST,
"list<item: string>": ValueType.STRING_LIST,
"list<item: binary>": ValueType.BYTES_LIST,
"list<item: bool>": ValueType.BOOL_LIST,
"null": ValueType.NULL,
}
return type_map[pa_type_as_str]
if pa_type_as_str.startswith("timestamp"):
value_type = ValueType.UNIX_TIMESTAMP
else:
type_map = {
"int32": ValueType.INT32,
"int64": ValueType.INT64,
"double": ValueType.DOUBLE,
"float": ValueType.FLOAT,
"string": ValueType.STRING,
"binary": ValueType.BYTES,
"bool": ValueType.BOOL,
"null": ValueType.NULL,
}
value_type = type_map[pa_type_as_str]

if is_list:
value_type = ValueType[value_type.name + "_LIST"]

return value_type


def bq_to_feast_value_type(bq_type_as_str: str) -> ValueType:
Expand Down

0 comments on commit 65cfa84

Please sign in to comment.