Search code examples
kqlazure-data-explorerdata-ingestionadxkusto-java-sdk

How does one specify query parameters when performing an inline ingestion in the Azure Data Explorer Java SDK?


I am trying to perform an inline ingestion into an ADX table (using the Java SDK) and although there is no exception thrown at the time I execute the command, no rows are returned and the ingestion receives an error message:

Stream_WrongNumberOfFields: hr: '2161770504' 'CSV error: record 4 (line: 5, byte: 179): found record with 4 fields, but the previous record has 1 fields'

Note that the error message comes when trying to ingest into a table that has no records.

I tried initially using the default ingestion policy but then tried adding an explicit policy to see if that helped (it didn't). I am invoking this via the Java SDK, however, I can demonstrate the error in the web UI. Here is the kql code I am running:

.ingest inline into table MyTable
with (
format = "csv",
ingestionMappingReference = "MyMapping"
) <|
declare query_parameters(field1:string);                                                                                                                                                                     
declare query_parameters(field2:string);                                                                                                                                                                     
declare query_parameters(field3:string);                                                                                                                                                                     
declare query_parameters(timeField:string);                                                                                                                                                                  
[field1, field2, field3, timeField]

This statement succeeds if I remove the declare statements, and I am guessing that it is somehow interpreting those lines as part of the inline ingestion (I have tried with and without the square brackets), however I get an error if I move the declare statements earlier in the expression.


Solution

  • query parameters, as their name implies, can only be used in queries, and not in control commands. .ingest is a control command.

    regardless, and specifically regarding the .ingest inline command - its input ([field1, field2, field3, timeField] in your example) is parsed according to the format specified (e.g. csv in your example). you can't use references to variables or parameters there.