title: Parameterizing the unusual inputs of a kusto function
body: <p>I work on an Python application that queries data from Kusto using the azure-kusto-data library (<a href="https://pypi.org/project/azure-kusto-data/" rel="nofollow noreferrer">https://pypi.org/project/azure-kusto-data/</a>)</p>
  <p>I am trying to write a kusto function to execute a particular function. This function takes in 2 inputs, a datatable input and a timespan input</p>
  <p>So as an example:</p>
  <p>Function Name: GenerateSomeOutputviaKusto
  Function Parameters: (T:(Env:string,Something:string,StartDate:datetime),inputGranularity:timespan)</p>
  <p>As you can see, this function input uses a tabular input. Now in order to properly call this function (in say, KustoExplorer), I use a &quot;let&quot; statement in order to create the tabular input for this function, following the guidance from this page: <a href="https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/letstatement" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/letstatement</a></p>
  <pre><code>    let QueryTable = datatable (Environment:string, Something:string, StartDate:datetime)
      [&quot;Prod&quot;, &quot;Sometext&quot;, datetime(&quot;2020-11-17&quot;)];
  GenerateSomeOutputviaKusto(QueryTable, 24h);
  </code></pre>
  <p>The issue is now, when I try to parameterize this function to execute this function from python. When I call this function using the kusto library in python, I need to parameterize this function.</p>
  <p><a href="https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/queryparametersstatement?pivots=azuredataexplorer" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/queryparametersstatement?pivots=azuredataexplorer</a></p>
  <p>I have my params set up as a python dictionary, as such:</p>
  <pre><code>    params = {
          &quot;env&quot;: self._env,
          &quot;something&quot;: something,
          &quot;startdate&quot;: self._alert_start_date_str,
      }
  </code></pre>
  <p>I am then trying to parameterize the kusto function from my python code as follows:</p>
  <pre><code>            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)
  </code></pre>
  <p>When I do so, I've been running into this error:</p>
  <blockquote>
  <p>[Retry confirmed] KustoServiceError([{'error': {'code': 'General_BadRequest', 'message': 'Request is invalid and cannot be executed.', '@type': 'Kusto.Data.Exceptions.KustoBadRequestException', '@message': &quot;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'&quot;, '@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 &gt; KD.Query.Client.ExecuteQueryAsKustoDataStream/d19ed49b-78f6-4f2c-adfc-cf0f6f443bb9 &gt; P.WCF.Service.ExecuteQueryInternalAsKustoDataStream..IClientServiceCommunicationContract/de01e770-e291-4f10-bf9e-a34978193451 &gt; 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': &quot;Syntax error: Query could not be parsed: SYN0002: A recognition error occurred. [line:position=5:17]. Query: 'declare query_parameters(env:string,\n</p>
  </blockquote>
  <p>I have replaced some of the sensitive fields for privacy reasons. My Kusto related question is, is this even the right way to do such a thing? The kusto docs are pretty scant when it comes to parameterizing functions, especially in
  corner cases like these. Parameterizing works, without using a  let statement, but using a &quot;declare&quot; statement and &quot;let&quot; statement in conjunction appears to lead to issues.</p>