Claus Ibsen created CAMEL-24801:
-----------------------------------
Summary: camel-sql - sql-stored: allow parentheses inside ${...}
simple expressions in the template grammar
Key: CAMEL-24801
URL: https://issues.apache.org/jira/browse/CAMEL-24801
Project: Camel
Issue Type: Improvement
Components: camel-sql
Reporter: Claus Ibsen
The sql-stored template grammar
({{components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj}})
rejects simple functions inside {{${...}}} parameters because the
{{SIMPLE_EXP_TOKEN}} character set does not include parentheses:
{code}
<SIMPLE_EXP_TOKEN: "${"(<LETTER>|<DIGIT> | <SPECIAL> | " ")+ "}">
<#SPECIAL: ([":","#","_","-","'",".","$","{","}","\"","[","]"])>
{code}
This works:
{code}
sql-stored:SCH_GetCalendarForPeriod( TIMESTAMP :#startDate, TIMESTAMP
:#endDate, INTEGER ${header.notType})
{code}
This fails:
{code}
sql-stored:SCH_GetCalendarForPeriod( TIMESTAMP :#startDate, TIMESTAMP
:#endDate, INTEGER ${val(1)})
{code}
with
{noformat}
org.apache.camel.component.sql.stored.template.ast.ParseRuntimeException:
org.apache.camel.component.sql.stored.template.generated.ParseException:
Encountered " <IDENTIFIER> "${val "" at line 1, column 83. Was expecting one
of: <SIMPLE_EXP_TOKEN> ... <PARAMETER_POS_TOKEN> ... <PARAMETER_NAME> ...
{noformat}
Since {{$}} and {{{}} are in {{SPECIAL}}, the lexer falls back to matching
{{${val}} as an {{IDENTIFIER}} and then chokes on {{(}}. The evaluation side is
not the problem: {{InParameter}} / {{InOutParameter}} hand the whole token
string to the simple language, so any function would work once it gets through
the lexer.
Proposal: add {{(}} and {{)}} to the {{SIMPLE_EXP_TOKEN}} character set. This
is safe with JavaCC longest-match because the token must end with {{}}}, so
{{${val(1)})}} stops at the {{}}} before the procedure's closing parenthesis.
It enables single-argument built-in functions such as {{${val(1)}}},
{{${bodyAs(String)}}}, and custom simple functions taking one argument.
Scope: this is deliberately *not* full simple support. Commas cannot be added
to the token (longest match would turn {{${a}, INTEGER ${b}}} into one token),
so multi-argument functions like {{${replace(a,b)}}} and nested functions
remain unsupported in the template. Users needing those should compute the
value into a header first and reference it with {{${header.xxx}}}.
Add test cases to {{ParserTest}} / {{TemplateParserLexicalErrorTest}} and
document the supported subset in the sql-stored component docs.
Reported by a user on Zulip.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)