Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

Reply
VenDaFabricator
Resolver I
Resolver I

Writing to KQL db from notebook - Error

Am following this link => Use Fabric notebooks with data from a KQL database - Microsoft Fabric | Microsoft Learn to write directly from notebook to KQL db, but gettting below error;

Py4JJavaError: An error occurred while calling o4856.save. : kusto_connector_shaded.com.microsoft.azure.kusto.data.exceptions.DataServiceException: IOException when trying to retrieve cluster metadata:xxxxxxxx.kusto.windows.net

 

Here is my code:

 

from pyspark.sql import SparkSession
from pyspark.sql.functions import col, lit, round
from datetime import datetime

# Welcome to your new notebook
# Type here in the cell editor to add code!
# The Kusto cluster uri to write the data. The query Uri is of the form https://<>.kusto.data.microsoft.com 
kustoUri = "https://xxxxxx.kusto.data.microsoft.com"
# The database to write the data
database = "BRDS"
# The table to write the data 
table    = "Metrics"
# The access credentials for the write
accessToken = mssparkutils.credentials.getToken(kustoUri)
print(accessToken)
# Generate a range of 5 rows with Id's 5 to 9
data = spark.range(5, 10).withColumnRenamed("id", "Id")

# Add columns for ProcessName, CpuUsage, MemoryUsage, and Timestamp
data = data.withColumn("ProcessName", lit("Process_") + col("Id").cast("string")) \
           .withColumn("CpuUsage", round(lit(10.0) * col("Id") / 10, 2)) \
           .withColumn("MemoryUsage", round(lit(20.0) * col("Id") / 10, 2)) \
           .withColumn("Timestamp", lit(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
data.show()
# Write data to a Kusto table
data.write.\
    format("com.microsoft.kusto.spark.synapse.datasource").\
    option("kustoCluster",kustoUri).\
    option("kustoDatabase",database).\
    option("kustoTable", table).\
    option("accessToken", accessToken ).\
    option("tableCreateOptions", "CreateIfNotExist").mode("Append").save()

 

Any clues! 

1 ACCEPTED SOLUTION

Instead of using Ingest URI, when i used Query URI https://<clusterid>kusto.fabric.microsoft.com and it works.  Documentation is bit mis-leading.

VenDaFabricator_0-1721634681366.png

 

View solution in original post

4 REPLIES 4
VenDaFabricator
Resolver I
Resolver I

HI Yang, 

 

No, there is no issue with URI, i changed it to 'xxxx' while posting in the forum, actual uri in code is from KQL db in Fabric, which was copied from (see below)

VenDaFabricator_1-1721431666961.png

other thing is when you copy url from above:

clusteruri is "https:<KQLdatabaseURI>z1.kusto.fabric.microsoft.com", whereas the codebase (from MS) say's  to specify clusteruri as "https://<yourKQLdatabaseURI>.z0.kusto.data.microsoft.com", but the error message says it can't find "<KQLdatabaseURI>.z1.kusto.windows.net"

 

 

Instead of using Ingest URI, when i used Query URI https://<clusterid>kusto.fabric.microsoft.com and it works.  Documentation is bit mis-leading.

VenDaFabricator_0-1721634681366.png

 

Anonymous
Not applicable

Hi @VenDaFabricator ,

 

It seems that you have gotten a solution. Could you please mark the helpful post as Answered?

 

It will help the others in the community find the solution easily if they face the same problem as yours.

 

Thank you.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Anonymous
Not applicable

Hi @VenDaFabricator ,

 

The error message indicates a problem retrieving cluster metadata from the Kusto database.

 

Consider the following to resolve the problem:

 

There seems to be a problem with your kustoUri:

vhuijieymsft_0-1721379817034.png

 

After checking this, please verify that the access token was retrieved correctly and is valid. You have done a good job. this statement prints the token to ensure that it is not empty or expired.

vhuijieymsft_1-1721379817034.png

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.