Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not use SHOW SHARES [sc-25711] #832

Merged
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
5 changes: 1 addition & 4 deletions metaphor/snowflake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ grant usage on warehouse identifier($warehouse) to role identifier($role);

-- Grant privilege to access Snowflake Account Usage views:
grant imported privileges on database snowflake to role identifier($role);

-- (Optional) Grant privilege to "show shares" for inbound shared databases
grant import share on account to identifier($role);
```

For each database, run the following statements to grant the required privileges:
For each database, including the inbound shared databases, run the following statements to grant the required privileges:

```sql
set db = '<database>';
Expand Down
10 changes: 5 additions & 5 deletions metaphor/snowflake/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,20 @@ def collect_query_logs(self) -> Iterator[QueryLog]:

@staticmethod
def fetch_databases(cursor: SnowflakeCursor) -> List[str]:
"""
Fetch all databases from Snowflake, including shared/imported databases.
"""
cursor.execute(
"SELECT database_name FROM information_schema.databases WHERE type != 'IMPORTED DATABASE' ORDER BY database_name"
"SELECT database_name FROM information_schema.databases ORDER BY database_name"
)
return [db[0].lower() for db in cursor]

@staticmethod
def _fetch_shared_databases(cursor: SnowflakeCursor) -> List[str]:
cursor.execute("SHOW SHARES")
alyiwang marked this conversation as resolved.
Show resolved Hide resolved
shared_database = [db[4].lower() for db in cursor if db[1] == "INBOUND"]
cursor.execute(
"SELECT database_name FROM information_schema.databases WHERE type = 'IMPORTED DATABASE' ORDER BY database_name"
)
shared_database += [db[0].lower() for db in cursor]
return list(set(shared_database))
return [db[0].lower() for db in cursor]

@staticmethod
def _fetch_secure_views(cursor: SnowflakeCursor) -> Set[str]:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metaphor-connectors"
version = "0.13.168"
version = "0.13.169"
license = "Apache-2.0"
description = "A collection of Python-based 'connectors' that extract metadata from various sources to ingest into the Metaphor app."
authors = ["Metaphor <[email protected]>"]
Expand Down Expand Up @@ -200,4 +200,4 @@ skips = [
'B603',
'B607',
'B608'
]
]
20 changes: 1 addition & 19 deletions tests/snowflake/test_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,31 +476,13 @@ def test_fetch_shared_databases(mock_connect: MagicMock):
mock_cursor = MagicMock()

mock_cursor.__iter__.side_effect = [
iter(
[
(
None,
"INBOUND",
None,
None,
"shared_1",
),
(
None,
"UNKNOWN",
None,
None,
"shared_2",
),
]
),
iter([("shared_1",), ("shared_3",)]),
]

extractor = SnowflakeExtractor(make_snowflake_config())
results = extractor._fetch_shared_databases(mock_cursor)

assert set(results) == {"shared_1", "shared_3"}
assert results == ["shared_1", "shared_3"]


@patch("metaphor.snowflake.extractor.check_access_history")
Expand Down
Loading