From 32f2e542aca9917f7dd672a3691e1f96c96e7e5d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 29 Sep 2024 19:28:26 +0200 Subject: [PATCH 1/3] fixed issue 174 --- src/sempy_labs/directlake/_dl_helper.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sempy_labs/directlake/_dl_helper.py b/src/sempy_labs/directlake/_dl_helper.py index 9436fbb5..ae5e1fa5 100644 --- a/src/sempy_labs/directlake/_dl_helper.py +++ b/src/sempy_labs/directlake/_dl_helper.py @@ -100,19 +100,26 @@ def generate_direct_lake_semantic_model( If set to True, overwrites the existing semantic model if it already exists. refresh: bool, default=True If True, refreshes the newly created semantic model after it is created. - - Returns - ------- """ from sempy_labs.lakehouse import get_lakehouse_tables, get_lakehouse_columns from sempy_labs import create_blank_semantic_model, refresh_semantic_model from sempy_labs.tom import connect_semantic_model from sempy_labs.directlake import get_shared_expression + from sempy_labs._helper_functions import resolve_lakehouse_name if isinstance(lakehouse_tables, str): lakehouse_tables = [lakehouse_tables] + workspace = fabric.resolve_workspace_name(workspace) + if lakehouse_workspace is None: + lakehouse_workspace = workspace + if lakehouse is None: + lakehouse_id = fabric.get_lakehouse_id() + lakehouse_workspace_id = fabric.get_workspace_id() + lakehouse_workspace = fabric.resolve_workspace_name(lakehouse_workspace_id) + lakehouse = resolve_lakehouse_name(lakehouse_id, lakehouse_workspace) + dfLT = get_lakehouse_tables(lakehouse=lakehouse, workspace=lakehouse_workspace) # Validate lakehouse tables From 71bc00d0cd8e7251a0eb72245145217c65fc4543 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 29 Sep 2024 19:56:49 +0200 Subject: [PATCH 2/3] updates --- src/sempy_labs/directlake/_dl_helper.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/sempy_labs/directlake/_dl_helper.py b/src/sempy_labs/directlake/_dl_helper.py index ae5e1fa5..b28d366c 100644 --- a/src/sempy_labs/directlake/_dl_helper.py +++ b/src/sempy_labs/directlake/_dl_helper.py @@ -5,7 +5,14 @@ from uuid import UUID import sempy_labs._icons as icons from sempy._utils._log import log -from sempy_labs._helper_functions import retry, resolve_dataset_id +from sempy_labs._helper_functions import ( + retry, + resolve_dataset_id, + resolve_lakehouse_name, +) +from sempy_labs.tom import connect_semantic_model +from sempy_labs._generate_semantic_model import create_blank_semantic_model +from sempy_labs._refresh_semantic_model import refresh_semantic_model def check_fallback_reason( @@ -31,13 +38,11 @@ def check_fallback_reason( workspace = fabric.resolve_workspace_name(workspace) - dfP = fabric.list_partitions(dataset=dataset, workspace=workspace) - dfP_filt = dfP[dfP["Mode"] == "DirectLake"] - - if len(dfP_filt) == 0: - raise ValueError( - f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake. This function is only applicable to Direct Lake semantic models." - ) + with connect_semantic_model(dataset=dataset, workspace=workspace, readonly=True) as tom: + if not tom.is_direct_lake(): + raise ValueError( + f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake. This function is only applicable to Direct Lake semantic models." + ) df = fabric.evaluate_dax( dataset=dataset, @@ -103,10 +108,7 @@ def generate_direct_lake_semantic_model( """ from sempy_labs.lakehouse import get_lakehouse_tables, get_lakehouse_columns - from sempy_labs import create_blank_semantic_model, refresh_semantic_model - from sempy_labs.tom import connect_semantic_model from sempy_labs.directlake import get_shared_expression - from sempy_labs._helper_functions import resolve_lakehouse_name if isinstance(lakehouse_tables, str): lakehouse_tables = [lakehouse_tables] @@ -219,6 +221,7 @@ def get_direct_lake_source( response = client.post( "metadata/relations/upstream?apiVersion=3", json=request_body ) + artifacts = response.json().get("artifacts", []) sql_id, sql_object_name, sql_workspace_id, artifact_type = None, None, None, None From 9788440b624596720a6f74a5a24ceaac6e4adfb1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 29 Sep 2024 22:04:34 +0200 Subject: [PATCH 3/3] fixed issue --- src/sempy_labs/directlake/_dl_helper.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sempy_labs/directlake/_dl_helper.py b/src/sempy_labs/directlake/_dl_helper.py index b28d366c..bcc49822 100644 --- a/src/sempy_labs/directlake/_dl_helper.py +++ b/src/sempy_labs/directlake/_dl_helper.py @@ -10,9 +10,6 @@ resolve_dataset_id, resolve_lakehouse_name, ) -from sempy_labs.tom import connect_semantic_model -from sempy_labs._generate_semantic_model import create_blank_semantic_model -from sempy_labs._refresh_semantic_model import refresh_semantic_model def check_fallback_reason( @@ -35,10 +32,13 @@ def check_fallback_reason( pandas.DataFrame The tables in the semantic model and their fallback reason. """ + from sempy_labs.tom import connect_semantic_model workspace = fabric.resolve_workspace_name(workspace) - with connect_semantic_model(dataset=dataset, workspace=workspace, readonly=True) as tom: + with connect_semantic_model( + dataset=dataset, workspace=workspace, readonly=True + ) as tom: if not tom.is_direct_lake(): raise ValueError( f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake. This function is only applicable to Direct Lake semantic models." @@ -109,6 +109,9 @@ def generate_direct_lake_semantic_model( from sempy_labs.lakehouse import get_lakehouse_tables, get_lakehouse_columns from sempy_labs.directlake import get_shared_expression + from sempy_labs.tom import connect_semantic_model + from sempy_labs._generate_semantic_model import create_blank_semantic_model + from sempy_labs._refresh_semantic_model import refresh_semantic_model if isinstance(lakehouse_tables, str): lakehouse_tables = [lakehouse_tables]