tnakama created CALCITE-7922:
--------------------------------

             Summary: Support BigQuery-style raw string literals
                 Key: CALCITE-7922
                 URL: https://issues.apache.org/jira/browse/CALCITE-7922
             Project: Calcite
          Issue Type: New Feature
          Components: core
            Reporter: tnakama


Support BigQuery-style raw string literals when the parser uses 
{{Lex.BIG_QUERY}}.

GoogleSQL accepts a case-insensitive {{r}} prefix on string literals. 
Backslashes and the following characters are preserved instead of being 
decoded. This is useful for regular expression patterns and other strings 
containing backslashes.

h3. Current behavior
The released {{calcite-core:1.42.0}} parser rejects raw string literals. For 
example:
{code:java}
import org.apache.calcite.config.Lex;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.validate.SqlConformanceEnum;

var config = SqlParser.config()
    .withLex(Lex.BIG_QUERY)
    .withConformance(SqlConformanceEnum.BIG_QUERY);
SqlParser.create("SELECT r'\\d+'", config).parseQuery();
// Actual: SqlParseException
// Expected: a character literal with value "\\d+"
{code}

h3. Examples and expected values
These examples are SQL source text, not Java string literals.
{noformat}
SELECT r'\d+';        -- backslash + d + plus
SELECT r'\n';         -- backslash + n, not a newline
SELECT R"a\b";        -- a + backslash + b
SELECT r'it\'s';      -- i + t + backslash + quote + s
SELECT r'trailing\\'; -- ends with two backslashes
{noformat}

h3. Proposed initial scope
* Accept both {{r}} and {{R}} prefixes with single- and double-quoted strings.
* Preserve backslashes, including the backslash used before an enclosed quote.
* Reject literals ending with an odd number of backslashes and other invalid 
quote delimiters, according to GoogleSQL rules.
* Keep ordinary character literals and other lexical policies unchanged.
* Verify parsed values and their use as function arguments, including regular 
expressions.

GoogleSQL also supports triple-quoted raw strings and raw bytes. Those 
extensions, along with literal concatenation, can be scoped separately rather 
than being prerequisites for the initial single-/double-quoted string support.

h3. Relation to existing issues
CALCITE-7921 tracks decoding backslash escapes in existing ordinary BigQuery 
string literals. Raw literals add separate syntax and preserve their contents, 
so they are tracked here as a distinct feature.

CALCITE-2406 concerns implicit timestamp conversion of ordinary MySQL strings 
and is unrelated to the {{r}} prefix.

h3. Reference
https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/lexical#string_and_bytes_literals




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

Reply via email to