You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/12/17 12:02:05 UTC
[shardingsphere] branch master updated: Add parser config to
CalciteContextFactory (#8672)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 93764d3 Add parser config to CalciteContextFactory (#8672)
93764d3 is described below
commit 93764d371ee1d56eb973fe19f6074f48980af0f3
Author: Juan Pan(Trista) <pa...@apache.org>
AuthorDate: Thu Dec 17 20:01:49 2020 +0800
Add parser config to CalciteContextFactory (#8672)
* Add parser config to CalciteContextFactory
* fix pom
* check style
* reverse
* reverse
---
.../shardingsphere-infra-context/pom.xml | 5 +++++
.../shardingsphere-infra-optimize/pom.xml | 2 +-
.../infra/optimize/context/CalciteContext.java | 7 ++++++-
.../infra/optimize/context/CalciteContextFactory.java | 19 ++++++++++++++-----
.../infra/optimize/schema/CalciteSchemaFactory.java | 8 ++++++--
5 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-context/pom.xml b/shardingsphere-infra/shardingsphere-infra-context/pom.xml
index bf5fd97..7e72860 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/pom.xml
+++ b/shardingsphere-infra/shardingsphere-infra-context/pom.xml
@@ -44,6 +44,11 @@
<artifactId>shardingsphere-distsql-parser-engine</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-optimize</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/pom.xml b/shardingsphere-infra/shardingsphere-infra-optimize/pom.xml
index 5d42ee3..36eb447 100644
--- a/shardingsphere-infra/shardingsphere-infra-optimize/pom.xml
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/pom.xml
@@ -31,7 +31,7 @@
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-context</artifactId>
+ <artifactId>shardingsphere-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContext.java b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContext.java
index 0752261..0f29c4d 100644
--- a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContext.java
@@ -26,6 +26,7 @@ import org.apache.calcite.prepare.CalciteCatalogReader;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.schema.Schema;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql.validate.SqlValidatorUtil;
import org.apache.calcite.sql2rel.SqlToRelConverter;
@@ -45,14 +46,18 @@ public final class CalciteContext {
private final CalciteCatalogReader catalogReader;
+ private final SqlParser.Config parserConfig;
+
private final SqlValidator validator;
private final SqlToRelConverter relConverter;
- public CalciteContext(final CalciteConnectionConfig config, final RelDataTypeFactory typeFactory, final RelOptCluster cluster, final Schema calciteSchema) {
+ public CalciteContext(final CalciteConnectionConfig config,
+ final SqlParser.Config parserConfig, final RelDataTypeFactory typeFactory, final RelOptCluster cluster, final Schema calciteSchema) {
rootSchema = CalciteSchema.createRootSchema(true);
rootSchema.add(((CalciteSchema) calciteSchema).name, calciteSchema);
catalogReader = new CalciteCatalogReader(rootSchema, Collections.singletonList(config.schema()), typeFactory, config);
+ this.parserConfig = parserConfig;
validator = SqlValidatorUtil.newValidator(SqlStdOperatorTable.instance(), catalogReader, typeFactory, SqlValidator.Config.DEFAULT
.withLenientOperatorLookup(config.lenientOperatorLookup())
.withSqlConformance(config.conformance())
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactory.java b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactory.java
index 5fe87d9..2a924c8 100644
--- a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactory.java
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/CalciteContextFactory.java
@@ -29,11 +29,13 @@ import org.apache.calcite.plan.volcano.VolcanoPlanner;
import org.apache.calcite.rel.rules.CoreRules;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.SqlParser.Config;
+import org.apache.calcite.sql.parser.impl.SqlParserImpl;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.optimize.schema.CalciteSchemaFactory;
-import java.sql.SQLException;
import java.util.Map;
import java.util.Properties;
@@ -43,7 +45,9 @@ import java.util.Properties;
*/
public final class CalciteContextFactory {
- private final CalciteConnectionConfig config;
+ private final CalciteConnectionConfig connectionConfig;
+
+ private final Config parserConfig;
private final RelDataTypeFactory typeFactory;
@@ -51,8 +55,13 @@ public final class CalciteContextFactory {
private final RelOptCluster cluster;
- public CalciteContextFactory(final Map<String, ShardingSphereMetaData> metaDataMap) throws SQLException {
- config = new CalciteConnectionConfigImpl(createProperties());
+ public CalciteContextFactory(final Map<String, ShardingSphereMetaData> metaDataMap) {
+ connectionConfig = new CalciteConnectionConfigImpl(createProperties());
+ parserConfig = SqlParser.config()
+ .withLex(connectionConfig.lex())
+ .withIdentifierMaxLength(SqlParser.DEFAULT_IDENTIFIER_MAX_LENGTH)
+ .withConformance(connectionConfig.conformance())
+ .withParserFactory(SqlParserImpl.FACTORY);
typeFactory = new JavaTypeFactoryImpl();
factory = new CalciteSchemaFactory(metaDataMap);
cluster = newCluster();
@@ -89,6 +98,6 @@ public final class CalciteContextFactory {
* @return calcite context
*/
public CalciteContext create(final String schema) {
- return new CalciteContext(config, typeFactory, cluster, factory.create(schema));
+ return new CalciteContext(connectionConfig, parserConfig, typeFactory, cluster, factory.create(schema));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/schema/CalciteSchemaFactory.java b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/schema/CalciteSchemaFactory.java
index 0c04782..1928ccc 100644
--- a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/schema/CalciteSchemaFactory.java
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/schema/CalciteSchemaFactory.java
@@ -41,9 +41,13 @@ public final class CalciteSchemaFactory {
private final Map<String, Schema> schemas = new LinkedMap<>();
- public CalciteSchemaFactory(final Map<String, ShardingSphereMetaData> metaDataMap) throws SQLException {
+ public CalciteSchemaFactory(final Map<String, ShardingSphereMetaData> metaDataMap) {
for (Entry<String, ShardingSphereMetaData> each : metaDataMap.entrySet()) {
- schemas.put(each.getKey(), createCalciteSchema(each.getValue()));
+ try {
+ schemas.put(each.getKey(), createCalciteSchema(each.getValue()));
+ } catch (final SQLException ex) {
+ throw new ShardingSphereException(ex);
+ }
}
}