Created
November 15, 2023 04:55
-
-
Save pawarbi/b48efdc9a8e864d0c4082b851d28d1ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import swifter | |
import json | |
def get_modes(dataset, workspace): | |
''' | |
Author: Sandeep Pawar | fabric.guru | |
Returns storage mode of a dataset as identified from TMSL | |
Fabric uses XMLA client so this will work only for the semantic models in Premium capacity | |
Swifter is used to process a long list faster using .apply method | |
Always verify the results. | |
''' | |
try: | |
tmsl = json.loads(fabric.get_tmsl(dataset=dataset, workspace=workspace)) | |
if 'model' in tmsl and 'tables' in tmsl['model']: | |
modes = set(p['mode'] for table in tmsl['model']['tables'] for p in table['partitions'] if 'mode' in p) | |
return modes | |
else: | |
## if the model doesn't have a partition, | |
## it's likely a default semantic model | |
return "{default}" | |
except Exception as e: | |
# datamart dataset doesn't support XMLA, handling that as an exception | |
error_message = str(e) | |
try: | |
error = json.loads(error_message) | |
if 'DatamartInvalidData' in str(error): | |
return "Datamart Semantic Model" | |
except json.JSONDecodeError: | |
pass # | |
return None | |
datasets['Mode/Type'] = datasets.swifter.apply(lambda row: get_modes(row['Dataset ID'], row['workspace']), axis=1) | |
#If you don't want to install/use swifter, use datasets.apply(...) instead | |
datasets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment