Skip to content

Instantly share code, notes, and snippets.

@pawarbi
Created November 15, 2023 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawarbi/b48efdc9a8e864d0c4082b851d28d1ad to your computer and use it in GitHub Desktop.
Save pawarbi/b48efdc9a8e864d0c4082b851d28d1ad to your computer and use it in GitHub Desktop.
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