From 2f29638c2d888e399ae3ab58ff7a8c89cf6b805d Mon Sep 17 00:00:00 2001 From: Curtis Stallings Date: Sat, 31 Dec 2022 09:50:24 -0600 Subject: [PATCH 1/4] fixed issue for double query with effective_user --- pytabular/query.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pytabular/query.py b/pytabular/query.py index 7886ee9..f1c5f4e 100644 --- a/pytabular/query.py +++ b/pytabular/query.py @@ -53,7 +53,9 @@ def Query(self, Query_Str: str) -> Union[pd.DataFrame, str, int]: with open(Query_Str, "r") as file: Query_Str = str(file.read()) - if self.State.value__ == 0: + if str(self.get_State()) != 'Open': + #Works for now, need to update to handle different types of conneciton properties + #https://learn.microsoft.com/en-us/dotnet/api/system.data.connectionstate?view=net-7.0 logger.info("Checking initial Adomd Connection...") self.Open() logger.info(f"Connected! Session ID - {self.SessionID}") From c63e97d8531b6a45779d71deaccdd9b10501aa2a Mon Sep 17 00:00:00 2001 From: Curtis Stallings Date: Sat, 31 Dec 2022 09:54:47 -0600 Subject: [PATCH 2/4] fixed bug with multiple queries for effective_user --- pytabular/pytabular.py | 4 ++-- pytabular/query.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pytabular/pytabular.py b/pytabular/pytabular.py index 4ef475f..3d3dba6 100644 --- a/pytabular/pytabular.py +++ b/pytabular/pytabular.py @@ -451,9 +451,9 @@ def Query( try: conn = self.Effective_Users[Effective_User] - if isinstance(conn, Connection): - conn.Query(Query_Str) + logger.debug(f"Effective user found querying as... {Effective_User}") except Exception: + logger.debug(f"Creating new connection with {Effective_User}") conn = Connection(self.Server, Effective_User=Effective_User) self.Effective_Users[Effective_User] = conn diff --git a/pytabular/query.py b/pytabular/query.py index f1c5f4e..226f472 100644 --- a/pytabular/query.py +++ b/pytabular/query.py @@ -53,9 +53,9 @@ def Query(self, Query_Str: str) -> Union[pd.DataFrame, str, int]: with open(Query_Str, "r") as file: Query_Str = str(file.read()) - if str(self.get_State()) != 'Open': - #Works for now, need to update to handle different types of conneciton properties - #https://learn.microsoft.com/en-us/dotnet/api/system.data.connectionstate?view=net-7.0 + if str(self.get_State()) != "Open": + # Works for now, need to update to handle different types of conneciton properties + # https://learn.microsoft.com/en-us/dotnet/api/system.data.connectionstate?view=net-7.0 logger.info("Checking initial Adomd Connection...") self.Open() logger.info(f"Connected! Session ID - {self.SessionID}") From edc6c7c44df33b16b5e0e951fa3272f551a2e6e9 Mon Sep 17 00:00:00 2001 From: Curtis Stallings Date: Sat, 31 Dec 2022 09:55:09 -0600 Subject: [PATCH 3/4] temp fix for aas directquery with topnskip --- pytabular/column.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/pytabular/column.py b/pytabular/column.py index 8eb3e7a..341570a 100644 --- a/pytabular/column.py +++ b/pytabular/column.py @@ -32,19 +32,34 @@ def __init__(self, object, table) -> None: def get_sample_values(self, top_n: int = 3) -> pd.DataFrame: """Get sample values of column.""" column_to_sample = f"'{self.Table.Name}'[{self.Name}]" - dax_query = f"""EVALUATE - TOPNSKIP( - {top_n}, - 0, - FILTER( - VALUES({column_to_sample}), - NOT ISBLANK({column_to_sample}) && LEN({column_to_sample}) > 0 - ), - 1 - ) - ORDER BY {column_to_sample} - """ - return self.Table.Model.Query(dax_query) + try: + # adding temporary try except. TOPNSKIP will not work for directquery mode. + # Need an efficient way to identify if query is direct query or not. + dax_query = f"""EVALUATE + TOPNSKIP( + {top_n}, + 0, + FILTER( + VALUES({column_to_sample}), + NOT ISBLANK({column_to_sample}) && LEN({column_to_sample}) > 0 + ), + 1 + ) + ORDER BY {column_to_sample} + """ + return self.Table.Model.Query(dax_query) + except Exception: + dax_query = f""" + EVALUATE + TOPN( + {top_n}, + FILTER( + VALUES({column_to_sample}), + NOT ISBLANK({column_to_sample}) && LEN({column_to_sample}) > 0 + ) + ) + """ + return self.Table.Model.Query(dax_query) def Distinct_Count(self, No_Blank=False) -> int: """Get [DISTINCTCOUNT](https://learn.microsoft.com/en-us/dax/distinctcount-function-dax) of Column. From 27d5e7c08d3875653b852b24024378664410cd9d Mon Sep 17 00:00:00 2001 From: Curtis Stallings Date: Sat, 31 Dec 2022 10:05:28 -0600 Subject: [PATCH 4/4] shifted tests to 2tabular.py --- test/test_2tabular.py | 20 +++++++++++++++++++- test/test_3custom.py | 20 +------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/test_2tabular.py b/test/test_2tabular.py index dc96df7..7d08f98 100644 --- a/test/test_2tabular.py +++ b/test/test_2tabular.py @@ -1,7 +1,7 @@ import pytest import pandas as pd import pytabular as p -from test.config import testingtablename, testing_parameters, get_test_path +from test.config import testingtablename, testing_parameters, get_test_path, LOCAL_FILE @pytest.mark.parametrize("model", testing_parameters) @@ -81,3 +81,21 @@ def test_Table_Last_Refresh_Times(model): def test_Return_Zero_Row_Tables(model): """Testing that `Return_Zero_Row_Tables`""" assert isinstance(p.Return_Zero_Row_Tables(model), list) is True + + +@pytest.mark.parametrize("model", testing_parameters) +def test_get_dependencies(model): + if len(model.Measures) > 0: + dependencies = model.Measures[0].get_dependencies() + assert len(dependencies) > 0 + else: + assert True + + +@pytest.mark.parametrize("model", testing_parameters) +def test_get_sample_values(model): + if LOCAL_FILE[0] == "AdventureWorks Sales": + df = model.Columns["Country"].get_sample_values() + assert len(df) > 0 + else: + assert True diff --git a/test/test_3custom.py b/test/test_3custom.py index 474c11f..265ebda 100644 --- a/test/test_3custom.py +++ b/test/test_3custom.py @@ -2,7 +2,7 @@ These were designed selfishly for my own uses. So seperating out, to one day sunset and remove. """ -from test.config import testing_parameters, testingtablename, LOCAL_FILE +from test.config import testing_parameters, testingtablename import pytest @@ -44,21 +44,3 @@ def test_revert_table(model): ) == 1 ) - - -@pytest.mark.parametrize("model", testing_parameters) -def test_get_dependencies(model): - if len(model.Measures) > 0: - dependencies = model.Measures[0].get_dependencies() - assert len(dependencies) > 0 - else: - assert True - - -@pytest.mark.parametrize("model", testing_parameters) -def test_get_sample_values(model): - if LOCAL_FILE[0] == "AdventureWorks Sales": - df = model.Columns["Country"].get_sample_values() - assert len(df) > 0 - else: - assert True