semantic-link-labs 0.4.2__tar.gz → 0.5.0__tar.gz
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/.github/ISSUE_TEMPLATE/bug_report.md +32 -0
- semantic_link_labs-0.5.0/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- semantic_link_labs-0.5.0/.github/ISSUE_TEMPLATE/issue--question---advice-needed.md +14 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/PKG-INFO +1 -1
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/README.md +6 -5
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/docs/source/conf.py +1 -1
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/notebooks/Migration to Direct Lake.ipynb +1 -1
- semantic_link_labs-0.5.0/notebooks/Tabular Object Model.ipynb +1 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/pyproject.toml +1 -1
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/semantic_link_labs.egg-info/PKG-INFO +1 -1
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/semantic_link_labs.egg-info/SOURCES.txt +3 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/__init__.py +27 -3
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_ai.py +12 -32
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_clear_cache.py +1 -3
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_connections.py +39 -38
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_generate_semantic_model.py +9 -14
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_helper_functions.py +3 -12
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_icons.py +1 -0
- semantic_link_labs-0.5.0/src/sempy_labs/_list_functions.py +2152 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_model_auto_build.py +2 -4
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_model_bpa.py +26 -30
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_model_dependencies.py +7 -13
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_one_lake_integration.py +2 -5
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_query_scale_out.py +12 -30
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_refresh_semantic_model.py +5 -15
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_translations.py +1 -1
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_vertipaq.py +3 -10
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_directlake_schema_compare.py +3 -9
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_directlake_schema_sync.py +2 -6
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_fallback.py +2 -6
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_get_shared_expression.py +3 -9
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_guardrails.py +3 -5
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_list_directlake_model_calc_tables.py +3 -4
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_show_unsupported_directlake_objects.py +1 -2
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_update_directlake_model_lakehouse_connection.py +3 -7
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_update_directlake_partition_entity.py +2 -8
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_warm_cache.py +5 -8
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/lakehouse/_get_lakehouse_columns.py +1 -1
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/lakehouse/_get_lakehouse_tables.py +3 -5
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/lakehouse/_lakehouse.py +1 -3
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/lakehouse/_shortcuts.py +2 -5
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/migration/_create_pqt_file.py +4 -13
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/migration/_migrate_model_objects_to_semantic_model.py +2 -6
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/migration/_migration_validation.py +4 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/migration/_refresh_calc_tables.py +2 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/report/_generate_report.py +2 -6
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/report/_report_functions.py +30 -73
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/report/_report_rebind.py +39 -39
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/tom/_model.py +141 -183
- semantic_link_labs-0.4.2/notebooks/Tabular Object Model.ipynb +0 -1
- semantic_link_labs-0.4.2/src/sempy_labs/_list_functions.py +0 -1628
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/.github/workflows/build.yaml +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/.github/workflows/codeql.yaml +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/.gitignore +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/.readthedocs.yaml +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/.vscode/settings.json +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/CODE_OF_CONDUCT.md +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/LICENSE +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/SECURITY.md +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/SUPPORT.md +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/docs/Makefile +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/docs/make.bat +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/docs/requirements.txt +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/docs/source/index.rst +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/docs/source/modules.rst +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/environment.yml +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/notebooks/Model Optimization.ipynb +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/notebooks/Query Scale Out.ipynb +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/setup.cfg +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/semantic_link_labs.egg-info/dependency_links.txt +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/semantic_link_labs.egg-info/requires.txt +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/semantic_link_labs.egg-info/top_level.txt +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/_dax.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/__init__.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/directlake/_get_directlake_lakehouse.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/lakehouse/__init__.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/migration/__init__.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/migration/_migrate_calctables_to_lakehouse.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/migration/_migrate_calctables_to_semantic_model.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/migration/_migrate_tables_columns_to_semantic_model.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/report/__init__.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/sempy_labs/tom/__init__.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/tests/__init__.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/tests/test_shortcuts.py +0 -0
- {semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/tests/test_tom.py +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: ''
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Describe the bug**
|
|
11
|
+
A clear and concise description of what the bug is.
|
|
12
|
+
|
|
13
|
+
**To Reproduce**
|
|
14
|
+
Steps to reproduce the behavior:
|
|
15
|
+
1. Go to '...'
|
|
16
|
+
2. Click on '....'
|
|
17
|
+
3. Scroll down to '....'
|
|
18
|
+
4. See error
|
|
19
|
+
|
|
20
|
+
**Expected behavior**
|
|
21
|
+
A clear and concise description of what you expected to happen.
|
|
22
|
+
|
|
23
|
+
**Screenshots**
|
|
24
|
+
If applicable, add screenshots to help explain your problem.
|
|
25
|
+
|
|
26
|
+
**Desktop (please complete the following information):**
|
|
27
|
+
- OS: [e.g. iOS]
|
|
28
|
+
- Browser [e.g. chrome, safari]
|
|
29
|
+
- Version [e.g. 22]
|
|
30
|
+
|
|
31
|
+
**Additional context**
|
|
32
|
+
Add any other context about the problem here.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest an idea for this project
|
|
4
|
+
title: ''
|
|
5
|
+
labels: enhancement
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
12
|
+
|
|
13
|
+
**Describe the solution you'd like**
|
|
14
|
+
A clear and concise description of what you want to happen.
|
|
15
|
+
|
|
16
|
+
**Describe alternatives you've considered**
|
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
|
18
|
+
|
|
19
|
+
**Additional context**
|
|
20
|
+
Add any other context or screenshots about the feature request here.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: 'Issue: Question / Advice needed'
|
|
3
|
+
about: Ask a question about this project
|
|
4
|
+
title: ''
|
|
5
|
+
labels: question
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**What are you trying to achieve?**
|
|
11
|
+
Provide a brief background description of the problem you're trying to solve. Include information about the semantic engine you're working on (Power BI Desktop, Azure Analysis Services, etc.), as not everything is possible across engines.
|
|
12
|
+
|
|
13
|
+
**What have you tried so far?**
|
|
14
|
+
If applicable, describe the steps you have tried so far. For scripting-related questions, show the code that you have written.
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
# semantic-link-labs
|
|
1
|
+
# [semantic-link-labs](https://semantic-link-labs.readthedocs.io/en/0.5.0/)
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/py/semantic-link-labs)
|
|
4
|
-
[](https://readthedocs.org/projects/semantic-link-labs/)
|
|
5
5
|
[](https://github.com/psf/black)
|
|
6
6
|
[](https://pepy.tech/project/semantic-link-labs)
|
|
7
7
|
|
|
8
|
+
All functions in this library are documented [here](https://semantic-link-labs.readthedocs.io/en/0.5.0/)!
|
|
8
9
|
|
|
9
|
-
This is a python library intended to be used in [Microsoft Fabric notebooks](https://learn.microsoft.com/fabric/data-engineering/how-to-use-notebook). This library was originally intended to contain functions used for [migrating semantic models to Direct Lake mode](https://github.com/microsoft/semantic-link-labs?tab=readme-ov-file#direct-lake-migration
|
|
10
|
+
This is a python library intended to be used in [Microsoft Fabric notebooks](https://learn.microsoft.com/fabric/data-engineering/how-to-use-notebook). This library was originally intended to contain functions used for [migrating semantic models to Direct Lake mode](https://github.com/microsoft/semantic-link-labs?tab=readme-ov-file#direct-lake-migration). However, it quickly became apparent that functions within such a library could support many other useful activities in the realm of semantic models, reports, lakehouses and really anything Fabric-related. As such, this library contains a variety of functions ranging from running [Vertipaq Analyzer](https://semantic-link-labs.readthedocs.io/en/0.5.0/sempy_labs.html#sempy_labs.import_vertipaq_analyzer) or the [Best Practice Analyzer](https://semantic-link-labs.readthedocs.io/en/0.5.0/sempy_labs.html#sempy_labs.run_model_bpa) against a semantic model to seeing if any [lakehouse tables hit Direct Lake guardrails](https://semantic-link-labs.readthedocs.io/en/0.5.0/sempy_labs.lakehouse.html#sempy_labs.lakehouse.get_lakehouse_tables) or accessing the [Tabular Object Model](https://semantic-link-labs.readthedocs.io/en/0.5.0/sempy_labs.tom.html) and more!
|
|
10
11
|
|
|
11
|
-
Instructions for migrating import/DirectQuery semantic models to Direct Lake mode can be found [here](https://github.com/microsoft/semantic-link-labs?tab=readme-ov-file#direct-lake-migration
|
|
12
|
+
Instructions for migrating import/DirectQuery semantic models to Direct Lake mode can be found [here](https://github.com/microsoft/semantic-link-labs?tab=readme-ov-file#direct-lake-migration).
|
|
12
13
|
|
|
13
14
|
If you encounter any issues, please [raise a bug](https://github.com/microsoft/semantic-link-labs/issues/new?assignees=&labels=&projects=&template=bug_report.md&title=).
|
|
14
15
|
|
|
15
16
|
If you have ideas for new features/functions, please [request a feature](https://github.com/microsoft/semantic-link-labs/issues/new?assignees=&labels=&projects=&template=feature_request.md&title=).
|
|
16
17
|
|
|
17
|
-
## [Function documentation](https://semantic-link-labs.readthedocs.io/en/0.
|
|
18
|
+
## [Function documentation](https://semantic-link-labs.readthedocs.io/en/0.5.0/)
|
|
18
19
|
|
|
19
20
|
## Install the library in a Fabric notebook
|
|
20
21
|
```python
|
|
@@ -13,7 +13,7 @@ sys.path.insert(0, os.path.abspath('../../src/'))
|
|
|
13
13
|
project = 'semantic-link-labs'
|
|
14
14
|
copyright = '2024, Microsoft and community'
|
|
15
15
|
author = 'Microsoft and community'
|
|
16
|
-
release = '0.
|
|
16
|
+
release = '0.5.0'
|
|
17
17
|
|
|
18
18
|
# -- General configuration ---------------------------------------------------
|
|
19
19
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
{semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/notebooks/Migration to Direct Lake.ipynb
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"cells":[{"cell_type":"markdown","id":"5c27dfd1-4fe0-4a97-92e6-ddf78889aa93","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Install the latest .whl package\n","\n","Check [here](https://pypi.org/project/semantic-link-labs/) to see the latest version."]},{"cell_type":"code","execution_count":null,"id":"d5cae9db-cef9-48a8-a351-9c5fcc99645c","metadata":{"jupyter":{"outputs_hidden":true,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["%pip install semantic-link-labs"]},{"cell_type":"markdown","id":"969a29bf","metadata":{},"source":["### Import the library and set initial parameters"]},{"cell_type":"code","execution_count":null,"id":"29c923f8","metadata":{},"outputs":[],"source":["import sempy_labs as labs\n","from sempy_labs import migration, report, directlake\n","\n","dataset_name = '' #Enter the import/DQ semantic model name\n","workspace_name = None #Enter the workspace of the import/DQ semantic model. It set to none it will use the current workspace.\n","new_dataset_name = '' #Enter the new Direct Lake semantic model name\n","new_dataset_workspace_name = None #Enter the workspace where the Direct Lake model will be created. If set to None it will use the current workspace.\n","lakehouse_name = None #Enter the lakehouse to be used for the Direct Lake model. If set to None it will use the lakehouse attached to the notebook.\n","lakehouse_workspace_name = None #Enter the lakehouse workspace. If set to None it will use the new_dataset_workspace_name."]},{"cell_type":"markdown","id":"5a3fe6e8-b8aa-4447-812b-7931831e07fe","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Create the [Power Query Template](https://learn.microsoft.com/power-query/power-query-template) file\n","\n","This encapsulates all of the semantic model's Power Query logic into a single file."]},{"cell_type":"code","execution_count":null,"id":"cde43b47-4ecc-46ae-9125-9674819c7eab","metadata":{"jupyter":{"outputs_hidden":false,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["migration.create_pqt_file(dataset = dataset_name, workspace = workspace_name)"]},{"cell_type":"markdown","id":"bf945d07-544c-4934-b7a6-cfdb90ca725e","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Import the Power Query Template to Dataflows Gen2\n","\n","- Open the [OneLake file explorer](https://www.microsoft.com/download/details.aspx?id=105222) and sync your files (right click -> Sync from OneLake)\n","\n","- Navigate to your lakehouse. From this window, create a new Dataflows Gen2 and import the Power Query Template file from OneLake (OneLake -> Workspace -> Lakehouse -> Files...), and publish the Dataflows Gen2.\n","\n","<div class=\"alert alert-block alert-info\">\n","<b>Important!:</b> Make sure to create the Dataflows Gen2 from within the lakehouse window. That will ensure that all the tables automatically map to that lakehouse as the destination. Otherwise, you will have to manually map each table to its destination individually.\n","</div>"]},{"cell_type":"markdown","id":"9975db7d","metadata":{},"source":["### Create the Direct Lake model based on the import/DQ semantic model\n","\n","Calculated columns are not migrated to the Direct Lake model as they are not supported in Direct Lake mode."]},{"cell_type":"code","execution_count":null,"id":"0a3616b5-566e-414e-a225-fb850d6418dc","metadata":{"jupyter":{"outputs_hidden":false,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["import time\n","labs.create_blank_semantic_model(dataset = new_dataset_name, workspace = new_dataset_workspace_name)\n","\n","time.sleep(2)\n","\n","migration.migrate_calc_tables_to_lakehouse(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name,\n"," lakehouse = lakehouse_name,\n"," lakehouse_workspace = lakehouse_workspace_name)\n","migration.migrate_tables_columns_to_semantic_model(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name,\n"," lakehouse = lakehouse_name,\n"," lakehouse_workspace = lakehouse_workspace_name)\n","migration.migrate_calc_tables_to_semantic_model(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name,\n"," lakehouse = lakehouse_name,\n"," lakehouse_workspace = lakehouse_workspace_name)\n","migration.migrate_model_objects_to_semantic_model(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name)\n","migration.migrate_field_parameters(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name)\n","time.sleep(2)\n","
|
|
1
|
+
{"cells":[{"cell_type":"markdown","id":"5c27dfd1-4fe0-4a97-92e6-ddf78889aa93","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Install the latest .whl package\n","\n","Check [here](https://pypi.org/project/semantic-link-labs/) to see the latest version."]},{"cell_type":"code","execution_count":null,"id":"d5cae9db-cef9-48a8-a351-9c5fcc99645c","metadata":{"jupyter":{"outputs_hidden":true,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["%pip install semantic-link-labs"]},{"cell_type":"markdown","id":"969a29bf","metadata":{},"source":["### Import the library and set initial parameters"]},{"cell_type":"code","execution_count":null,"id":"29c923f8","metadata":{},"outputs":[],"source":["import sempy_labs as labs\n","from sempy_labs import migration, report, directlake\n","\n","dataset_name = '' #Enter the import/DQ semantic model name\n","workspace_name = None #Enter the workspace of the import/DQ semantic model. It set to none it will use the current workspace.\n","new_dataset_name = '' #Enter the new Direct Lake semantic model name\n","new_dataset_workspace_name = None #Enter the workspace where the Direct Lake model will be created. If set to None it will use the current workspace.\n","lakehouse_name = None #Enter the lakehouse to be used for the Direct Lake model. If set to None it will use the lakehouse attached to the notebook.\n","lakehouse_workspace_name = None #Enter the lakehouse workspace. If set to None it will use the new_dataset_workspace_name."]},{"cell_type":"markdown","id":"5a3fe6e8-b8aa-4447-812b-7931831e07fe","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Create the [Power Query Template](https://learn.microsoft.com/power-query/power-query-template) file\n","\n","This encapsulates all of the semantic model's Power Query logic into a single file."]},{"cell_type":"code","execution_count":null,"id":"cde43b47-4ecc-46ae-9125-9674819c7eab","metadata":{"jupyter":{"outputs_hidden":false,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["migration.create_pqt_file(dataset = dataset_name, workspace = workspace_name)"]},{"cell_type":"markdown","id":"bf945d07-544c-4934-b7a6-cfdb90ca725e","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Import the Power Query Template to Dataflows Gen2\n","\n","- Open the [OneLake file explorer](https://www.microsoft.com/download/details.aspx?id=105222) and sync your files (right click -> Sync from OneLake)\n","\n","- Navigate to your lakehouse. From this window, create a new Dataflows Gen2 and import the Power Query Template file from OneLake (OneLake -> Workspace -> Lakehouse -> Files...), and publish the Dataflows Gen2.\n","\n","<div class=\"alert alert-block alert-info\">\n","<b>Important!:</b> Make sure to create the Dataflows Gen2 from within the lakehouse window. That will ensure that all the tables automatically map to that lakehouse as the destination. Otherwise, you will have to manually map each table to its destination individually.\n","</div>"]},{"cell_type":"markdown","id":"9975db7d","metadata":{},"source":["### Create the Direct Lake model based on the import/DQ semantic model\n","\n","Calculated columns are not migrated to the Direct Lake model as they are not supported in Direct Lake mode."]},{"cell_type":"code","execution_count":null,"id":"0a3616b5-566e-414e-a225-fb850d6418dc","metadata":{"jupyter":{"outputs_hidden":false,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["import time\n","labs.create_blank_semantic_model(dataset = new_dataset_name, workspace = new_dataset_workspace_name)\n","\n","time.sleep(2)\n","\n","migration.migrate_calc_tables_to_lakehouse(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name,\n"," lakehouse = lakehouse_name,\n"," lakehouse_workspace = lakehouse_workspace_name)\n","migration.migrate_tables_columns_to_semantic_model(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name,\n"," lakehouse = lakehouse_name,\n"," lakehouse_workspace = lakehouse_workspace_name)\n","migration.migrate_calc_tables_to_semantic_model(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name,\n"," lakehouse = lakehouse_name,\n"," lakehouse_workspace = lakehouse_workspace_name)\n","migration.migrate_model_objects_to_semantic_model(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name)\n","migration.migrate_field_parameters(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name,\n"," workspace = workspace_name,\n"," new_dataset_workspace = new_dataset_workspace_name)\n","time.sleep(2)\n","labs.refresh_semantic_model(dataset = new_dataset_name, workspace = new_dataset_workspace_name)\n","migration.refresh_calc_tables(dataset = new_dataset_name, workspace = new_dataset_workspace_name)\n","labs.refresh_semantic_model(dataset = new_dataset_name, workspace = new_dataset_workspace_name)"]},{"cell_type":"markdown","id":"bb98bb13","metadata":{},"source":["### Show migrated/unmigrated objects"]},{"cell_type":"code","execution_count":null,"id":"5db2f22c","metadata":{},"outputs":[],"source":["migration.migration_validation(\n"," dataset = dataset_name,\n"," new_dataset = new_dataset_name, \n"," workspace = workspace_name, \n"," new_dataset_workspace = new_dataset_workspace_name)"]},{"cell_type":"markdown","id":"fa244e9d-87c2-4a66-a7e0-be539a0ac7de","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Rebind all reports using the old semantic model to the new Direct Lake semantic model"]},{"cell_type":"code","execution_count":null,"id":"d4e867cc","metadata":{},"outputs":[],"source":["report.report_rebind_all(\n"," dataset = dataset_name,\n"," dataset_workspace = workspace_name,\n"," new_dataset = new_dataset_name,\n"," new_dataset_workpace = new_dataset_workspace_name,\n"," report_workspace = workspace_name)"]},{"cell_type":"markdown","id":"3365d20d","metadata":{},"source":["### Rebind reports one-by-one (optional)"]},{"cell_type":"code","execution_count":null,"id":"056b7180-d7ac-492c-87e7-ac7d0e4bb929","metadata":{"jupyter":{"outputs_hidden":false,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["report_name = '' # Enter report name which you want to rebind to the new Direct Lake model\n","\n","report.report_rebind(\n"," report = report_name,\n"," dataset = new_dataset_name,\n"," report_workspace=workspace_name,\n"," dataset_workspace = new_dataset_workspace_name)"]},{"cell_type":"markdown","id":"526f2327","metadata":{},"source":["### Show unsupported objects"]},{"cell_type":"code","execution_count":null,"id":"a47376d7","metadata":{},"outputs":[],"source":["dfT, dfC, dfR = directlake.show_unsupported_direct_lake_objects(dataset = dataset_name, workspace = workspace_name)\n","\n","print('Calculated Tables are not supported...')\n","display(dfT)\n","print(\"Learn more about Direct Lake limitations here: https://learn.microsoft.com/power-bi/enterprise/directlake-overview#known-issues-and-limitations\")\n","print('Calculated columns are not supported. Columns of binary data type are not supported.')\n","display(dfC)\n","print('Columns used for relationship cannot be of data type datetime and they also must be of the same data type.')\n","display(dfR)"]},{"cell_type":"markdown","id":"ed08ba4c","metadata":{},"source":["### Schema check between semantic model tables/columns and lakehouse tables/columns\n","\n","This will list any tables/columns which are in the new semantic model but do not exist in the lakehouse"]},{"cell_type":"code","execution_count":null,"id":"03889ba4","metadata":{},"outputs":[],"source":["directlake.direct_lake_schema_compare(dataset = new_dataset_name, workspace = new_dataset_workspace_name)"]},{"cell_type":"markdown","id":"2229963b","metadata":{},"source":["### Show calculated tables which have been migrated to the Direct Lake semantic model as regular tables"]},{"cell_type":"code","execution_count":null,"id":"dd537d90","metadata":{},"outputs":[],"source":["directlake.list_direct_lake_model_calc_tables(dataset = new_dataset_name, workspace = new_dataset_workspace_name)"]}],"metadata":{"kernel_info":{"name":"synapse_pyspark"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.12.3"},"microsoft":{"language":"python"},"nteract":{"version":"nteract-front-end@1.0.0"},"spark_compute":{"compute_id":"/trident/default"},"synapse_widget":{"state":{},"version":"0.1"},"widgets":{}},"nbformat":4,"nbformat_minor":5}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"cells":[{"cell_type":"markdown","id":"5c27dfd1-4fe0-4a97-92e6-ddf78889aa93","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Install the latest .whl package\n","\n","Check [here](https://pypi.org/project/semantic-link-labs/) to see the latest version."]},{"cell_type":"code","execution_count":null,"id":"d5cae9db-cef9-48a8-a351-9c5fcc99645c","metadata":{"jupyter":{"outputs_hidden":true,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["%pip install semantic-link-labs"]},{"cell_type":"markdown","id":"5a3fe6e8-b8aa-4447-812b-7931831e07fe","metadata":{"nteract":{"transient":{"deleting":false}}},"source":["### Connect to the [Tabular Object Model](https://learn.microsoft.com/analysis-services/tom/introduction-to-the-tabular-object-model-tom-in-analysis-services-amo?view=asallproducts-allversions) ([TOM](https://learn.microsoft.com/dotnet/api/microsoft.analysisservices.tabular.model?view=analysisservices-dotnet))\n","Setting the 'readonly' property to False enables read/write mode. This allows changes to be made to the semantic model."]},{"cell_type":"code","execution_count":null,"id":"cde43b47-4ecc-46ae-9125-9674819c7eab","metadata":{"jupyter":{"outputs_hidden":false,"source_hidden":false},"nteract":{"transient":{"deleting":false}}},"outputs":[],"source":["import sempy_labs as labs\n","from sempy_labs.tom import connect_semantic_model\n","\n","dataset = '' # Enter dataset name\n","workspace = None # Enter workspace name\n","\n","with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for t in tom.model.Tables:\n"," print(t.Name)"]},{"cell_type":"markdown","id":"fc6b277e","metadata":{},"source":["### Make changes to a semantic model using custom functions\n","Note that the custom functions have additional optional parameters (which may not be used in the examples below) for adding properties to model objects. Check the [documentation](https://semantic-link-labs.readthedocs.io/en/0.5.0/sempy_labs.tom.html) to see all available parameters for each function."]},{"cell_type":"markdown","id":"402a477c","metadata":{},"source":["#### Add measure(s) to the semantic model"]},{"cell_type":"code","execution_count":null,"id":"bdaaaa5c","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_measure(table_name ='Internet Sales', measure_name = 'Sales Amount', expression = \"SUM('Internet Sales'[SalesAmount])\")\n"," tom.add_measure(table_name ='Internet Sales', measure_name = 'Order Quantity', expression = \"SUM('Internet Sales'[OrderQty])\") "]},{"cell_type":"code","execution_count":null,"id":"a53a544b","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," for t in tom.model.Tables:\n"," if t.Name == 'Internet Sales':\n"," tom.add_measure(table_name = t.Name, measure_name = 'Sales Amount', expression = \"SUM('Internet Sales'[SalesAmount])\")\n"," tom.add_measure(table_name = t.Name, measure_name = 'Order Quantity', expression = \"SUM('Internet Sales'[OrderQty])\")"]},{"cell_type":"markdown","id":"1cb1632f","metadata":{},"source":["#### Add column(s) to the semantic model"]},{"cell_type":"code","execution_count":null,"id":"81a22749","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_data_column(table_name ='Product', column_name = 'Size Range', source_column = 'SizeRange', data_type = 'Int64')\n"," tom.add_data_column(table_name = 'Segment', column_name = 'Summary Segment', source_column = 'SummarySegment', data_type = 'String')\n","\n"," tom.add_calculated_column(table_name = 'Internet Sales', column_name = 'GrossMargin', expression = \"'Internet Sales'[SalesAmount] - 'Internet Sales'[ProductCost]\", data_type = 'Decimal')"]},{"cell_type":"code","execution_count":null,"id":"053b6516","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," for t in tom.model.Tables:\n"," if t.Name == 'Product':\n"," tom.add_data_column(table_name = t.Name, column_name = 'Size Range', source_column = 'SizeRange', data_type = 'Int64')\n"," elif t.Name == 'Segment':\n"," tom.add_data_column(table_name = t.Name, column_name = 'Summary Segment', source_column = 'SummarySegment', data_type = 'String')\n"," elif t.Name == 'Internet Sales':\n"," tom.add_calculated_column(table_name = t.Name, column_name = 'GrossMargin', expression = \"'Internet Sales'[SalesAmount] - 'Internet Sales'[ProductCost]\", data_type = 'Decimal')"]},{"cell_type":"markdown","id":"f53dcca7","metadata":{},"source":["#### Add hierarchies to the semantic model"]},{"cell_type":"code","execution_count":null,"id":"a9309e23","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_hierarchy(table_name = 'Geography', hierarchy_name = 'Geo Hierarchy', levels = ['Continent', 'Country', 'State', 'City'])"]},{"cell_type":"code","execution_count":null,"id":"a04281ce","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," for t in tom.model.Tables:\n"," if t.Name == 'Geography':\n"," tom.add_hierarchy(table_name = t.Name, hierarchy_name = 'Geo Hierarchy', levels = ['Continent', 'Country', 'State', 'City'])"]},{"cell_type":"markdown","id":"47c06a4f","metadata":{},"source":["#### Add relationship(s) to the semantic model"]},{"cell_type":"code","execution_count":null,"id":"e8cd7bbf","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_relationship(\n"," from_table = 'Internet Sales', from_column = 'ProductKey',\n"," to_table = 'Product', to_column = 'ProductKey', \n"," from_cardinality = 'Many', to_cardinality = 'One')"]},{"cell_type":"markdown","id":"3cc7f11e","metadata":{},"source":["#### Add a table with an M partition to a semantic model"]},{"cell_type":"code","execution_count":null,"id":"0f5dd66a","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," table_name = 'Sales'\n"," tom.add_table(name = table_name)\n"," tom.add_m_partition(table_name = table_name, partition_name = table_name, expression = 'let....')"]},{"cell_type":"markdown","id":"ea389123","metadata":{},"source":["#### Add a table with an entity partition to a Direct Lake semantic model "]},{"cell_type":"code","execution_count":null,"id":"f75387d1","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," table_name = 'Sales'\n"," tom.add_table(name = table_name)\n"," tom.add_entity_partition(table_name = table_name, entity_name = table_name)"]},{"cell_type":"markdown","id":"e74d0f54","metadata":{},"source":["#### Add a calculated table (and columns) to a semantic model"]},{"cell_type":"code","execution_count":null,"id":"934f7315","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," table_name = 'Sales'\n"," tom.add_calculated_table(name = table_name, expression = \"DISTINCT('Product'[Color])\")\n"," tom.add_calculated_table_column(table_name = table_name, column_name = 'Color', source_column = \"'Product[Color]\", data_type = 'String')"]},{"cell_type":"markdown","id":"0e7088b7","metadata":{},"source":["#### Add role(s) to the semantic model"]},{"cell_type":"code","execution_count":null,"id":"ad60ebb9","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_role(role_name = 'Reader')"]},{"cell_type":"markdown","id":"c541f81a","metadata":{},"source":["#### Set row level security (RLS) to the semantic model\n","This adds row level security (or updates it if it already exists)"]},{"cell_type":"code","execution_count":null,"id":"98603a08","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.set_rls(role_name ='Reader', table_name = 'Product', filter_expression = \"'Dim Product'[Color] = \\\"Blue\\\"\")"]},{"cell_type":"code","execution_count":null,"id":"effea009","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," for r in tom.model.Roles:\n"," if r.Name == 'Reader':\n"," tom.set_rls(role_name = r.Name, table_name = 'Product', filter_expression = \"'Dim Product'[Color] = \\\"Blue\\\"\")"]},{"cell_type":"markdown","id":"7fa7a03c","metadata":{},"source":["#### Set object level security (OLS) to the semantic model\n","This adds row level security (or updates it if it already exists)"]},{"cell_type":"code","execution_count":null,"id":"dd0def9d","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.set_ols(role_name = 'Reader', table_name = 'Product', column_name = 'Size', permission = 'None')"]},{"cell_type":"code","execution_count":null,"id":"7a389dc7","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," for r in tom.model.Roles:\n"," if r.Name == 'Reader':\n"," for t in tom.model.Tables:\n"," if t.Name == 'Product':\n"," tom.set_ols(role_name = r.Name, table_name = t.Name, column_name = 'Size', permission = 'None')"]},{"cell_type":"markdown","id":"d0f7ccd1","metadata":{},"source":["#### Add calculation groups and calculation items to the semantic model"]},{"cell_type":"code","execution_count":null,"id":"97f4708b","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_calculation_group(name = 'MyCalcGroup')"]},{"cell_type":"code","execution_count":null,"id":"fef68832","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_calculation_item(table_name = 'MyCalcGroup', calculation_item_name = 'YTD', expression = \"CALCULATE(SELECTEDMEASURE(), DATESYTD('Calendar'[CalendarDate]))\")\n"," tom.add_calculation_item(table_name = 'MyCalcGroup', calculation_item_name = 'MTD', expression = \"CALCULATE(SELECTEDMEASURE(), DATESMTD('Calendar'[CalendarDate]))\")"]},{"cell_type":"code","execution_count":null,"id":"c7653dcc","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," for t in tom.model.Tables:\n"," if t.Name == 'MyCalcGroup':\n"," tom.add_calculation_item(table_name = t.Name, calculation_item_name = 'YTD', expression = \"CALCULATE(SELECTEDMEASURE(), DATESYTD('Calendar'[CalendarDate]))\")\n"," tom.add_calculation_item(table_name = t.Name, calculation_item_name = 'MTD', expression = \"CALCULATE(SELECTEDMEASURE(), DATESMTD('Calendar'[CalendarDate]))\")"]},{"cell_type":"markdown","id":"c6450c74","metadata":{},"source":["#### Add translations to a semantic model"]},{"cell_type":"code","execution_count":null,"id":"2b616b90","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_translation(language = 'it-IT')"]},{"cell_type":"code","execution_count":null,"id":"dc24c200","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.set_translation(object = tom.model.Tables['Product'], language = 'it-IT', property = 'Name', value = 'Produtto')"]},{"cell_type":"markdown","id":"3048cc95","metadata":{},"source":["#### Add a [Field Parameter](https://learn.microsoft.com/power-bi/create-reports/power-bi-field-parameters) to a semantic model"]},{"cell_type":"code","execution_count":null,"id":"0a94af94","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.add_field_parameter(table_name = 'Parameter', objects = \"'Product'[Color], [Sales Amount], 'Geography'[Country]\")"]},{"cell_type":"markdown","id":"95aac09a","metadata":{},"source":["#### Remove an object(s) from a semantic model"]},{"cell_type":"code","execution_count":null,"id":"1e2572a8","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," for t in tom.model.Tables:\n"," if t.Name == 'Product':\n"," tom.remove_object(object = t.Columns['Size'])\n"," tom.remove_object(object = t.Hierarchies['Product Hierarchy'])"]},{"cell_type":"code","execution_count":null,"id":"bc453177","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.remove_object(object = tom.model.Tables['Product'].Columns['Size'])\n"," tom.remove_object(object = tom.model.Tables['Product'].Hierarchies['Product Hierarchy'])"]},{"cell_type":"markdown","id":"e0d0cb9e","metadata":{},"source":["### Custom functions to loop through non-top-level objects in a semantic model"]},{"cell_type":"code","execution_count":null,"id":"cbe3b1a3","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for c in tom.all_columns():\n"," print(c.Name)"]},{"cell_type":"code","execution_count":null,"id":"3f643e66","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for m in tom.all_measures():\n"," print(m.Name)"]},{"cell_type":"code","execution_count":null,"id":"ed1cde0f","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for p in tom.all_partitions():\n"," print(p.Name)"]},{"cell_type":"code","execution_count":null,"id":"f48014ae","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for h in tom.all_hierarchies():\n"," print(h.Name)"]},{"cell_type":"code","execution_count":null,"id":"9f5e7b72","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for ci in tom.all_calculation_items():\n"," print(ci.Name)"]},{"cell_type":"code","execution_count":null,"id":"3cd9ebc1","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for l in tom.all_levels():\n"," print(l.Name)"]},{"cell_type":"code","execution_count":null,"id":"12c58bad","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," for rls in tom.all_rls():\n"," print(rls.Name)"]},{"cell_type":"markdown","id":"1a294bd2","metadata":{},"source":["### See Vertipaq Analyzer stats"]},{"cell_type":"code","execution_count":null,"id":"469660e9","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:\n"," tom.set_vertipaq_annotations()\n","\n"," for t in tom.model.Tables:\n"," rc = tom.row_count(object = t)\n"," print(t.Name + ' : ' + str(rc))\n"," for c in t.Columns:\n"," col_size = tom.total_size(column = c)\n"," print(labs.format_dax_object_name(t.Name, c.Name) + ' : ' + str(col_size))"]},{"cell_type":"markdown","id":"1ab26dfd","metadata":{},"source":["### 'UsedIn' functions"]},{"cell_type":"code","execution_count":null,"id":"412bf287","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for c in tom.all_columns():\n"," full_name = labs.format_dax_object_name(c.Parent.Name, c.Name)\n"," for h in tom.used_in_hierarchies(column = c):\n"," print(full_name + ' : ' + h.Name)"]},{"cell_type":"code","execution_count":null,"id":"76556900","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for c in tom.all_columns():\n"," full_name = labs.format_dax_object_name(c.Parent.Name, c.Name)\n"," for r in tom.used_in_relationships(object = c):\n"," rel_name = labs.create_relationship_name(r.FromTable.Name, r.FromColumn.Name, r.ToTable.Name, r.ToColumn.Name)\n"," print(full_name + ' : ' + rel_name)"]},{"cell_type":"code","execution_count":null,"id":"4d9ec24e","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," for t in tom.model.Tables:\n"," for r in tom.used_in_relationships(object = t):\n"," rel_name = labs.create_relationship_name(r.FromTable.Name, r.FromColumn.Name, r.ToTable.Name, r.ToColumn.Name)\n"," print(t.Name + ' : ' + rel_name)"]},{"cell_type":"code","execution_count":null,"id":"82251336","metadata":{},"outputs":[],"source":["with connect_semantic_model(dataset=dataset, readonly=True, workspace=workspace) as tom:\n"," dep = labs.get_model_calc_dependencies(dataset = dataset, workspace=workspace)\n"," for o in tom.used_in_rls(object = tom.model.Tables['Product'].Columns['Color'], dependencies=dep):\n"," print(o.Name)"]}],"metadata":{"kernel_info":{"name":"synapse_pyspark"},"kernelspec":{"display_name":"Synapse PySpark","language":"Python","name":"synapse_pyspark"},"language_info":{"name":"python"},"microsoft":{"language":"python"},"nteract":{"version":"nteract-front-end@1.0.0"},"spark_compute":{"compute_id":"/trident/default"},"synapse_widget":{"state":{},"version":"0.1"},"widgets":{}},"nbformat":4,"nbformat_minor":5}
|
{semantic_link_labs-0.4.2 → semantic_link_labs-0.5.0}/src/semantic_link_labs.egg-info/SOURCES.txt
RENAMED
|
@@ -7,6 +7,9 @@ SECURITY.md
|
|
|
7
7
|
SUPPORT.md
|
|
8
8
|
environment.yml
|
|
9
9
|
pyproject.toml
|
|
10
|
+
.github/ISSUE_TEMPLATE/bug_report.md
|
|
11
|
+
.github/ISSUE_TEMPLATE/feature_request.md
|
|
12
|
+
.github/ISSUE_TEMPLATE/issue--question---advice-needed.md
|
|
10
13
|
.github/workflows/build.yaml
|
|
11
14
|
.github/workflows/codeql.yaml
|
|
12
15
|
.vscode/settings.json
|
|
@@ -34,9 +34,21 @@ from sempy_labs._list_functions import (
|
|
|
34
34
|
# list_sqlendpoints,
|
|
35
35
|
# list_tables,
|
|
36
36
|
list_warehouses,
|
|
37
|
-
|
|
37
|
+
list_workspace_role_assignments,
|
|
38
38
|
create_warehouse,
|
|
39
39
|
update_item,
|
|
40
|
+
list_custom_pools,
|
|
41
|
+
create_custom_pool,
|
|
42
|
+
update_custom_pool,
|
|
43
|
+
assign_workspace_to_capacity,
|
|
44
|
+
unassign_workspace_from_capacity,
|
|
45
|
+
get_spark_settings,
|
|
46
|
+
update_spark_settings,
|
|
47
|
+
add_user_to_workspace,
|
|
48
|
+
delete_user_from_workspace,
|
|
49
|
+
update_workspace_user,
|
|
50
|
+
list_workspace_users,
|
|
51
|
+
assign_workspace_to_dataflow_storage,
|
|
40
52
|
)
|
|
41
53
|
|
|
42
54
|
from sempy_labs._helper_functions import (
|
|
@@ -113,7 +125,7 @@ __all__ = [
|
|
|
113
125
|
#'list_sqlendpoints',
|
|
114
126
|
#'list_tables',
|
|
115
127
|
"list_warehouses",
|
|
116
|
-
|
|
128
|
+
'list_workspace_role_assignments',
|
|
117
129
|
"create_warehouse",
|
|
118
130
|
"update_item",
|
|
119
131
|
"create_abfss_path",
|
|
@@ -150,5 +162,17 @@ __all__ = [
|
|
|
150
162
|
#'visualize_vertipaq',
|
|
151
163
|
"import_vertipaq_analyzer",
|
|
152
164
|
"list_semantic_model_objects",
|
|
153
|
-
"list_shortcuts"
|
|
165
|
+
"list_shortcuts",
|
|
166
|
+
"list_custom_pools",
|
|
167
|
+
"create_custom_pool",
|
|
168
|
+
"update_custom_pool",
|
|
169
|
+
"assign_workspace_to_capacity",
|
|
170
|
+
"unassign_workspace_from_capacity",
|
|
171
|
+
"get_spark_settings",
|
|
172
|
+
"update_spark_settings",
|
|
173
|
+
"add_user_to_workspace",
|
|
174
|
+
"delete_user_from_workspace",
|
|
175
|
+
"update_workspace_user",
|
|
176
|
+
"list_workspace_users",
|
|
177
|
+
"assign_workspace_to_dataflow_storage"
|
|
154
178
|
]
|
|
@@ -14,6 +14,7 @@ def optimize_semantic_model(dataset: str, workspace: Optional[str] = None):
|
|
|
14
14
|
from ._model_bpa import run_model_bpa
|
|
15
15
|
from .directlake._fallback import check_fallback_reason
|
|
16
16
|
from ._helper_functions import format_dax_object_name
|
|
17
|
+
from sempy_labs.tom import connect_semantic_model
|
|
17
18
|
|
|
18
19
|
modelBPA = run_model_bpa(
|
|
19
20
|
dataset=dataset, workspace=workspace, return_dataframe=True
|
|
@@ -78,10 +79,7 @@ def generate_measure_descriptions(
|
|
|
78
79
|
|
|
79
80
|
validModels = ["gpt-35-turbo", "gpt-35-turbo-16k", "gpt-4"]
|
|
80
81
|
if gpt_model not in validModels:
|
|
81
|
-
|
|
82
|
-
f"{icons.red_dot} The '{gpt_model}' model is not a valid model. Enter a gpt_model from this list: {validModels}."
|
|
83
|
-
)
|
|
84
|
-
return
|
|
82
|
+
raise ValueError(f"{icons.red_dot} The '{gpt_model}' model is not a valid model. Enter a gpt_model from this list: {validModels}.")
|
|
85
83
|
|
|
86
84
|
dfM = fabric.list_measures(dataset=dataset, workspace=workspace)
|
|
87
85
|
|
|
@@ -116,8 +114,8 @@ def generate_measure_descriptions(
|
|
|
116
114
|
)
|
|
117
115
|
|
|
118
116
|
# Update the model to use the new descriptions
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
#with connect_semantic_model(dataset=dataset, workspace=workspace, readonly=False) as tom:
|
|
118
|
+
|
|
121
119
|
|
|
122
120
|
# for t in m.Tables:
|
|
123
121
|
# tName = t.Name
|
|
@@ -173,48 +171,33 @@ def generate_aggs(
|
|
|
173
171
|
numericTypes = ["Int64", "Double", "Decimal"]
|
|
174
172
|
|
|
175
173
|
if any(value not in aggTypes for value in columns.values()):
|
|
176
|
-
|
|
177
|
-
f"{icons.red_dot} Invalid aggregation type(s) have been specified in the 'columns' parameter. Valid aggregation types: {aggTypes}."
|
|
178
|
-
)
|
|
179
|
-
return
|
|
174
|
+
raise ValueError(f"{icons.red_dot} Invalid aggregation type(s) have been specified in the 'columns' parameter. Valid aggregation types: {aggTypes}.")
|
|
180
175
|
|
|
181
176
|
dfC = fabric.list_columns(dataset=dataset, workspace=workspace)
|
|
182
177
|
dfP = fabric.list_partitions(dataset=dataset, workspace=workspace)
|
|
183
178
|
dfM = fabric.list_measures(dataset=dataset, workspace=workspace)
|
|
184
179
|
dfR = fabric.list_relationships(dataset=dataset, workspace=workspace)
|
|
185
180
|
if not any(r["Mode"] == "DirectLake" for i, r in dfP.iterrows()):
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
189
|
-
return
|
|
190
|
-
|
|
181
|
+
raise ValueError(f"{icons.red_dot} The '{dataset}' semantic model within the '{workspace}' workspace is not in Direct Lake mode. This function is only relevant for Direct Lake semantic models.")
|
|
182
|
+
|
|
191
183
|
dfC_filtT = dfC[dfC["Table Name"] == table_name]
|
|
192
184
|
|
|
193
185
|
if len(dfC_filtT) == 0:
|
|
194
|
-
|
|
195
|
-
f"{icons.red_dot} The '{table_name}' table does not exist in the '{dataset}' semantic model within the '{workspace}' workspace."
|
|
196
|
-
)
|
|
197
|
-
return
|
|
186
|
+
raise ValueError(f"{icons.red_dot} The '{table_name}' table does not exist in the '{dataset}' semantic model within the '{workspace}' workspace.")
|
|
198
187
|
|
|
199
188
|
dfC_filt = dfC[
|
|
200
189
|
(dfC["Table Name"] == table_name) & (dfC["Column Name"].isin(columnValues))
|
|
201
190
|
]
|
|
202
191
|
|
|
203
192
|
if len(columns) != len(dfC_filt):
|
|
204
|
-
|
|
205
|
-
f"{icons.red_dot} Columns listed in '{columnValues}' do not exist in the '{table_name}' table in the '{dataset}' semantic model within the '{workspace}' workspace."
|
|
206
|
-
)
|
|
207
|
-
return
|
|
193
|
+
raise ValueError(f"{icons.red_dot} Columns listed in '{columnValues}' do not exist in the '{table_name}' table in the '{dataset}' semantic model within the '{workspace}' workspace.")
|
|
208
194
|
|
|
209
195
|
# Check if doing sum/count/min/max etc. on a non-number column
|
|
210
196
|
for col, agg in columns.items():
|
|
211
197
|
dfC_col = dfC_filt[dfC_filt["Column Name"] == col]
|
|
212
198
|
dataType = dfC_col["Data Type"].iloc[0]
|
|
213
199
|
if agg in aggTypesAggregate and dataType not in numericTypes:
|
|
214
|
-
|
|
215
|
-
f"{icons.red_dot} The '{col}' column in the '{table_name}' table is of '{dataType}' data type. Only columns of '{numericTypes}' data types can be aggregated as '{aggTypesAggregate}' aggregation types."
|
|
216
|
-
)
|
|
217
|
-
return
|
|
200
|
+
raise ValueError(f"{icons.red_dot} The '{col}' column in the '{table_name}' table is of '{dataType}' data type. Only columns of '{numericTypes}' data types can be aggregated as '{aggTypesAggregate}' aggregation types.")
|
|
218
201
|
|
|
219
202
|
# Create/update lakehouse delta agg table
|
|
220
203
|
aggSuffix = "_agg"
|
|
@@ -230,10 +213,7 @@ def generate_aggs(
|
|
|
230
213
|
dfI_filt = dfI[(dfI["Id"] == sqlEndpointId)]
|
|
231
214
|
|
|
232
215
|
if len(dfI_filt) == 0:
|
|
233
|
-
|
|
234
|
-
f"{icons.red_dot} The lakehouse (SQL Endpoint) used by the '{dataset}' semantic model does not reside in the '{lakehouse_workspace}' workspace. Please update the lakehouse_workspace parameter."
|
|
235
|
-
)
|
|
236
|
-
return
|
|
216
|
+
raise ValueError(f"{icons.red_dot} The lakehouse (SQL Endpoint) used by the '{dataset}' semantic model does not reside in the '{lakehouse_workspace}' workspace. Please update the lakehouse_workspace parameter.")
|
|
237
217
|
|
|
238
218
|
lakehouseName = dfI_filt["Display Name"].iloc[0]
|
|
239
219
|
lakehouse_id = resolve_lakehouse_id(
|
|
@@ -284,7 +264,7 @@ def generate_aggs(
|
|
|
284
264
|
# Create/update semantic model agg table
|
|
285
265
|
tom_server = fabric.create_tom_server(readonly=False, workspace=workspace)
|
|
286
266
|
m = tom_server.Databases.GetByName(dataset).Model
|
|
287
|
-
f"\n{icons.in_progress} Updating the '{dataset}' semantic model..."
|
|
267
|
+
print(f"\n{icons.in_progress} Updating the '{dataset}' semantic model...")
|
|
288
268
|
dfC_agg = dfC[dfC["Table Name"] == aggTableName]
|
|
289
269
|
|
|
290
270
|
if len(dfC_agg) == 0:
|
|
@@ -20,9 +20,7 @@ def clear_cache(dataset: str, workspace: Optional[str] = None):
|
|
|
20
20
|
or if no lakehouse attached, resolves to the workspace of the notebook.
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
workspace_id = fabric.get_workspace_id()
|
|
25
|
-
workspace = fabric.resolve_workspace_name(workspace_id)
|
|
23
|
+
workspace = fabric.resolve_workspace_name(workspace)
|
|
26
24
|
|
|
27
25
|
datasetID = resolve_dataset_id(dataset=dataset, workspace=workspace)
|
|
28
26
|
|
|
@@ -2,6 +2,7 @@ import sempy
|
|
|
2
2
|
import sempy.fabric as fabric
|
|
3
3
|
import pandas as pd
|
|
4
4
|
from typing import List, Optional, Union
|
|
5
|
+
import sempy_labs._icons as icons
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
def create_connection_cloud(
|
|
@@ -11,7 +12,7 @@ def create_connection_cloud(
|
|
|
11
12
|
user_name: str,
|
|
12
13
|
password: str,
|
|
13
14
|
privacy_level: str,
|
|
14
|
-
):
|
|
15
|
+
) -> pd.DataFrame:
|
|
15
16
|
|
|
16
17
|
# https://review.learn.microsoft.com/en-us/rest/api/fabric/core/connections/create-connection?branch=features%2Fdmts&tabs=HTTP
|
|
17
18
|
|
|
@@ -60,16 +61,16 @@ def create_connection_cloud(
|
|
|
60
61
|
if response.status_code == 200:
|
|
61
62
|
o = response.json()
|
|
62
63
|
new_data = {
|
|
63
|
-
"Connection Id": o
|
|
64
|
-
"Connection Name": o
|
|
65
|
-
"Connectivity Type": o
|
|
66
|
-
"Connection Type": o
|
|
67
|
-
"Connection Path": o
|
|
68
|
-
"Privacy Level": o
|
|
69
|
-
"Credential Type": o
|
|
70
|
-
"Single Sign On Type": o
|
|
71
|
-
"Connection Encryption": o
|
|
72
|
-
"Skip Test Connection": o
|
|
64
|
+
"Connection Id": o.get("id"),
|
|
65
|
+
"Connection Name": o.get("name"),
|
|
66
|
+
"Connectivity Type": o.get("connectivityType"),
|
|
67
|
+
"Connection Type": o.get("connectionDetails",{}).get("type"),
|
|
68
|
+
"Connection Path": o.get("connectionDetails",{}).get("path"),
|
|
69
|
+
"Privacy Level": o.get("privacyLevel"),
|
|
70
|
+
"Credential Type": o.get("credentialDetails",{}).get("credentialType"),
|
|
71
|
+
"Single Sign On Type": o.get("credentialDetails",{}).get("singleSignOnType"),
|
|
72
|
+
"Connection Encryption": o.get("credentialDetails",{}).get("connectionEncryption"),
|
|
73
|
+
"Skip Test Connection": o.get("credentialDetails",{}).get("skipTestConnection"),
|
|
73
74
|
}
|
|
74
75
|
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
|
|
75
76
|
|
|
@@ -77,7 +78,7 @@ def create_connection_cloud(
|
|
|
77
78
|
|
|
78
79
|
return df
|
|
79
80
|
else:
|
|
80
|
-
print(response.status_code)
|
|
81
|
+
print(f"{icons.red_dot} {response.status_code}")
|
|
81
82
|
|
|
82
83
|
|
|
83
84
|
def create_connection_on_prem(
|
|
@@ -87,7 +88,7 @@ def create_connection_on_prem(
|
|
|
87
88
|
database_name: str,
|
|
88
89
|
credentials: str,
|
|
89
90
|
privacy_level: str,
|
|
90
|
-
):
|
|
91
|
+
) -> pd.DataFrame:
|
|
91
92
|
|
|
92
93
|
df = pd.DataFrame(
|
|
93
94
|
columns=[
|
|
@@ -135,17 +136,17 @@ def create_connection_on_prem(
|
|
|
135
136
|
if response.status_code == 200:
|
|
136
137
|
o = response.json()
|
|
137
138
|
new_data = {
|
|
138
|
-
"Connection Id": o
|
|
139
|
-
"Connection Name": o
|
|
140
|
-
"Gateway ID": o
|
|
141
|
-
"Connectivity Type": o
|
|
142
|
-
"Connection Type": o
|
|
143
|
-
"Connection Path": o
|
|
144
|
-
"Privacy Level": o
|
|
145
|
-
"Credential Type": o
|
|
146
|
-
"Single Sign On Type": o
|
|
147
|
-
"Connection Encryption": o
|
|
148
|
-
"Skip Test Connection": o
|
|
139
|
+
"Connection Id": o.get("id"),
|
|
140
|
+
"Connection Name": o.get("name"),
|
|
141
|
+
"Gateway ID": o.get("gatewayId"),
|
|
142
|
+
"Connectivity Type": o.get("connectivityType"),
|
|
143
|
+
"Connection Type": o.get("connectionDetails",{}).get("type"),
|
|
144
|
+
"Connection Path": o.get("connectionDetails",{}).get("path"),
|
|
145
|
+
"Privacy Level": o.get("privacyLevel"),
|
|
146
|
+
"Credential Type": o.get("credentialDetails",{}).get("credentialType"),
|
|
147
|
+
"Single Sign On Type": o.get("credentialDetails",{}).get("singleSignOnType"),
|
|
148
|
+
"Connection Encryption": o.get("credentialDetails",{}).get("connectionEncryption"),
|
|
149
|
+
"Skip Test Connection": o.get("credentialDetails",{}).get("skipTestConnection"),
|
|
149
150
|
}
|
|
150
151
|
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
|
|
151
152
|
|
|
@@ -153,7 +154,7 @@ def create_connection_on_prem(
|
|
|
153
154
|
|
|
154
155
|
return df
|
|
155
156
|
else:
|
|
156
|
-
print(response.status_code)
|
|
157
|
+
print(f"{icons.red_dot} {response.status_code}")
|
|
157
158
|
|
|
158
159
|
|
|
159
160
|
def create_connection_vnet(
|
|
@@ -164,7 +165,7 @@ def create_connection_vnet(
|
|
|
164
165
|
user_name: str,
|
|
165
166
|
password: str,
|
|
166
167
|
privacy_level: str,
|
|
167
|
-
):
|
|
168
|
+
) -> pd.DataFrame:
|
|
168
169
|
|
|
169
170
|
df = pd.DataFrame(
|
|
170
171
|
columns=[
|
|
@@ -213,17 +214,17 @@ def create_connection_vnet(
|
|
|
213
214
|
if response.status_code == 200:
|
|
214
215
|
o = response.json()
|
|
215
216
|
new_data = {
|
|
216
|
-
"Connection Id": o
|
|
217
|
-
"Connection Name": o
|
|
218
|
-
"Gateway ID": o
|
|
219
|
-
"Connectivity Type": o
|
|
220
|
-
"Connection Type": o
|
|
221
|
-
"Connection Path": o
|
|
222
|
-
"Privacy Level": o
|
|
223
|
-
"Credential Type": o
|
|
224
|
-
"Single Sign On Type": o
|
|
225
|
-
"Connection Encryption": o
|
|
226
|
-
"Skip Test Connection": o
|
|
217
|
+
"Connection Id": o.get("id"),
|
|
218
|
+
"Connection Name": o.get("name"),
|
|
219
|
+
"Gateway ID": o.get("gatewayId"),
|
|
220
|
+
"Connectivity Type": o.get("connectivityType"),
|
|
221
|
+
"Connection Type": o.get("connectionDetails",{}).get("type"),
|
|
222
|
+
"Connection Path": o.get("connectionDetails",{}).get("path"),
|
|
223
|
+
"Privacy Level": o.get("privacyLevel"),
|
|
224
|
+
"Credential Type": o.get("credentialDetails",{}).get("credentialType"),
|
|
225
|
+
"Single Sign On Type": o.get("credentialDetails",{}).get("singleSignOnType"),
|
|
226
|
+
"Connection Encryption": o.get("credentialDetails",{}).get("connectionEncryption"),
|
|
227
|
+
"Skip Test Connection": o.get("credentialDetails",{}).get("skipTestConnection"),
|
|
227
228
|
}
|
|
228
229
|
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
|
|
229
230
|
|
|
@@ -231,4 +232,4 @@ def create_connection_vnet(
|
|
|
231
232
|
|
|
232
233
|
return df
|
|
233
234
|
else:
|
|
234
|
-
print(response.status_code)
|
|
235
|
+
print(f"{icons.red_dot} {response.status_code}")
|