gpt4 book ai didi

parameters - 如何在 KQL 查询中指定参数?

转载 作者:行者123 更新时间:2023-12-05 07:22:53 25 4
gpt4 key购买 nike

我正在尝试使用查询参数和 .NET Kusto SDK 针对 Azure 数据资源管理器集群执行 KQL 查询。

我试过将参数放在大括号 {} 内和不带大括号。

我已阅读有关将参数传递给查询的文档,但我找不到任何示例说明在通过 .NET SDK 将查询传递给 Azure 数据资源管理器时应该如何显示查询。

当我在工具中设置参数时,我的查询在 Kusto.Explorer 工具中有效,但我在使用 SDK 时运气不好。

var queryParameters = new Dictionary<string, string>()
{
{ "myscope", "scope001" },
{ "startdate", "2019-01-01" },
{ "enddate", "2019-01-30" },
{ "author", "Bob Jammo" }
};

var query = @"declare query_parameters (myscope:string, startdate:string, enddate:string, author:string);
Events
| where Scope == ""{myscope}""
and EventTime between (datetime({startdate}) .. datetime({enddate}))
and EventType == ""product""
and User.Email <> """"
| mv-expand Payload.products
| where Payload_products.authors contains ""{author}""
| distinct DeviceId
| count";

using (var client = KustoClientFactory.CreateCslQueryProvider(ConfigurationManager.AppSettings["AdxConnectionString"]))
{
var clientRequestProperties = new Kusto.Data.Common.ClientRequestProperties(
options: null,
parameters: queryParameters);

clientRequestProperties.ClientRequestId = StepsBase.ScenarioScope;

using (var reader = client.ExecuteQuery(query, clientRequestProperties))
{
reader.Read();
return Convert.ToInt32(reader[0]);
}
}

我收到一个错误,指示我尚未设置参数值:“语法错误:无法解析查询:无法解析日期时间文字:'datetime(startdate)'”

最佳答案

根据错误消息判断,这是因为您使用的是 datetime({startdate}) 而不是 todatetime({startdate})

无论如何,您也可以考虑将 startdateenddate 的类型更改为 datetime 而不是 string开始(并调整它们在 .NET 词典中的定义)

关于parameters - 如何在 KQL 查询中指定参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56359317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com