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

Feature: Changing get_table_names from column_parser #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion sqlanalyzer/column_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_table_names(self, line_query):

for line in line_query:

table_line = re.findall(r"(FROM|JOIN).(\w+.*)", line)
table_line = re.findall(r"(?i)(FROM|JOIN).(\w*`?.*)", line)

if table_line != []:
table_name_line = table_line[0][1].split(' ')
Expand Down
21 changes: 21 additions & 0 deletions sqlanalyzer/tests/test_column_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ def sample_query():
return query


@pytest.fixture
def sample_query_diff_dbs():
query = """
SELECT *
from `some_database.schema.table`
INNER JOIN some_schema.some_table
WHERE column IS NULL
"""
return query


@pytest.fixture
def formatter(sample_query):
formatter = column_parser.Parser(sample_query)
Expand All @@ -36,3 +47,13 @@ def test_get_table_names(sample_query, formatter):

assert table_name_mapping == {'sfdc_accounts': 'sfdc.accounts',
'opportunity_to_name': 'opportunity_to_name'}


def test_get_table_names_diff_dbs(sample_query_diff_dbs):
formatter = column_parser.Parser(sample_query_diff_dbs)
formatted_query = formatter.format_query(sample_query_diff_dbs)
table_name_mapping = formatter.get_table_names(formatted_query.split('\n'))

assert table_name_mapping == {'`some_database.schema.table`': '`some_database.schema.table`',
'some_schema.some_table': 'some_schema.some_table'}