From 2aa9ef140d6e6a9524df0d56100f228bd3a7c89b Mon Sep 17 00:00:00 2001 From: kge Date: Thu, 10 Mar 2022 16:26:57 -0500 Subject: [PATCH 1/2] Replacing backquotes with equivalent double quotes to fix Trino SqlParser exitBackQuotedIdentifier error --- .../linkedin/coral/trino/trino2rel/TrinoToRelConverter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoToRelConverter.java b/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoToRelConverter.java index d306d8392..7b988bece 100644 --- a/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoToRelConverter.java +++ b/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoToRelConverter.java @@ -83,7 +83,7 @@ protected SqlToRelConverter getSqlToRelConverter() { @Override protected SqlNode toSqlNode(String sql, Table trinoView) { - String trimmedSql = trimParenthesis(sql.toUpperCase()); + String trimmedSql = trimParenthesis(standardizeSql(sql)); SqlNode parsedSqlNode = PrestoParserDriver.parse(trimmedSql).accept(parseTreeBuilder, parserVisitorContext); SqlNode convertedSqlNode = parsedSqlNode.accept(new Trino2CoralOperatorConverter()); return convertedSqlNode; @@ -94,6 +94,10 @@ protected RelNode standardizeRel(RelNode relNode) { return relNode; } + private static String standardizeSql(String sql) { + return sql.toUpperCase().replaceAll("`", "\""); + } + private static String trimParenthesis(String value) { String str = value.trim(); if (str.startsWith("(") && str.endsWith(")")) { From c107a7f11567d531c9cdf5e2a6efc9547abec561 Mon Sep 17 00:00:00 2001 From: kge Date: Thu, 10 Mar 2022 17:51:16 -0500 Subject: [PATCH 2/2] Union of standardizeSql --- .../trino/trino2rel/TrinoToRelConverter.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoToRelConverter.java b/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoToRelConverter.java index 7b988bece..a17fb0764 100644 --- a/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoToRelConverter.java +++ b/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoToRelConverter.java @@ -83,7 +83,7 @@ protected SqlToRelConverter getSqlToRelConverter() { @Override protected SqlNode toSqlNode(String sql, Table trinoView) { - String trimmedSql = trimParenthesis(standardizeSql(sql)); + String trimmedSql = standardizeSql(sql); SqlNode parsedSqlNode = PrestoParserDriver.parse(trimmedSql).accept(parseTreeBuilder, parserVisitorContext); SqlNode convertedSqlNode = parsedSqlNode.accept(new Trino2CoralOperatorConverter()); return convertedSqlNode; @@ -94,16 +94,15 @@ protected RelNode standardizeRel(RelNode relNode) { return relNode; } - private static String standardizeSql(String sql) { - return sql.toUpperCase().replaceAll("`", "\""); - } - - private static String trimParenthesis(String value) { + /* + * Standardizing Sql to ensure compatability with Sql Parser. + */ + private static String standardizeSql(String value) { String str = value.trim(); if (str.startsWith("(") && str.endsWith(")")) { - return trimParenthesis(str.substring(1, str.length() - 1)); + return standardizeSql(str.substring(1, str.length() - 1)); } - return str; + return str.toUpperCase().replaceAll("`", "\""); } }