Skip to content

Commit 3c71c3d

Browse files
committed
Revert "fix: Verify the existence of Registry tables in snowflake before calling CREATE sql command. Allow read-only user to call feast apply. (feast-dev#3851)"
This reverts commit 9a3590e. Signed-off-by: Edson Tirelli <etirelli@redhat.com>
1 parent 9a3590e commit 3c71c3d

File tree

3 files changed

+14
-171
lines changed

3 files changed

+14
-171
lines changed

sdk/python/feast/infra/registry/snowflake.py

+9-62
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,15 @@ def __init__(
124124
f'"{self.registry_config.database}"."{self.registry_config.schema_}"'
125125
)
126126

127-
if not self._verify_registry_database():
128-
# Verify the existing resitry database schema from snowflake. If any table names and column types is wrong, run table recreation SQL.
129-
with GetSnowflakeConnection(self.registry_config) as conn:
130-
sql_function_file = f"{os.path.dirname(feast.__file__)}/infra/utils/snowflake/registry/snowflake_table_creation.sql"
131-
with open(sql_function_file, "r") as file:
132-
sqlFile = file.read()
133-
134-
sqlCommands = sqlFile.split(";")
135-
for command in sqlCommands:
136-
query = command.replace(
137-
"REGISTRY_PATH", f"{self.registry_path}"
138-
)
139-
execute_snowflake_statement(conn, query)
127+
with GetSnowflakeConnection(self.registry_config) as conn:
128+
sql_function_file = f"{os.path.dirname(feast.__file__)}/infra/utils/snowflake/registry/snowflake_table_creation.sql"
129+
with open(sql_function_file, "r") as file:
130+
sqlFile = file.read()
131+
132+
sqlCommands = sqlFile.split(";")
133+
for command in sqlCommands:
134+
query = command.replace("REGISTRY_PATH", f"{self.registry_path}")
135+
execute_snowflake_statement(conn, query)
140136

141137
self.cached_registry_proto = self.proto()
142138
proto_registry_utils.init_project_metadata(self.cached_registry_proto, project)
@@ -149,55 +145,6 @@ def __init__(
149145
)
150146
self.project = project
151147

152-
def _verify_registry_database(
153-
self,
154-
) -> bool:
155-
"""Verify the records in registry database. To check:
156-
1, the 11 tables are existed.
157-
2, the column types are correct.
158-
159-
Example return from snowflake's cursor.describe("SELECT * FROM a_table") command:
160-
[ResultMetadata(name='ENTITY_NAME', type_code=2, display_size=None, internal_size=16777216, precision=None, scale=None, is_nullable=False),
161-
ResultMetadata(name='PROJECT_ID', type_code=2, display_size=None, internal_size=16777216, precision=None, scale=None, is_nullable=False),
162-
ResultMetadata(name='LAST_UPDATED_TIMESTAMP', type_code=6, display_size=None, internal_size=None, precision=0, scale=9, is_nullable=False),
163-
ResultMetadata(name='ENTITY_PROTO', type_code=11, display_size=None, internal_size=8388608, precision=None, scale=None, is_nullable=False)]
164-
165-
Returns:
166-
True if the necessary 11 tables are existed in Snowflake and schema of each table is correct.
167-
False if failure happens.
168-
"""
169-
170-
from feast.infra.utils.snowflake.registry.snowflake_registry_table import (
171-
snowflake_registry_table_names_and_column_types as expect_tables,
172-
)
173-
174-
res = True
175-
176-
try:
177-
with GetSnowflakeConnection(self.registry_config) as conn:
178-
for table_name in expect_tables:
179-
result_metadata_list = conn.cursor().describe(
180-
f"SELECT * FROM {table_name}"
181-
)
182-
for col in result_metadata_list:
183-
if (
184-
expect_tables[table_name][col.name]["type_code"]
185-
!= col.type_code
186-
):
187-
res = False
188-
break
189-
except Exception as e:
190-
res = False # Set to False for all errors.
191-
logger.debug(
192-
f"Failed to verify Registry tables and columns types with exception: {e}."
193-
)
194-
finally:
195-
# The implementation in snowflake_utils.py will cache the established connection without re-connection logic.
196-
# conn.close()
197-
pass
198-
199-
return res
200-
201148
def refresh(self, project: Optional[str] = None):
202149
if project:
203150
project_metadata = proto_registry_utils.get_project_metadata(

sdk/python/feast/infra/utils/snowflake/registry/snowflake_registry_table.py

-104
This file was deleted.

sdk/python/feast/infra/utils/snowflake/snowflake_utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ def __init__(self, config: str, autocommit=True):
4949

5050
def __enter__(self):
5151

52-
assert self.config.type in {
52+
assert self.config.type in [
5353
"snowflake.registry",
5454
"snowflake.offline",
5555
"snowflake.engine",
5656
"snowflake.online",
57-
}
57+
]
5858

5959
if self.config.type not in _cache:
6060
if self.config.type == "snowflake.registry":
6161
config_header = "connections.feast_registry"
6262
elif self.config.type == "snowflake.offline":
6363
config_header = "connections.feast_offline_store"
64-
elif self.config.type == "snowflake.engine":
64+
if self.config.type == "snowflake.engine":
6565
config_header = "connections.feast_batch_engine"
6666
elif self.config.type == "snowflake.online":
6767
config_header = "connections.feast_online_store"
@@ -113,11 +113,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
113113

114114
def assert_snowflake_feature_names(feature_view: FeatureView) -> None:
115115
for feature in feature_view.features:
116-
assert feature.name not in {
116+
assert feature.name not in [
117117
"entity_key",
118118
"feature_name",
119119
"feature_value",
120-
}, f"Feature Name: {feature.name} is a protected name to ensure query stability"
120+
], f"Feature Name: {feature.name} is a protected name to ensure query stability"
121121
return None
122122

123123

0 commit comments

Comments
 (0)