From 912bb670521106c2851b2346ee9f0161c1065c8b Mon Sep 17 00:00:00 2001 From: "Limian (Raymond) Zhang" Date: Tue, 7 Nov 2023 15:27:06 -0700 Subject: [PATCH] =?UTF-8?q?[Partial=20Backport]=20partially=20backport=20C?= =?UTF-8?q?ALCITE-3823=20to=20make=20quoteIdent=E2=80=A6=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Partial Backport] partially backport CALCITE-3823 to make quoteIdentifier use identifierNeedsQuote() * update --- .../java/org/apache/calcite/sql/SqlDialect.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java index bd88560fd..7dea05099 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java @@ -334,14 +334,7 @@ public RelDataTypeSystem getTypeSystem() { * @return Quoted identifier */ public String quoteIdentifier(String val) { - if (identifierQuoteString == null) { - return val; // quoting is not supported - } - String val2 = - val.replaceAll( - identifierEndQuoteString, - identifierEscapedQuote); - return identifierQuoteString + val2 + identifierEndQuoteString; + return quoteIdentifier(new StringBuilder(), val).toString(); } /** @@ -360,15 +353,13 @@ public StringBuilder quoteIdentifier( StringBuilder buf, String val) { if (identifierQuoteString == null // quoting is not supported + || identifierEndQuoteString == null + || identifierEscapedQuote == null || !identifierNeedsQuote(val)) { buf.append(val); } else { - String val2 = - val.replaceAll( - identifierEndQuoteString, - identifierEscapedQuote); buf.append(identifierQuoteString); - buf.append(val2); + buf.append(val.replace(identifierEndQuoteString, identifierEscapedQuote)); buf.append(identifierEndQuoteString); } return buf;