semantic-link-labs 0.5.0__py3-none-any.whl → 0.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of semantic-link-labs might be problematic. Click here for more details.
- {semantic_link_labs-0.5.0.dist-info → semantic_link_labs-0.6.0.dist-info}/METADATA +2 -2
- semantic_link_labs-0.6.0.dist-info/RECORD +54 -0
- {semantic_link_labs-0.5.0.dist-info → semantic_link_labs-0.6.0.dist-info}/WHEEL +1 -1
- sempy_labs/__init__.py +19 -13
- sempy_labs/_ai.py +43 -24
- sempy_labs/_clear_cache.py +4 -5
- sempy_labs/_connections.py +77 -70
- sempy_labs/_dax.py +7 -9
- sempy_labs/_generate_semantic_model.py +55 -44
- sempy_labs/_helper_functions.py +13 -6
- sempy_labs/_icons.py +14 -0
- sempy_labs/_list_functions.py +491 -304
- sempy_labs/_model_auto_build.py +4 -3
- sempy_labs/_model_bpa.py +131 -1118
- sempy_labs/_model_bpa_rules.py +831 -0
- sempy_labs/_model_dependencies.py +14 -12
- sempy_labs/_one_lake_integration.py +11 -5
- sempy_labs/_query_scale_out.py +89 -81
- sempy_labs/_refresh_semantic_model.py +16 -10
- sempy_labs/_translations.py +213 -287
- sempy_labs/_vertipaq.py +53 -37
- sempy_labs/directlake/__init__.py +2 -0
- sempy_labs/directlake/_directlake_schema_compare.py +12 -5
- sempy_labs/directlake/_directlake_schema_sync.py +13 -19
- sempy_labs/directlake/_fallback.py +5 -3
- sempy_labs/directlake/_get_directlake_lakehouse.py +1 -1
- sempy_labs/directlake/_get_shared_expression.py +4 -2
- sempy_labs/directlake/_guardrails.py +3 -3
- sempy_labs/directlake/_list_directlake_model_calc_tables.py +17 -10
- sempy_labs/directlake/_show_unsupported_directlake_objects.py +3 -2
- sempy_labs/directlake/_update_directlake_model_lakehouse_connection.py +10 -5
- sempy_labs/directlake/_update_directlake_partition_entity.py +132 -9
- sempy_labs/directlake/_warm_cache.py +6 -3
- sempy_labs/lakehouse/_get_lakehouse_columns.py +1 -1
- sempy_labs/lakehouse/_get_lakehouse_tables.py +5 -3
- sempy_labs/lakehouse/_lakehouse.py +2 -1
- sempy_labs/lakehouse/_shortcuts.py +19 -12
- sempy_labs/migration/__init__.py +1 -1
- sempy_labs/migration/_create_pqt_file.py +21 -15
- sempy_labs/migration/_migrate_calctables_to_lakehouse.py +16 -13
- sempy_labs/migration/_migrate_calctables_to_semantic_model.py +17 -18
- sempy_labs/migration/_migrate_model_objects_to_semantic_model.py +43 -40
- sempy_labs/migration/_migrate_tables_columns_to_semantic_model.py +14 -14
- sempy_labs/migration/_migration_validation.py +2 -2
- sempy_labs/migration/_refresh_calc_tables.py +8 -5
- sempy_labs/report/__init__.py +2 -2
- sempy_labs/report/_generate_report.py +10 -5
- sempy_labs/report/_report_functions.py +67 -29
- sempy_labs/report/_report_rebind.py +9 -8
- sempy_labs/tom/__init__.py +1 -4
- sempy_labs/tom/_model.py +555 -152
- semantic_link_labs-0.5.0.dist-info/RECORD +0 -53
- {semantic_link_labs-0.5.0.dist-info → semantic_link_labs-0.6.0.dist-info}/LICENSE +0 -0
- {semantic_link_labs-0.5.0.dist-info → semantic_link_labs-0.6.0.dist-info}/top_level.txt +0 -0
sempy_labs/_vertipaq.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
import pandas as pd
|
|
4
3
|
from IPython.display import display, HTML
|
|
5
|
-
import zipfile
|
|
4
|
+
import zipfile
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import datetime
|
|
8
|
+
import warnings
|
|
6
9
|
from pyspark.sql import SparkSession
|
|
7
10
|
from sempy_labs._helper_functions import (
|
|
8
11
|
format_dax_object_name,
|
|
@@ -12,10 +15,11 @@ from sempy_labs._helper_functions import (
|
|
|
12
15
|
from sempy_labs._list_functions import list_relationships
|
|
13
16
|
from sempy_labs.lakehouse._get_lakehouse_tables import get_lakehouse_tables
|
|
14
17
|
from sempy_labs.lakehouse._lakehouse import lakehouse_attached
|
|
15
|
-
from typing import
|
|
18
|
+
from typing import Optional
|
|
16
19
|
from sempy._utils._log import log
|
|
17
20
|
import sempy_labs._icons as icons
|
|
18
21
|
|
|
22
|
+
|
|
19
23
|
@log
|
|
20
24
|
def vertipaq_analyzer(
|
|
21
25
|
dataset: str,
|
|
@@ -51,6 +55,8 @@ def vertipaq_analyzer(
|
|
|
51
55
|
|
|
52
56
|
"""
|
|
53
57
|
|
|
58
|
+
from sempy_labs.tom import connect_semantic_model
|
|
59
|
+
|
|
54
60
|
pd.options.mode.copy_on_write = True
|
|
55
61
|
warnings.filterwarnings(
|
|
56
62
|
"ignore", message="createDataFrame attempted Arrow optimization*"
|
|
@@ -71,18 +77,21 @@ def vertipaq_analyzer(
|
|
|
71
77
|
dfR["From Object"] = format_dax_object_name(dfR["From Table"], dfR["From Column"])
|
|
72
78
|
dfR["To Object"] = format_dax_object_name(dfR["To Table"], dfR["To Column"])
|
|
73
79
|
dfP = fabric.list_partitions(dataset=dataset, extended=True, workspace=workspace)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
|
|
81
|
+
with connect_semantic_model(
|
|
82
|
+
dataset=dataset, readonly=True, workspace=workspace
|
|
83
|
+
) as tom:
|
|
84
|
+
compat_level = tom.model.Model.Database.CompatibilityLevel
|
|
85
|
+
is_direct_lake = tom.is_direct_lake()
|
|
86
|
+
def_mode = tom.model.DefaultMode
|
|
87
|
+
table_count = tom.model.Tables.Count
|
|
88
|
+
column_count = len(list(tom.all_columns()))
|
|
89
|
+
|
|
81
90
|
dfR["Missing Rows"] = None
|
|
82
91
|
|
|
83
92
|
# Direct Lake
|
|
84
93
|
if read_stats_from_data:
|
|
85
|
-
if
|
|
94
|
+
if is_direct_lake:
|
|
86
95
|
dfC = pd.merge(
|
|
87
96
|
dfC,
|
|
88
97
|
dfP[["Table Name", "Query", "Source Type"]],
|
|
@@ -100,7 +109,10 @@ def vertipaq_analyzer(
|
|
|
100
109
|
dfI_filt = dfI[(dfI["Id"] == sqlEndpointId)]
|
|
101
110
|
|
|
102
111
|
if len(dfI_filt) == 0:
|
|
103
|
-
raise ValueError(
|
|
112
|
+
raise ValueError(
|
|
113
|
+
f"{icons.red_dot} The lakehouse (SQL Endpoint) used by the '{dataset}' semantic model does not reside in the '{lakehouse_workspace}' workspace."
|
|
114
|
+
"Please update the lakehouse_workspace parameter."
|
|
115
|
+
)
|
|
104
116
|
else:
|
|
105
117
|
lakehouseName = dfI_filt["Display Name"].iloc[0]
|
|
106
118
|
|
|
@@ -238,7 +250,7 @@ def vertipaq_analyzer(
|
|
|
238
250
|
|
|
239
251
|
try:
|
|
240
252
|
missingRows = result.iloc[0, 0]
|
|
241
|
-
except:
|
|
253
|
+
except Exception:
|
|
242
254
|
pass
|
|
243
255
|
|
|
244
256
|
dfR.at[i, "Missing Rows"] = missingRows
|
|
@@ -308,7 +320,6 @@ def vertipaq_analyzer(
|
|
|
308
320
|
)
|
|
309
321
|
dfTable = pd.merge(dfTable, dfTP, on="Table Name", how="left")
|
|
310
322
|
dfTable = pd.merge(dfTable, dfTC, on="Table Name", how="left")
|
|
311
|
-
dfTable = dfTable.drop_duplicates() # Drop duplicates (temporary)
|
|
312
323
|
dfTable = dfTable.sort_values(by="Total Size", ascending=False)
|
|
313
324
|
dfTable.reset_index(drop=True, inplace=True)
|
|
314
325
|
export_Table = dfTable.copy()
|
|
@@ -318,7 +329,7 @@ def vertipaq_analyzer(
|
|
|
318
329
|
pctList = ["% DB"]
|
|
319
330
|
dfTable[pctList] = dfTable[pctList].applymap("{:.2f}%".format)
|
|
320
331
|
|
|
321
|
-
|
|
332
|
+
# Relationships
|
|
322
333
|
# dfR.drop(columns=['Max From Cardinality', 'Max To Cardinality'], inplace=True)
|
|
323
334
|
dfR = pd.merge(
|
|
324
335
|
dfR,
|
|
@@ -359,12 +370,17 @@ def vertipaq_analyzer(
|
|
|
359
370
|
intList.remove("Missing Rows")
|
|
360
371
|
dfR[intList] = dfR[intList].applymap("{:,}".format)
|
|
361
372
|
|
|
362
|
-
|
|
373
|
+
# Partitions
|
|
363
374
|
dfP = dfP[
|
|
364
|
-
[
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
375
|
+
[
|
|
376
|
+
"Table Name",
|
|
377
|
+
"Partition Name",
|
|
378
|
+
"Mode",
|
|
379
|
+
"Record Count",
|
|
380
|
+
"Segment Count",
|
|
381
|
+
# "Records per Segment",
|
|
382
|
+
]
|
|
383
|
+
].sort_values(by="Record Count", ascending=False)
|
|
368
384
|
dfP["Records per Segment"] = round(
|
|
369
385
|
dfP["Record Count"] / dfP["Segment Count"], 2
|
|
370
386
|
) # Remove after records per segment is fixed
|
|
@@ -373,7 +389,7 @@ def vertipaq_analyzer(
|
|
|
373
389
|
intList = ["Record Count", "Segment Count", "Records per Segment"]
|
|
374
390
|
dfP[intList] = dfP[intList].applymap("{:,}".format)
|
|
375
391
|
|
|
376
|
-
|
|
392
|
+
# Hierarchies
|
|
377
393
|
dfH_filt = dfH[dfH["Level Ordinal"] == 0]
|
|
378
394
|
dfH_filt = dfH_filt[["Table Name", "Hierarchy Name", "Used Size"]].sort_values(
|
|
379
395
|
by="Used Size", ascending=False
|
|
@@ -383,7 +399,7 @@ def vertipaq_analyzer(
|
|
|
383
399
|
intList = ["Used Size"]
|
|
384
400
|
dfH_filt[intList] = dfH_filt[intList].applymap("{:,}".format)
|
|
385
401
|
|
|
386
|
-
|
|
402
|
+
# Model
|
|
387
403
|
if total_size >= 1000000000:
|
|
388
404
|
y = total_size / (1024**3) * 1000000000
|
|
389
405
|
elif total_size >= 1000000:
|
|
@@ -392,19 +408,14 @@ def vertipaq_analyzer(
|
|
|
392
408
|
y = total_size / (1024) * 1000
|
|
393
409
|
y = round(y)
|
|
394
410
|
|
|
395
|
-
tblCount = len(dfT)
|
|
396
|
-
colCount = len(dfC_filt)
|
|
397
|
-
compatLevel = dfD["Compatibility Level"].iloc[0]
|
|
398
|
-
defMode = dfD["Model Default Mode"].iloc[0]
|
|
399
|
-
|
|
400
411
|
dfModel = pd.DataFrame(
|
|
401
412
|
{
|
|
402
413
|
"Dataset Name": dataset,
|
|
403
414
|
"Total Size": y,
|
|
404
|
-
"Table Count":
|
|
405
|
-
"Column Count":
|
|
406
|
-
"Compatibility Level":
|
|
407
|
-
"Default Mode":
|
|
415
|
+
"Table Count": table_count,
|
|
416
|
+
"Column Count": column_count,
|
|
417
|
+
"Compatibility Level": compat_level,
|
|
418
|
+
"Default Mode": def_mode,
|
|
408
419
|
},
|
|
409
420
|
index=[0],
|
|
410
421
|
)
|
|
@@ -429,11 +440,13 @@ def vertipaq_analyzer(
|
|
|
429
440
|
|
|
430
441
|
visualize_vertipaq(dfs)
|
|
431
442
|
|
|
432
|
-
|
|
443
|
+
# Export vertipaq to delta tables in lakehouse
|
|
433
444
|
if export in ["table", "zip"]:
|
|
434
445
|
lakeAttach = lakehouse_attached()
|
|
435
446
|
if lakeAttach is False:
|
|
436
|
-
raise ValueError(
|
|
447
|
+
raise ValueError(
|
|
448
|
+
f"{icons.red_dot} In order to save the Vertipaq Analyzer results, a lakehouse must be attached to the notebook. Please attach a lakehouse to this notebook."
|
|
449
|
+
)
|
|
437
450
|
|
|
438
451
|
if export == "table":
|
|
439
452
|
spark = SparkSession.builder.getOrCreate()
|
|
@@ -465,7 +478,9 @@ def vertipaq_analyzer(
|
|
|
465
478
|
"export_Model": ["Model", export_Model],
|
|
466
479
|
}
|
|
467
480
|
|
|
468
|
-
print(
|
|
481
|
+
print(
|
|
482
|
+
f"{icons.in_progress} Saving Vertipaq Analyzer to delta tables in the lakehouse...\n"
|
|
483
|
+
)
|
|
469
484
|
now = datetime.datetime.now()
|
|
470
485
|
for key, (obj, df) in dfMap.items():
|
|
471
486
|
df["Timestamp"] = now
|
|
@@ -487,7 +502,7 @@ def vertipaq_analyzer(
|
|
|
487
502
|
f"{icons.bullet} Vertipaq Analyzer results for '{obj}' have been appended to the '{delta_table_name}' delta table."
|
|
488
503
|
)
|
|
489
504
|
|
|
490
|
-
|
|
505
|
+
# Export vertipaq to zip file within the lakehouse
|
|
491
506
|
if export == "zip":
|
|
492
507
|
dataFrames = {
|
|
493
508
|
"dfModel": dfModel,
|
|
@@ -525,7 +540,8 @@ def vertipaq_analyzer(
|
|
|
525
540
|
if os.path.exists(filePath):
|
|
526
541
|
os.remove(filePath)
|
|
527
542
|
print(
|
|
528
|
-
f"{icons.green_dot} The Vertipaq Analyzer info for the '{dataset}' semantic model in the '{workspace}' workspace has been saved
|
|
543
|
+
f"{icons.green_dot} The Vertipaq Analyzer info for the '{dataset}' semantic model in the '{workspace}' workspace has been saved "
|
|
544
|
+
f"to the 'Vertipaq Analyzer/{zipFileName}' in the default lakehouse attached to this notebook."
|
|
529
545
|
)
|
|
530
546
|
|
|
531
547
|
|
|
@@ -832,7 +848,7 @@ def visualize_vertipaq(dataframes):
|
|
|
832
848
|
(tooltipDF["ViewName"] == vw) & (tooltipDF["ColumnName"] == col)
|
|
833
849
|
]
|
|
834
850
|
tt = tooltipDF_filt["Tooltip"].iloc[0]
|
|
835
|
-
except:
|
|
851
|
+
except Exception:
|
|
836
852
|
pass
|
|
837
853
|
df_html = df_html.replace(f"<th>{col}</th>", f'<th title="{tt}">{col}</th>')
|
|
838
854
|
content_html += (
|
|
@@ -21,6 +21,7 @@ from sempy_labs.directlake._update_directlake_model_lakehouse_connection import
|
|
|
21
21
|
)
|
|
22
22
|
from sempy_labs.directlake._update_directlake_partition_entity import (
|
|
23
23
|
update_direct_lake_partition_entity,
|
|
24
|
+
add_table_to_direct_lake_semantic_model,
|
|
24
25
|
)
|
|
25
26
|
from sempy_labs.directlake._warm_cache import (
|
|
26
27
|
warm_direct_lake_cache_isresident,
|
|
@@ -42,4 +43,5 @@ __all__ = [
|
|
|
42
43
|
"update_direct_lake_partition_entity",
|
|
43
44
|
"warm_direct_lake_cache_isresident",
|
|
44
45
|
"warm_direct_lake_cache_perspective",
|
|
46
|
+
"add_table_to_direct_lake_semantic_model",
|
|
45
47
|
]
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
import pandas as pd
|
|
4
3
|
from sempy_labs._helper_functions import (
|
|
@@ -13,6 +12,7 @@ from typing import Optional
|
|
|
13
12
|
import sempy_labs._icons as icons
|
|
14
13
|
from sempy._utils._log import log
|
|
15
14
|
|
|
15
|
+
|
|
16
16
|
@log
|
|
17
17
|
def direct_lake_schema_compare(
|
|
18
18
|
dataset: str,
|
|
@@ -55,10 +55,15 @@ def direct_lake_schema_compare(
|
|
|
55
55
|
dfI_filt = dfI[(dfI["Id"] == sqlEndpointId)]
|
|
56
56
|
|
|
57
57
|
if len(dfI_filt) == 0:
|
|
58
|
-
raise ValueError(
|
|
58
|
+
raise ValueError(
|
|
59
|
+
f"{icons.red_dot} The SQL Endpoint in the '{dataset}' semantic model in the '{workspace} workspace does not point to the "
|
|
60
|
+
f"'{lakehouse}' lakehouse in the '{lakehouse_workspace}' workspace as specified."
|
|
61
|
+
)
|
|
59
62
|
|
|
60
63
|
if not any(r["Mode"] == "DirectLake" for i, r in dfP.iterrows()):
|
|
61
|
-
raise ValueError(
|
|
64
|
+
raise ValueError(
|
|
65
|
+
f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake mode."
|
|
66
|
+
)
|
|
62
67
|
|
|
63
68
|
dfT = list_tables(dataset, workspace)
|
|
64
69
|
dfC = fabric.list_columns(dataset=dataset, workspace=workspace)
|
|
@@ -92,7 +97,8 @@ def direct_lake_schema_compare(
|
|
|
92
97
|
)
|
|
93
98
|
else:
|
|
94
99
|
print(
|
|
95
|
-
f"{icons.yellow_dot} The following tables exist in the '{dataset}' semantic model within the '{workspace}' workspace
|
|
100
|
+
f"{icons.yellow_dot} The following tables exist in the '{dataset}' semantic model within the '{workspace}' workspace"
|
|
101
|
+
f" but do not exist in the '{lakehouse}' lakehouse within the '{lakehouse_workspace}' workspace."
|
|
96
102
|
)
|
|
97
103
|
display(missingtbls)
|
|
98
104
|
if len(missingcols) == 0:
|
|
@@ -101,6 +107,7 @@ def direct_lake_schema_compare(
|
|
|
101
107
|
)
|
|
102
108
|
else:
|
|
103
109
|
print(
|
|
104
|
-
f"{icons.yellow_dot} The following columns exist in the '{dataset}' semantic model within the '{workspace}' workspace
|
|
110
|
+
f"{icons.yellow_dot} The following columns exist in the '{dataset}' semantic model within the '{workspace}' workspace "
|
|
111
|
+
f"but do not exist in the '{lakehouse}' lakehouse within the '{lakehouse_workspace}' workspace."
|
|
105
112
|
)
|
|
106
113
|
display(missingcols)
|
|
@@ -12,6 +12,7 @@ from typing import Optional
|
|
|
12
12
|
from sempy._utils._log import log
|
|
13
13
|
import sempy_labs._icons as icons
|
|
14
14
|
|
|
15
|
+
|
|
15
16
|
@log
|
|
16
17
|
def direct_lake_schema_sync(
|
|
17
18
|
dataset: str,
|
|
@@ -61,7 +62,10 @@ def direct_lake_schema_sync(
|
|
|
61
62
|
dfI_filt = dfI[(dfI["Id"] == sqlEndpointId)]
|
|
62
63
|
|
|
63
64
|
if len(dfI_filt) == 0:
|
|
64
|
-
raise ValueError(
|
|
65
|
+
raise ValueError(
|
|
66
|
+
f"{icons.red_dot} The SQL Endpoint in the '{dataset}' semantic model in the '{workspace} workspace does not point to the "
|
|
67
|
+
f"'{lakehouse}' lakehouse in the '{lakehouse_workspace}' workspace as specified."
|
|
68
|
+
)
|
|
65
69
|
|
|
66
70
|
dfP = fabric.list_partitions(dataset=dataset, workspace=workspace)
|
|
67
71
|
dfP_filt = dfP[dfP["Source Type"] == "Entity"]
|
|
@@ -77,21 +81,9 @@ def direct_lake_schema_sync(
|
|
|
77
81
|
lc = get_lakehouse_columns(lakehouse, lakehouse_workspace)
|
|
78
82
|
lc_filt = lc[lc["Table Name"].isin(dfP_filt["Query"].values)]
|
|
79
83
|
|
|
80
|
-
mapping = {
|
|
81
|
-
"string": "String",
|
|
82
|
-
"bigint": "Int64",
|
|
83
|
-
"int": "Int64",
|
|
84
|
-
"smallint": "Int64",
|
|
85
|
-
"boolean": "Boolean",
|
|
86
|
-
"timestamp": "DateTime",
|
|
87
|
-
"date": "DateTime",
|
|
88
|
-
"decimal(38,18)": "Decimal",
|
|
89
|
-
"double": "Double",
|
|
90
|
-
}
|
|
91
|
-
|
|
92
84
|
with connect_semantic_model(
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
dataset=dataset, readonly=False, workspace=workspace
|
|
86
|
+
) as tom:
|
|
95
87
|
|
|
96
88
|
for i, r in lc_filt.iterrows():
|
|
97
89
|
lakeTName = r["Table Name"]
|
|
@@ -106,18 +98,20 @@ def direct_lake_schema_sync(
|
|
|
106
98
|
col = TOM.DataColumn()
|
|
107
99
|
col.Name = lakeCName
|
|
108
100
|
col.SourceColumn = lakeCName
|
|
109
|
-
dt =
|
|
101
|
+
dt = icons.data_type_mapping.get(dType)
|
|
110
102
|
try:
|
|
111
103
|
col.DataType = System.Enum.Parse(TOM.DataType, dt)
|
|
112
104
|
except Exception as e:
|
|
113
|
-
raise ValueError(
|
|
105
|
+
raise ValueError(
|
|
106
|
+
f"{icons.red_dot} Failed to map '{dType}' data type to the semantic model data types."
|
|
107
|
+
) from e
|
|
114
108
|
|
|
115
109
|
tom.model.Tables[tName].Columns.Add(col)
|
|
116
110
|
print(
|
|
117
|
-
f"{icons.green_dot} The '{lakeCName}' column has been added to the '{tName}' table as a '{dt}'
|
|
111
|
+
f"{icons.green_dot} The '{lakeCName}' column has been added to the '{tName}' table as a '{dt}' "
|
|
112
|
+
f"data type within the '{dataset}' semantic model within the '{workspace}' workspace."
|
|
118
113
|
)
|
|
119
114
|
else:
|
|
120
115
|
print(
|
|
121
116
|
f"{icons.yellow_dot} The {fullColName} column exists in the lakehouse but not in the '{tName}' table in the '{dataset}' semantic model within the '{workspace}' workspace."
|
|
122
117
|
)
|
|
123
|
-
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
import numpy as np
|
|
4
|
-
from typing import
|
|
3
|
+
from typing import Optional
|
|
5
4
|
import sempy_labs._icons as icons
|
|
6
5
|
|
|
6
|
+
|
|
7
7
|
def check_fallback_reason(dataset: str, workspace: Optional[str] = None):
|
|
8
8
|
"""
|
|
9
9
|
Shows the reason a table in a Direct Lake semantic model would fallback to DirectQuery.
|
|
@@ -29,7 +29,9 @@ def check_fallback_reason(dataset: str, workspace: Optional[str] = None):
|
|
|
29
29
|
dfP_filt = dfP[dfP["Mode"] == "DirectLake"]
|
|
30
30
|
|
|
31
31
|
if len(dfP_filt) == 0:
|
|
32
|
-
raise ValueError(
|
|
32
|
+
raise ValueError(
|
|
33
|
+
f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake. This function is only applicable to Direct Lake semantic models."
|
|
34
|
+
)
|
|
33
35
|
else:
|
|
34
36
|
df = fabric.evaluate_dax(
|
|
35
37
|
dataset=dataset,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
from sempy_labs._helper_functions import (
|
|
4
3
|
resolve_lakehouse_id,
|
|
@@ -9,6 +8,7 @@ from typing import Optional, Tuple
|
|
|
9
8
|
from uuid import UUID
|
|
10
9
|
import sempy_labs._icons as icons
|
|
11
10
|
|
|
11
|
+
|
|
12
12
|
def get_direct_lake_lakehouse(
|
|
13
13
|
dataset: str,
|
|
14
14
|
workspace: Optional[str] = None,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
from sempy_labs._helper_functions import resolve_lakehouse_name
|
|
4
3
|
from sempy_labs._list_functions import list_lakehouses
|
|
5
4
|
from typing import Optional
|
|
6
5
|
import sempy_labs._icons as icons
|
|
7
6
|
|
|
7
|
+
|
|
8
8
|
def get_shared_expression(
|
|
9
9
|
lakehouse: Optional[str] = None, workspace: Optional[str] = None
|
|
10
10
|
):
|
|
@@ -40,7 +40,9 @@ def get_shared_expression(
|
|
|
40
40
|
provStatus = lakeDetail["SQL Endpoint Provisioning Status"].iloc[0]
|
|
41
41
|
|
|
42
42
|
if provStatus == "InProgress":
|
|
43
|
-
raise ValueError(
|
|
43
|
+
raise ValueError(
|
|
44
|
+
f"{icons.red_dot} The SQL Endpoint for the '{lakehouse}' lakehouse within the '{workspace}' workspace has not yet been provisioned. Please wait until it has been provisioned."
|
|
45
|
+
)
|
|
44
46
|
|
|
45
47
|
sh = (
|
|
46
48
|
'let\n\tdatabase = Sql.Database("'
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
import pandas as pd
|
|
4
|
-
from typing import
|
|
3
|
+
from typing import Optional
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
def get_direct_lake_guardrails() -> pd.DataFrame:
|
|
8
7
|
"""
|
|
9
|
-
Shows the guardrails for when Direct Lake semantic models will fallback to Direct Query
|
|
8
|
+
Shows the guardrails for when Direct Lake semantic models will fallback to Direct Query
|
|
9
|
+
based on Microsoft's `online documentation <https://learn.microsoft.com/power-bi/enterprise/directlake-overview>`_.
|
|
10
10
|
|
|
11
11
|
Parameters
|
|
12
12
|
----------
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
import pandas as pd
|
|
4
|
-
from sempy_labs._list_functions import list_tables
|
|
3
|
+
from sempy_labs._list_functions import list_tables
|
|
5
4
|
from sempy_labs.tom import connect_semantic_model
|
|
6
5
|
from typing import Optional
|
|
7
6
|
from sempy._utils._log import log
|
|
8
7
|
import sempy_labs._icons as icons
|
|
9
8
|
|
|
9
|
+
|
|
10
10
|
@log
|
|
11
|
-
def list_direct_lake_model_calc_tables(
|
|
11
|
+
def list_direct_lake_model_calc_tables(
|
|
12
|
+
dataset: str, workspace: Optional[str] = None
|
|
13
|
+
) -> pd.DataFrame:
|
|
12
14
|
"""
|
|
13
15
|
Shows the calculated tables and their respective DAX expression for a Direct Lake model (which has been migrated from import/DirectQuery).
|
|
14
16
|
|
|
@@ -32,18 +34,21 @@ def list_direct_lake_model_calc_tables(dataset: str, workspace: Optional[str] =
|
|
|
32
34
|
df = pd.DataFrame(columns=["Table Name", "Source Expression"])
|
|
33
35
|
|
|
34
36
|
with connect_semantic_model(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
dataset=dataset, readonly=True, workspace=workspace
|
|
38
|
+
) as tom:
|
|
39
|
+
|
|
38
40
|
is_direct_lake = tom.is_direct_lake()
|
|
39
41
|
|
|
40
42
|
if not is_direct_lake:
|
|
41
|
-
raise ValueError(
|
|
43
|
+
raise ValueError(
|
|
44
|
+
f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake mode."
|
|
45
|
+
)
|
|
42
46
|
else:
|
|
43
|
-
dfA = list_annotations(dataset, workspace)
|
|
47
|
+
dfA = fabric.list_annotations(dataset=dataset, workspace=workspace)
|
|
44
48
|
dfT = list_tables(dataset, workspace)
|
|
45
49
|
dfA_filt = dfA[
|
|
46
|
-
(dfA["Object Type"] == "Model")
|
|
50
|
+
(dfA["Object Type"] == "Model")
|
|
51
|
+
& (dfA["Annotation Name"].isin(dfT["Name"]))
|
|
47
52
|
]
|
|
48
53
|
|
|
49
54
|
for i, r in dfA_filt.iterrows():
|
|
@@ -51,6 +56,8 @@ def list_direct_lake_model_calc_tables(dataset: str, workspace: Optional[str] =
|
|
|
51
56
|
se = r["Annotation Value"]
|
|
52
57
|
|
|
53
58
|
new_data = {"Table Name": tName, "Source Expression": se}
|
|
54
|
-
df = pd.concat(
|
|
59
|
+
df = pd.concat(
|
|
60
|
+
[df, pd.DataFrame(new_data, index=[0])], ignore_index=True
|
|
61
|
+
)
|
|
55
62
|
|
|
56
63
|
return df
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
import pandas as pd
|
|
4
3
|
from sempy_labs._list_functions import list_tables
|
|
@@ -6,12 +5,14 @@ from sempy_labs._helper_functions import format_dax_object_name
|
|
|
6
5
|
from typing import Optional, Tuple
|
|
7
6
|
from sempy._utils._log import log
|
|
8
7
|
|
|
8
|
+
|
|
9
9
|
@log
|
|
10
10
|
def show_unsupported_direct_lake_objects(
|
|
11
11
|
dataset: str, workspace: Optional[str] = None
|
|
12
12
|
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
|
|
13
13
|
"""
|
|
14
|
-
Returns a list of a semantic model's objects which are not supported by Direct Lake based on
|
|
14
|
+
Returns a list of a semantic model's objects which are not supported by Direct Lake based on
|
|
15
|
+
`official documentation <https://learn.microsoft.com/power-bi/enterprise/directlake-overview#known-issues-and-limitations>`_.
|
|
15
16
|
|
|
16
17
|
Parameters
|
|
17
18
|
----------
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import sempy
|
|
2
1
|
import sempy.fabric as fabric
|
|
3
2
|
from sempy_labs.directlake._get_shared_expression import get_shared_expression
|
|
4
3
|
from sempy_labs._helper_functions import (
|
|
5
4
|
resolve_lakehouse_name,
|
|
6
|
-
resolve_workspace_name_and_id,
|
|
7
5
|
)
|
|
8
6
|
from sempy_labs.tom import connect_semantic_model
|
|
9
7
|
from typing import Optional
|
|
@@ -54,13 +52,18 @@ def update_direct_lake_model_lakehouse_connection(
|
|
|
54
52
|
dfI_filt = dfI[(dfI["Display Name"] == lakehouse)]
|
|
55
53
|
|
|
56
54
|
if len(dfI_filt) == 0:
|
|
57
|
-
raise ValueError(
|
|
55
|
+
raise ValueError(
|
|
56
|
+
f"{icons.red_dot} The '{lakehouse}' lakehouse does not exist within the '{lakehouse_workspace}' workspace. "
|
|
57
|
+
f"Therefore it cannot be used to support the '{dataset}' semantic model within the '{workspace}' workspace."
|
|
58
|
+
)
|
|
58
59
|
|
|
59
60
|
dfP = fabric.list_partitions(dataset=dataset, workspace=workspace)
|
|
60
61
|
dfP_filt = dfP[dfP["Mode"] == "DirectLake"]
|
|
61
62
|
|
|
62
63
|
if len(dfP_filt) == 0:
|
|
63
|
-
raise ValueError(
|
|
64
|
+
raise ValueError(
|
|
65
|
+
f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake. This function is only applicable to Direct Lake semantic models."
|
|
66
|
+
)
|
|
64
67
|
else:
|
|
65
68
|
with connect_semantic_model(
|
|
66
69
|
dataset=dataset, readonly=False, workspace=workspace
|
|
@@ -73,4 +76,6 @@ def update_direct_lake_model_lakehouse_connection(
|
|
|
73
76
|
f"{icons.green_dot} The expression in the '{dataset}' semantic model has been updated to point to the '{lakehouse}' lakehouse in the '{lakehouse_workspace}' workspace."
|
|
74
77
|
)
|
|
75
78
|
except Exception as e:
|
|
76
|
-
raise ValueError(
|
|
79
|
+
raise ValueError(
|
|
80
|
+
f"{icons.red_dot} The expression in the '{dataset}' semantic model was not updated."
|
|
81
|
+
) from e
|