diff --git a/common/src/main/java/com/tencent/supersonic/common/calcite/Configuration.java b/common/src/main/java/com/tencent/supersonic/common/calcite/Configuration.java index 749db0d8f2..516baeccf7 100644 --- a/common/src/main/java/com/tencent/supersonic/common/calcite/Configuration.java +++ b/common/src/main/java/com/tencent/supersonic/common/calcite/Configuration.java @@ -80,6 +80,9 @@ public static SqlParser.Config getParserConfig(EngineType engineType) { .setQuoting(Quoting.SINGLE_QUOTE).setQuotedCasing(Casing.TO_UPPER) .setUnquotedCasing(Casing.TO_UPPER).setConformance(sqlDialect.getConformance()) .setLex(Lex.BIG_QUERY); + if (EngineType.HANADB.equals(engineType)) { + parserConfig = parserConfig.setQuoting(Quoting.DOUBLE_QUOTE); + } parserConfig = parserConfig.setQuotedCasing(Casing.UNCHANGED); parserConfig = parserConfig.setUnquotedCasing(Casing.UNCHANGED); return parserConfig.build(); diff --git a/common/src/main/java/com/tencent/supersonic/common/calcite/SqlDialectFactory.java b/common/src/main/java/com/tencent/supersonic/common/calcite/SqlDialectFactory.java index 1abdb1fd19..c549ce88a4 100644 --- a/common/src/main/java/com/tencent/supersonic/common/calcite/SqlDialectFactory.java +++ b/common/src/main/java/com/tencent/supersonic/common/calcite/SqlDialectFactory.java @@ -21,6 +21,10 @@ public class SqlDialectFactory { .withDatabaseProduct(DatabaseProduct.BIG_QUERY).withLiteralQuoteString("'") .withLiteralEscapedQuoteString("''").withUnquotedCasing(Casing.UNCHANGED) .withQuotedCasing(Casing.UNCHANGED).withCaseSensitive(false); + public static final Context HANADB_CONTEXT = SqlDialect.EMPTY_CONTEXT + .withDatabaseProduct(DatabaseProduct.BIG_QUERY).withLiteralQuoteString("'") + .withIdentifierQuoteString("\"").withLiteralEscapedQuoteString("''").withUnquotedCasing(Casing.UNCHANGED) + .withQuotedCasing(Casing.UNCHANGED).withCaseSensitive(true); private static Map sqlDialectMap; static { @@ -29,6 +33,7 @@ public class SqlDialectFactory { sqlDialectMap.put(EngineType.MYSQL, new SemanticSqlDialect(DEFAULT_CONTEXT)); sqlDialectMap.put(EngineType.H2, new SemanticSqlDialect(DEFAULT_CONTEXT)); sqlDialectMap.put(EngineType.POSTGRESQL, new SemanticSqlDialect(POSTGRESQL_CONTEXT)); + sqlDialectMap.put(EngineType.HANADB, new SemanticSqlDialect(HANADB_CONTEXT)); } public static SemanticSqlDialect getSqlDialect(EngineType engineType) { diff --git a/common/src/main/java/com/tencent/supersonic/common/pojo/enums/EngineType.java b/common/src/main/java/com/tencent/supersonic/common/pojo/enums/EngineType.java index 7acd72ed12..8b70cf97a4 100644 --- a/common/src/main/java/com/tencent/supersonic/common/pojo/enums/EngineType.java +++ b/common/src/main/java/com/tencent/supersonic/common/pojo/enums/EngineType.java @@ -9,7 +9,8 @@ public enum EngineType { H2(5, "h2"), POSTGRESQL(6, "postgresql"), OTHER(7, "other"), - DUCKDB(8, "duckdb"); + DUCKDB(8, "duckdb"), + HANADB(9, "hanadb"); private Integer code; diff --git a/headless/core/src/main/java/com/tencent/supersonic/headless/core/adaptor/db/DbAdaptorFactory.java b/headless/core/src/main/java/com/tencent/supersonic/headless/core/adaptor/db/DbAdaptorFactory.java index c8e0aa582c..0145688529 100644 --- a/headless/core/src/main/java/com/tencent/supersonic/headless/core/adaptor/db/DbAdaptorFactory.java +++ b/headless/core/src/main/java/com/tencent/supersonic/headless/core/adaptor/db/DbAdaptorFactory.java @@ -17,6 +17,7 @@ public class DbAdaptorFactory { dbAdaptorMap.put(EngineType.POSTGRESQL.getName(), new PostgresqlAdaptor()); dbAdaptorMap.put(EngineType.OTHER.getName(), new DefaultDbAdaptor()); dbAdaptorMap.put(EngineType.DUCKDB.getName(), new DuckdbAdaptor()); + dbAdaptorMap.put(EngineType.HANADB.getName(), new HanadbAdaptor()); } public static DbAdaptor getEngineAdaptor(String engineType) { diff --git a/headless/core/src/main/java/com/tencent/supersonic/headless/core/adaptor/db/HanadbAdaptor.java b/headless/core/src/main/java/com/tencent/supersonic/headless/core/adaptor/db/HanadbAdaptor.java new file mode 100644 index 0000000000..55aaf4f39b --- /dev/null +++ b/headless/core/src/main/java/com/tencent/supersonic/headless/core/adaptor/db/HanadbAdaptor.java @@ -0,0 +1,13 @@ +package com.tencent.supersonic.headless.core.adaptor.db; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class HanadbAdaptor extends DefaultDbAdaptor { + + @Override + public String rewriteSql(String sql) { + return sql.replaceAll("`", "\""); + } + +} diff --git a/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/DbParameterFactory.java b/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/DbParameterFactory.java index 957da1463f..072023a420 100644 --- a/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/DbParameterFactory.java +++ b/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/DbParameterFactory.java @@ -15,6 +15,7 @@ public class DbParameterFactory { parametersBuilder.put(EngineType.CLICKHOUSE.getName(), new ClickHouseParametersBuilder()); parametersBuilder.put(EngineType.MYSQL.getName(), new MysqlParametersBuilder()); parametersBuilder.put(EngineType.POSTGRESQL.getName(), new PostgresqlParametersBuilder()); + parametersBuilder.put(EngineType.HANADB.getName(), new HanadbParametersBuilder()); parametersBuilder.put(EngineType.OTHER.getName(), new OtherParametersBuilder()); } diff --git a/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/HanadbParametersBuilder.java b/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/HanadbParametersBuilder.java new file mode 100644 index 0000000000..145b758a6a --- /dev/null +++ b/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/HanadbParametersBuilder.java @@ -0,0 +1,16 @@ +package com.tencent.supersonic.headless.server.pojo; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@Slf4j +public class HanadbParametersBuilder extends DefaultParametersBuilder { + + @Override + public List build() { + return super.build(); + } +}