Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,10 +2076,16 @@ def arrow_to_pg_type(t_str: str) -> str:
return "jsonb"
if t_str.startswith("struct<") or t_str.startswith("struct{"):
return "jsonb"
if t_str.startswith("decimal"):
return "numeric"
if t_str.startswith("date"):
return "date"
return {
"null": "null",
# Postgres has no "null" type; an all-null column still needs one.
"null": "text",
"bool": "boolean",
"int8": "tinyint",
# Postgres has no 1-byte integer type.
"int8": "smallint",
"int16": "smallint",
"int32": "int",
"int64": "bigint",
Expand All @@ -2094,7 +2100,8 @@ def arrow_to_pg_type(t_str: str) -> str:
"uint64": "bigint",
"float": "float",
"double": "double precision",
"binary": "binary",
"binary": "bytea",
"large_binary": "bytea",
"string": "text",
}[t_str]
except KeyError:
Expand Down
17 changes: 17 additions & 0 deletions sdk/python/tests/unit/test_type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,23 @@ def test_convert_value_type_str_round_trips_every_name(self, value_type):
"""Every ValueType name converts back to that ValueType."""
assert _convert_value_type_str_to_value_type(value_type.name) == value_type

@pytest.mark.parametrize(
"arrow_type, expected",
[
(pyarrow.int8(), "smallint"),
(pyarrow.binary(), "bytea"),
(pyarrow.large_binary(), "bytea"),
(pyarrow.null(), "text"),
(pyarrow.date32(), "date"),
(pyarrow.date64(), "date"),
(pyarrow.decimal128(10, 2), "numeric"),
],
)
def test_arrow_to_pg_type_uses_postgres_type_names(self, arrow_type, expected):
"""Postgres has no tinyint, binary or null type; the entity dataframe
upload builds CREATE TABLE from these names."""
assert arrow_to_pg_type(str(arrow_type)) == expected

def test_arrow_to_pg_type_map(self):
"""Test that Arrow map type converts to Postgres jsonb."""
assert arrow_to_pg_type("map<string, string>") == "jsonb"
Expand Down
Loading