Skip to content

Commit f77832e

Browse files
committed
fix: Infer a type for Snowflake NUMBER(19,0) columns
SnowflakeSource.get_table_column_names_and_types types integer columns with precision up to 18 from the precision and reads MAX() for columns with precision above 19. A NUMBER(19,0) column matched neither branch, so its type was returned as "None" and snowflake_type_to_feast_value_type raised KeyError: 'None' during feature inference and offline_write_batch. Read MAX() for every integer column with precision above 18. Before the MAX() lookups were batched in PR 5387, precision 19 also took that path. Signed-off-by: sohailshk <122166523+sohailshk@users.noreply.github.com>
1 parent 820b264 commit f77832e

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎sdk/python/feast/infra/offline_stores/snowflake_source.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def get_table_column_names_and_types(
252252
high_precision_number_columns = [
253253
col["column_name"]
254254
for col in metadata
255-
if col["type_code"] == 0 and col["scale"] == 0 and col["precision"] > 19
255+
if col["type_code"] == 0 and col["scale"] == 0 and col["precision"] > 18
256256
]
257257

258258
if high_precision_number_columns:

‎sdk/python/tests/unit/infra/offline_stores/test_snowflake.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from types import SimpleNamespace
23
from unittest.mock import ANY, MagicMock, patch
34

45
import pandas as pd
@@ -10,6 +11,7 @@
1011
SnowflakeOfflineStoreConfig,
1112
SnowflakeRetrievalJob,
1213
)
14+
from feast.infra.offline_stores.snowflake_source import SnowflakeSource
1315
from feast.infra.online_stores.sqlite import SqliteOnlineStoreConfig
1416
from feast.repo_config import RepoConfig
1517
from feast.types import Array, String
@@ -85,3 +87,53 @@ def test_snowflake_to_df_internal(
8587
)
8688
retrieval_job._feature_views = [feature_view]
8789
retrieval_job._to_df_internal()
90+
91+
92+
@pytest.mark.parametrize(
93+
"precision, max_value, expected",
94+
[
95+
(18, None, "NUMBER64"),
96+
(19, 42, "NUMBER32"),
97+
(19, 1234567890123, "NUMBER64"),
98+
(38, 1234567890123, "NUMBER64"),
99+
],
100+
)
101+
def test_snowflake_source_integer_column_types(
102+
mocker: MockFixture, precision, max_value, expected
103+
):
104+
config = RepoConfig(
105+
registry="s3://ml-test/repo/registry.db",
106+
project="test",
107+
provider="local",
108+
online_store=SqliteOnlineStoreConfig(type="sqlite"),
109+
offline_store=SnowflakeOfflineStoreConfig(
110+
type="snowflake.offline",
111+
account="snow",
112+
user="snow",
113+
password="snow",
114+
role="snow",
115+
warehouse="snow",
116+
database="FEAST",
117+
schema="PUBLIC",
118+
),
119+
entity_key_serialization_version=3,
120+
)
121+
sample = MagicMock()
122+
sample.description = [
123+
SimpleNamespace(
124+
name="ID", type_code=0, precision=precision, scale=0, is_nullable=True
125+
)
126+
]
127+
sample.fetch_pandas_all.return_value = pd.DataFrame({"ID": [1]})
128+
maximum = MagicMock()
129+
maximum.fetch_pandas_all.return_value = pd.DataFrame({"ID": [max_value]})
130+
mocker.patch("feast.infra.utils.snowflake.snowflake_utils.GetSnowflakeConnection")
131+
mocker.patch(
132+
"feast.infra.utils.snowflake.snowflake_utils.execute_snowflake_statement",
133+
side_effect=[sample, maximum],
134+
)
135+
source = SnowflakeSource(
136+
name="source", database="FEAST", schema="PUBLIC", table="T"
137+
)
138+
139+
assert list(source.get_table_column_names_and_types(config)) == [("ID", expected)]

0 commit comments

Comments
 (0)