-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1043081: Adding support for qualified names for image repositori…
…es. (#823) * SNOW-1043081: Adding support for qualified image repository names * SNOW-1043081: Fixing test imports * SNOW-1043081: Adding tests for getting image repository url without db or schema
- Loading branch information
1 parent
24800a1
commit a1f258c
Showing
10 changed files
with
210 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import re | ||
from typing import Optional, Tuple | ||
|
||
from snowflake.cli.api.project.util import ( | ||
VALID_IDENTIFIER_REGEX, | ||
) | ||
|
||
|
||
def from_qualified_name(name: str) -> Tuple[str, Optional[str], Optional[str]]: | ||
""" | ||
Takes in an object name in the form [[database.]schema.]name. Returns a tuple (name, [schema], [database]) | ||
""" | ||
# TODO: Use regex to match object name to a valid identifier or valid identifier (args). Second case is for sprocs and UDFs | ||
qualifier_pattern = rf"(?:(?P<first_qualifier>{VALID_IDENTIFIER_REGEX})\.)?(?:(?P<second_qualifier>{VALID_IDENTIFIER_REGEX})\.)?(?P<name>.*)" | ||
result = re.fullmatch(qualifier_pattern, name) | ||
|
||
if result is None: | ||
raise ValueError(f"'{name}' is not a valid qualified name") | ||
|
||
unqualified_name = result.group("name") | ||
if result.group("second_qualifier") is not None: | ||
database = result.group("first_qualifier") | ||
schema = result.group("second_qualifier") | ||
else: | ||
database = None | ||
schema = result.group("first_qualifier") | ||
return unqualified_name, schema, database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
from snowflake.cli.api.utils.naming_utils import from_qualified_name | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"qualified_name, expected", | ||
[ | ||
("func(number, number)", ("func(number, number)", None, None)), | ||
("name", ("name", None, None)), | ||
("schema.name", ("name", "schema", None)), | ||
("db.schema.name", ("name", "schema", "db")), | ||
], | ||
) | ||
def test_from_fully_qualified_name(qualified_name, expected): | ||
assert from_qualified_name(qualified_name) == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.