Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/qe/SessionVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@ public static MaterializedViewRewriteMode parse(String str) {

public static final String SQL_DIALECT = "sql_dialect";

// Is Trino dialect downgraded to Starrocks
public static final String ENABLE_DIALECT_DOWNGRADE ="enable_dialect_downgrade";

public static final String ENABLE_OUTER_JOIN_REORDER = "enable_outer_join_reorder";

public static final String CBO_REORDER_THRESHOLD_USE_EXHAUSTIVE = "cbo_reorder_threshold_use_exhaustive";
Expand Down Expand Up @@ -1898,6 +1901,9 @@ public long getConnectorSinkTargetMaxFileSize() {
@VarAttr(name = SQL_DIALECT)
private String sqlDialect = "StarRocks";

@VarAttr(name = ENABLE_DIALECT_DOWNGRADE)
private boolean enableDialectDowngrade = true;

@VarAttr(name = ENABLE_OUTER_JOIN_REORDER)
private boolean enableOuterJoinReorder = true;

Expand Down Expand Up @@ -3711,6 +3717,14 @@ public void setSqlDialect(String dialect) {
this.sqlDialect = dialect;
}

public boolean isEnableDialectDowngrade() {
return enableDialectDowngrade;
}

public void setEnableDialectDowngrade(boolean enableDialectDowngrade) {
this.enableDialectDowngrade = enableDialectDowngrade;
}

public boolean isEnableOuterJoinReorder() {
return enableOuterJoinReorder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,26 @@ private static List<StatementBase> parseWithTrinoDialect(String sql, SessionVari
// In Trino parser AstBuilder, it could throw ParsingException for unexpected exception,
// use StarRocks parser to parse now.
LOG.warn("Trino parse sql [{}] error, cause by {}", sql, e);
return tryParseWithStarRocksDialect(sql, sessionVariable, e);
if (sessionVariable.isEnableDialectDowngrade()) {
return tryParseWithStarRocksDialect(sql, sessionVariable, e);
}
throw e;
} catch (io.trino.sql.parser.ParsingException e) {
// This sql does not use Trino syntax,use StarRocks parser to parse now.
if (sql.toLowerCase().contains("select")) {
LOG.warn("Trino parse sql [{}] error, cause by {}", sql, e);
}
return tryParseWithStarRocksDialect(sql, sessionVariable, e);
if (sessionVariable.isEnableDialectDowngrade()) {
return tryParseWithStarRocksDialect(sql, sessionVariable, e);
}
throw e;
} catch (TrinoParserUnsupportedException e) {
// We only support Trino partial syntax now, and for Trino parser unsupported statement,
// try to use StarRocks parser to parse
return tryParseWithStarRocksDialect(sql, sessionVariable, e);
if (sessionVariable.isEnableDialectDowngrade()) {
return tryParseWithStarRocksDialect(sql, sessionVariable, e);
}
throw e;
} catch (UnsupportedException e) {
// For unsupported statement, it can not be parsed by trino or StarRocks parser, both parser
// can not support it now, we just throw the exception here to give user more information
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.starrocks.connector.parser.trino;
import com.starrocks.sql.ast.QueryStatement;

Check failure on line 16 in fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoDialectDowngradeTest.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Unused import - com.starrocks.sql.ast.QueryStatement. Raw Output: /github/workspace/./fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoDialectDowngradeTest.java:16:8: error: Unused import - com.starrocks.sql.ast.QueryStatement. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import com.starrocks.sql.parser.SqlParser;

Check failure on line 17 in fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoDialectDowngradeTest.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Unused import - com.starrocks.sql.parser.SqlParser. Raw Output: /github/workspace/./fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoDialectDowngradeTest.java:17:8: error: Unused import - com.starrocks.sql.parser.SqlParser. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import org.junit.BeforeClass;
import org.junit.Test;

public class TrinoDialectDowngradeTest extends TrinoTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
TrinoTestBase.beforeClass();
}

@Test
public void testTrinoDialectDowngrade() throws Exception {
String querySql = "select date_add('2010-11-30 23:59:59', INTERVAL 2 DAY);";
try {
connectContext.getSessionVariable().setEnableDialectDowngrade(true);
connectContext.getSessionVariable().setSqlDialect("trino");
analyzeSuccess(querySql);
connectContext.getSessionVariable().setEnableDialectDowngrade(false);
analyzeFail(querySql, "mismatched input '2'. Expecting: '+', '-', <string>");
} finally {
connectContext.getSessionVariable().setSqlDialect("trino");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static void analyzeFail(String originStmt, String exceptMessage) {
connectContext.getSessionVariable()).get(0);
Analyzer.analyze(statementBase, connectContext);
Assert.fail("Miss semantic error exception");
} catch (ParsingException | StarRocksPlannerException e) {
} catch (ParsingException | StarRocksPlannerException | io.trino.sql.parser.ParsingException e) {
if (!exceptMessage.equals("")) {
Assert.assertTrue(e.getMessage(), e.getMessage().contains(exceptMessage));
}
Expand Down
Loading