mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-09 02:02:12 +00:00

Co-authored-by: Harshal Sheth <hsheth2@gmail.com> Co-authored-by: Aseem Bansal <asmbansal2@gmail.com>
32 lines
1.7 KiB
Python
32 lines
1.7 KiB
Python
from typing import List
|
|
|
|
from datahub.ingestion.source.powerbi.m_query import native_sql_parser
|
|
|
|
|
|
def test_join():
|
|
query: str = "select A.name from GSL_TEST_DB.PUBLIC.SALES_ANALYST as A inner join GSL_TEST_DB.PUBLIC.SALES_FORECAST as B on A.name = B.name where startswith(A.name, 'mo')"
|
|
tables: List[str] = native_sql_parser.get_tables(query)
|
|
|
|
assert len(tables) == 2
|
|
assert tables[0] == "GSL_TEST_DB.PUBLIC.SALES_ANALYST"
|
|
assert tables[1] == "GSL_TEST_DB.PUBLIC.SALES_FORECAST"
|
|
|
|
|
|
def test_simple_from():
|
|
query: str = "SELECT#(lf)concat((UPPER(REPLACE(SELLER,'-',''))), MONTHID) as AGENT_KEY,#(lf)concat((UPPER(REPLACE(CLIENT_DIRECTOR,'-',''))), MONTHID) as CD_AGENT_KEY,#(lf) *#(lf)FROM#(lf)OPERATIONS_ANALYTICS.TRANSFORMED_PROD.V_APS_SME_UNITS_V4"
|
|
|
|
tables: List[str] = native_sql_parser.get_tables(query)
|
|
|
|
assert len(tables) == 1
|
|
assert tables[0] == "OPERATIONS_ANALYTICS.TRANSFORMED_PROD.V_APS_SME_UNITS_V4"
|
|
|
|
|
|
def test_drop_statement():
|
|
expected: str = "SELECT#(lf)concat((UPPER(REPLACE(SELLER,'-',''))), MONTHID) as AGENT_KEY,#(lf)concat((UPPER(REPLACE(CLIENT_DIRECTOR,'-',''))), MONTHID) as CD_AGENT_KEY,#(lf) *#(lf)FROM#(lf)OPERATIONS_ANALYTICS.TRANSFORMED_PROD.V_APS_SME_UNITS_V4"
|
|
|
|
query: str = "DROP TABLE IF EXISTS #table1; DROP TABLE IF EXISTS #table1,#table2; DROP TABLE IF EXISTS table1; DROP TABLE IF EXISTS table1, #table2;SELECT#(lf)concat((UPPER(REPLACE(SELLER,'-',''))), MONTHID) as AGENT_KEY,#(lf)concat((UPPER(REPLACE(CLIENT_DIRECTOR,'-',''))), MONTHID) as CD_AGENT_KEY,#(lf) *#(lf)FROM#(lf)OPERATIONS_ANALYTICS.TRANSFORMED_PROD.V_APS_SME_UNITS_V4"
|
|
|
|
actual: str = native_sql_parser.remove_drop_statement(query)
|
|
|
|
assert actual == expected
|