I want to declare Pyspark variable in Synapse and use the variable in Kusto queries.
The variable declared in Pyspark as below
s = "02-01-2022"
print(s)
e = "02-10-2022"
print(e)
Want to use the variable ' s
' and ' e
' in Kusto queries as shown below
%%pyspark
s = "02-01-2022"
print(s)
e = "02-10-2022"
print(e)
# Read data from Azure Data Explorer table(s)
# Full Sample Code available at: https://github.com/Azure/azure-kusto-spark/blob/master/samples/src/main/python/SynapseSample.py
sales_data = spark.read \
.format("com.microsoft.kusto.spark.synapse.datasource") \
.option("spark.synapse.linkedService", "LinkedServiceName") \
.option("kustoDatabase", "DatabaseName") \
.option("kustoQuery", "let starttime = startofday(todatetime('s')); let endtime = startofday(todatetime('e')); Table | where Time between (starttime .. endtime) | summarize amount = count() by Date= bin(TIMESTAMP,5h) | project Date,amount | order by Date asc") \
.load()
display(sales_data)
You can use the variable in the following way in pyspark:
option("kustoQuery", "let starttime = startofday(todatetime('" + s + "')); let endtime = startofday(todatetime('" + e + "')); Table | where Time between (starttime .. endtime) | summarize amount = count() by Date= bin(TIMESTAMP,5h) | project Date,amount | order by Date asc")
Also, please refer Azure Data Explorer (Kusto) connector for Apache Spark
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.