[ 
https://issues.apache.org/jira/browse/CAMEL-26105?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-26105.
---------------------------------
    Resolution: Fixed

> camel-aws2-athena - take the SQL from the body only with useMessageBodyForSql
> -----------------------------------------------------------------------------
>
>                 Key: CAMEL-26105
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26105
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-aws2
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 4.18.6, 4.22.3, 4.24.0
>
>
> h3. Behaviour today
> The {{startQueryExecution}} operation (the default operation of the 
> aws2-athena producer) takes the SQL from the message body first, then from 
> the {{CamelAwsAthenaQueryString}} header, and from the {{queryString}} 
> endpoint option only when both are empty 
> ({{Athena2Producer.determineQueryString}}).
> So an endpoint that is configured with {{queryString}} does not run that 
> query whenever the message has a body: it runs the text of the body instead. 
> Examples are the {{GetQueryExecutionResponse}} that an earlier 
> {{startQueryExecution}} with {{waitTimeout}} leaves as the body, or a {{Map}} 
> body, whose {{toString()}} is sent as the query. The documentation does not 
> state this order, and the option description says to prefer setting the SQL 
> as the body.
> In addition, with {{includeTrace=true}} the SQL comment contains the URI of 
> the from endpoint as is, without the masking Camel applies to endpoint URIs 
> elsewhere, and it fails with a {{NullPointerException}} when the exchange has 
> no from endpoint (for example an exchange built by hand).
> h3. Behaviour after the change
> * A new producer option {{useMessageBodyForSql}} (boolean, default 
> {{false}}), in line with the option of the same name in camel-sql.
> * When it is {{false}}, the SQL comes from the {{CamelAwsAthenaQueryString}} 
> header, else from the {{queryString}} option. The message body is not used. 
> When neither is set, the error names the {{queryString}} option, the header 
> and {{useMessageBodyForSql}}, so a route that relied on the body fails with a 
> clear message.
> * When it is {{true}}, the order stays as today: body, then header, then 
> option.
> * With {{includeTrace=true}}, the from endpoint URI is written with 
> {{URISupport.sanitizeUri}}, and it is left out when the exchange has no from 
> endpoint.
> h3. Code changes
> * {{Athena2Configuration}}: add {{useMessageBodyForSql}} ({{@UriParam(label = 
> "producer", defaultValue = "false")}}) with getter and setter; reword the 
> {{queryString}} description (header overrides the option; the body is used 
> only with {{useMessageBodyForSql}}).
> * {{Athena2Producer.determineQueryString}}: read the body only when 
> {{isUseMessageBodyForSql()}} is true; clearer error message; sanitized trace 
> comment and a null check on the from endpoint.
> * {{Athena2Constants}}: reword the description of {{QUERY_STRING}}.
> * {{aws2-athena-component.adoc}}: the examples that set the SQL with 
> {{setBody}} (Java, XML and YAML) also set {{useMessageBodyForSql=true}}, plus 
> a short section on where the SQL comes from.
> * Regenerated files: component JSON, configurers, 
> {{Athena2EndpointUriFactory}}, endpoint DSL and component DSL, catalog JSON 
> and doc.
> * Upgrade guide 4.24: routes that put the SQL in the message body must set 
> {{useMessageBodyForSql=true}}. Upgrade guide sections 4.22.3 and 4.18.6: a 
> route that sets {{queryString}} or the {{CamelAwsAthenaQueryString}} header 
> and also has a message body now runs that query, not the body.
> h3. Tests
> * {{AmazonAthenaClientMock}} keeps the last {{StartQueryExecutionRequest}}.
> * New {{Athena2ProducerQueryStringTest}}: the {{queryString}} option is used 
> when the body is set; the header overrides the option; no query fails with a 
> message naming {{useMessageBodyForSql}}; the body is used when 
> {{useMessageBodyForSql}} is enabled; with the option enabled and an empty 
> body the header is used; the response of an earlier step is not sent as the 
> query; the trace comment holds the sanitized from endpoint URI; the trace 
> comment works without a from endpoint.
> * {{AthenaComponentTest}} and {{AthenaComponentManualIT}} send the SQL in the 
> body, so their endpoints set {{useMessageBodyForSql=true}}.
> * {{AthenaComponentConfigurationTest}} covers the new option.
> h3. Backports
> Backport to 4.22.x and 4.18.x without the new option:
> * the {{CamelAwsAthenaQueryString}} header, then the {{queryString}} option, 
> then the body;
> * routes that put the SQL in the message body keep working;
> * the change of the trace comment goes along.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to