Nadav Har'El created CASSANDRA-21783:
----------------------------------------

             Summary: DESCRIBE FUNCTION output cannot re-create a function 
whose body contains "$$" or ends with "$"
                 Key: CASSANDRA-21783
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-21783
             Project: Apache Cassandra
          Issue Type: Bug
            Reporter: Nadav Har'El


DESCRIBE FUNCTION (and so DESCRIBE KEYSPACE / DESCRIBE SCHEMA) always prints a 
UDF's body as a pg-style (dollar-quoted) string literal, $$...$$ 
(UDFunction.toCqlString). Such a literal has no escape sequences: it ends at 
the first "$$", and a "$" just before the closing "$$" is a syntax error (see 
also CASSANDRA-13958). So when a function's body contains "$$", or ends with 
"$", executing the output of DESCRIBE fails - or, for a body containing "$$", 
ends the body early, and the rest of the body is parsed as CQL.

Such bodies can be created with a single-quoted literal. Reproducer, tested on 
Cassandra 5.0.9 and 6.0-alpha2:
{code:java}
CREATE FUNCTION ks.f(x text) RETURNS NULL ON NULL INPUT RETURNS text
    LANGUAGE java AS 'return x + "$$";';
DESCRIBE FUNCTION ks.f;
{code}
prints {{{}AS $$return x + "$$";$$;{}}}. Executing that output (after DROP 
FUNCTION ks.f) fails with
{noformat}
SyntaxException: line 5:28 mismatched character '<EOF>' expecting '"'
{noformat}
Similarly, the body {{return x; // $}} is printed as {{{}AS $$return x; // 
$$$;{}}}, which fails with
{noformat}
SyntaxException: line 5:25 mismatched character ';' expecting '$'
{noformat}
A possible fix: print the body as a single-quoted literal (with single quotes 
doubled) when it contains "$$" or ends with "$", and keep $$...$$ for all other 
bodies. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to