我在使用azure Kusto数据库(https://pypi.org/project/azure-kusto-data/)从Kusto查询数据的Python应用程序上工作
我试图编写一个kusto函数来执行一个特定的函数。此函数接收两个输入,一个datatable输入和一个timespan输入
例如:
函数名称:GenerateSomeOutputviaKusto 函数参数:(T:(Env:string,Something:string,StartDate:datetime),输入粒度:timespan)
如您所见,此函数输入使用表格输入。现在,为了正确调用这个函数(比如说,KustoExplorer),我使用“let”语句为这个函数创建表格输入,遵循本页的指导:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/letstatement
let QueryTable = datatable (Environment:string, Something:string, StartDate:datetime)
["Prod", "Sometext", datetime("2020-11-17")];
GenerateSomeOutputviaKusto(QueryTable, 24h);
现在的问题是,当我试图参数化此函数以从python执行此函数时。当我使用python中的kusto库调用此函数时,我需要参数化此函数
我将参数设置为python字典,如下所示:
params = {
"env": self._env,
"something": something,
"startdate": self._alert_start_date_str,
}
然后,我尝试从python代码中参数化kusto函数,如下所示:
declare query_parameters(env:string,
something:string,
starting_time:string);
let QueryTable = datatable (Environment:string, something:string, StartDate:datetime)
[env, something, datetime(startdate)];
GenerateSomeOutputViaKusto(QueryTable, 24h)
当我这样做时,我遇到了以下错误:
[Retry confirmed] KustoServiceError([{'error': {'code': 'General_BadRequest', 'message': 'Request is invalid and cannot be executed.', '@type': 'Kusto.Data.Exceptions.KustoBadRequestException', '@message': "Syntax error: Query could not be parsed: SYN0002: A recognition error occurred. [line:position=5:17]. Query: 'declare query_parameters(env:string,\n something:string,\n startdate:string);\n let QueryTable = datatable (Environment:string, something:string, StartDateTime:datetime)\n [env, something, datetime(startdate)];\n QueryTable'", '@context': {'timestamp': '2020-11-20T17:50:29.4796552Z', 'serviceAlias': 'EGFOLLOWING', 'machineName': 'KEngine000005', 'processName': 'Kusto.WinSvc.Svc', 'processId': 2728, 'threadId': 9068, 'appDomainName': 'Kusto.WinSvc.Svc.exe', 'clientRequestId': 'KPC.execute;1456198f-1e9a-47de-bf4d-053208c861f2', 'activityId': '59726ecc-5a4f-4d63-91f4-a04d706b10d6', 'subActivityId': '8e05442a-34c0-427a-b569-8879e7d1e2d1', 'activityType': 'DN.FE.ExecuteQuery', 'parentActivityId': 'de01e770-e291-4f10-bf9e-a34978193451', 'activityStack': '(Activity stack: CRID=KPC.execute;1456198f-1e9a-47de-bf4d-053208c861f2 ARID=59726ecc-5a4f-4d63-91f4-a04d706b10d6 > KD.Query.Client.ExecuteQueryAsKustoDataStream/d19ed49b-78f6-4f2c-adfc-cf0f6f443bb9 > P.WCF.Service.ExecuteQueryInternalAsKustoDataStream..IClientServiceCommunicationContract/de01e770-e291-4f10-bf9e-a34978193451 > DN.FE.ExecuteQuery/8e05442a-34c0-427a-b569-8879e7d1e2d1)'}, '@permanent': True, '@text': 'declare query_parameters(env:string,\n something:string,\n startdate:string);\n let QueryTable = datatable (Environment:string, something:string, StartDateTime:datetime)\n [env, something, datetime(startdate)];\n QueryTable', '@database': 'defaultdb', '@ClientRequestLogger': '', 'innererror': {'code': 'SYN0002', 'message': 'A recognition error occurred.', '@type': 'Kusto.Data.Exceptions.SyntaxException', '@message': "Syntax error: Query could not be parsed: SYN0002: A recognition error occurred. [line:position=5:17]. Query: 'declare query_parameters(env:string,\n
出于隐私原因,我已替换了一些敏感字段。我的库斯托相关问题是,这样做是否正确?kusto文档在参数化函数方面非常缺乏,尤其是在 像这样的小案子。参数化是可行的,不使用let语句,但同时使用“declare”语句和“let”语句似乎会导致问题
问题是您试图将非常量标量值传递给
datatable
运算符-这是不受支持的,无论是否使用查询参数您可以将
datatable
运算符的用法替换为print
,例如:相关问题 更多 >
编程相关推荐