[英]Declare Pyspark variable in Synapse and use it in Kusto query
I want to declare Pyspark variable in Synapse and use the variable in Kusto queries.我想在 Synapse 中声明 Pyspark 变量并在 Kusto 查询中使用该变量。
The variable declared in Pyspark as below Pyspark中声明的变量如下
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想要在 Kusto 查询中使用变量“ s
”和“ e
”,如下所示
%%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:在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另外,请参阅Azure Data Explorer (Kusto) connector for Apache Spark
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.