Forum Discussion
DennesTorres
Power Participant
2 years agoIdentify a shortcut in pyspark notebook
Hi, Shortcuts are very powerful and they are a great feature to enable a data mesh architecture. However, thinking on corporation level it may be hard to manage who links with who. How could ...
Syliano
1 year agoNew Member
I resolve this by using sempy :
import sempy.fabric as fabric
import json
import requests
import fnmatch
import base64
-- Get metadata
from pyspark.sql import SparkSession
from pyspark.sql.types import StructType, StructField, StringType
# Récupérer les données depuis Fabric
ws = fabric.get_workspace_id()
items = fabric.list_items(workspace=ws)
# Construire une liste de dictionnaires à partir des données
items_data = [dict(row) for row in items.to_dict("records")]
# print(items_data)
# Définir le schéma (adapté selon vos colonnes)
schema = StructType([
StructField("Id", StringType(), True),
StructField("Display Name", StringType(), True),
StructField("Description", StringType(), True),
StructField("Type", StringType(), True),
StructField("Workspace Id", StringType(), True),
])
# Créer le DataFrame Spark
items_df = spark.createDataFrame(items_data, schema)
# Créer une vue SparkSQL
items_df.createOrReplaceTempView("items_view")
-- get current lakehouse
ws = fabric.get_workspace_id()
items = fabric.list_items(workspace= ws)
item = items[(items['Display Name'] == "Bronze")& (items['Type']=="Lakehouse")].iloc[0]["Id"]
-- call api
client = fabric.FabricRestClient()
r = client.request(method="get", path_or_url=f"/v1/workspaces/{ws}/items/{item}/shortcuts")
-- update or créate shortcup to an other workspace
This code di you help you ?