This is an automated email from the ASF dual-hosted git repository.
chengzhang 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 e669f1c6083 Remove useless antlr parse and visit logic in sql
federation module (#26757)
e669f1c6083 is described below
commit e669f1c60834ed3990b889d8187f4f2cf6b3ebc8
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Jul 4 16:46:46 2023 +0800
Remove useless antlr parse and visit logic in sql federation module (#26757)
---
kernel/sql-federation/core/pom.xml | 27 --
.../src/main/antlr4/imports/rexnode/Alphabet.g4 | 50 ---
.../src/main/antlr4/imports/rexnode/Keyword.g4 | 42 ---
.../src/main/antlr4/imports/rexnode/Literals.g4 | 62 ----
.../core/src/main/antlr4/imports/rexnode/Symbol.g4 | 42 ---
.../rexnode/autogen/SQLOptimizerRexNode.g4 | 84 -----
.../enumerable/EnumerableScanExecutor.java | 7 -
.../executor/row/SQLFederationRowEnumerator.java | 1 -
.../executor/util/SQLOptimizerRexNodeVisitor.java | 342 ---------------------
.../executor/util/StringToRexNodeUtils.java | 59 ----
10 files changed, 716 deletions(-)
diff --git a/kernel/sql-federation/core/pom.xml
b/kernel/sql-federation/core/pom.xml
index e937238460b..0e4477d57bb 100644
--- a/kernel/sql-federation/core/pom.xml
+++ b/kernel/sql-federation/core/pom.xml
@@ -193,32 +193,5 @@
</plugins>
</build>
</profile>
- <profile>
- <id>jdk11+</id>
- <activation>
- <jdk>[11,)</jdk>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>antlr</id>
- <goals>
- <goal>antlr4</goal>
- </goals>
- <configuration>
-
<libDirectory>src/main/antlr4/imports/rexnode/</libDirectory>
- <listener>false</listener>
- <visitor>true</visitor>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
</profiles>
</project>
diff --git
a/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Alphabet.g4
b/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Alphabet.g4
deleted file mode 100644
index 8f6584c3692..00000000000
--- a/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Alphabet.g4
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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.
- */
-
-lexer grammar Alphabet;
-
-FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR';
-
-fragment A: [Aa];
-fragment B: [Bb];
-fragment C: [Cc];
-fragment D: [Dd];
-fragment E: [Ee];
-fragment F: [Ff];
-fragment G: [Gg];
-fragment H: [Hh];
-fragment I: [Ii];
-fragment J: [Jj];
-fragment K: [Kk];
-fragment L: [Ll];
-fragment M: [Mm];
-fragment N: [Nn];
-fragment O: [Oo];
-fragment P: [Pp];
-fragment Q: [Qq];
-fragment R: [Rr];
-fragment S: [Ss];
-fragment T: [Tt];
-fragment U: [Uu];
-fragment V: [Vv];
-fragment W: [Ww];
-fragment X: [Xx];
-fragment Y: [Yy];
-fragment Z: [Zz];
-fragment UL_: '_';
-fragment ML_: '-';
-fragment EIGHT_: '8';
diff --git
a/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Keyword.g4
b/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Keyword.g4
deleted file mode 100644
index 5bf0a0ee6ba..00000000000
--- a/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Keyword.g4
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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.
- */
-
-lexer grammar Keyword;
-
-import Alphabet;
-
-SEARCH: S E A R C H;
-
-LIKE: L I K E;
-
-INTEGER: I N T E G E R;
-
-BIGINT: B I G I N T;
-
-VARCHAR: V A R C H A R;
-
-DATE: D A T E;
-
-CAST: C A S T;
-
-SARG: S A R G;
-
-OR: O R;
-
-AND: A N D;
-
-NOT: N O T;
diff --git
a/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Literals.g4
b/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Literals.g4
deleted file mode 100644
index 559da392969..00000000000
--- a/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Literals.g4
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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.
- */
-
-lexer grammar Literals;
-
-import Alphabet, Symbol;
-
-PLACEHOLDER_
- : QUESTION_ INTEGER_
- ;
-
-STRING_
- : (DQ_ ( '\\'. | '""' | ~('"'| '\\') )* DQ_) | (SQ_ ('\\'. | '\'\'' |
~('\'' | '\\'))* SQ_)
- ;
-
-INTEGER_
- : INT_
- ;
-
-DATE_
- : YEAR_ MINUS_ MONTH_ MINUS_ DAY_
- ;
-
-NEGETIVE_INFINITY_: '-∞';
-
-POSITIVE_INFINITY_: '+∞';
-
-INT_
- : [0-9]+
- ;
-
-HEX_
- : [0-9a-fA-F]
- ;
-
-YEAR_
- : [0-9]+
- ;
-
-MONTH_
- : [0-9]+
- ;
-DAY_
- : [0-9]+
- ;
-
-UTF_: UL_ U T F ML_ EIGHT_;
-
diff --git
a/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Symbol.g4
b/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Symbol.g4
deleted file mode 100644
index 11a6ec3bac2..00000000000
--- a/kernel/sql-federation/core/src/main/antlr4/imports/rexnode/Symbol.g4
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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.
- */
-
-lexer grammar Symbol;
-
-EQ_: '=';
-NEQ_: '<>' | '!=' | '^=';
-GT_: '>';
-GTE_: '>=';
-LT_: '<';
-LTE_: '<=';
-LP_: '(';
-RP_: ')';
-LBE_: '{';
-RBE_: '}';
-LBT_: '[';
-RBT_: ']';
-COMMA_: ',';
-DQ_: '"';
-SQ_ : '\'';
-DOLLAR_: '$';
-COLON_: ':';
-RANGE_: '..';
-NEGETIVE_INFINITY_: '-∞';
-POSITIVE_INFINITY_: '+∞';
-QUESTION_: '?';
-MINUS_: '-';
-DOT_: '.';
diff --git
a/kernel/sql-federation/core/src/main/antlr4/org/apache/shardingsphere/rexnode/autogen/SQLOptimizerRexNode.g4
b/kernel/sql-federation/core/src/main/antlr4/org/apache/shardingsphere/rexnode/autogen/SQLOptimizerRexNode.g4
deleted file mode 100644
index e0bcfa13fe7..00000000000
---
a/kernel/sql-federation/core/src/main/antlr4/org/apache/shardingsphere/rexnode/autogen/SQLOptimizerRexNode.g4
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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.
- */
-
-grammar SQLOptimizerRexNode;
-
-import Symbol, Keyword, Literals;
-
-expression
- : op LP_ parameter COMMA_ parameter RP_
- ;
-
-parameter
- : input | expression
- ;
-
-input
- : inputRef | searchArgs | constant | cast | paramWithType
- ;
-
-inputRef
- : DOLLAR_ INTEGER_
- ;
-
-searchArgs
- : SARG LBT_ (argRange | argList | argRangeList) RBT_
- ;
-
-constant
- : INTEGER_ | STRING_ | PLACEHOLDER_ | DATE_ | string_zh
- ;
-
-cast
- : CAST LP_ inputRef RP_ COLON_ type
- ;
-
-paramWithType
- : (STRING_|INTEGER_|DATE_) COLON_ type
- ;
-
-op
- : SEARCH | LIKE | OR | NOT | AND | EQ_ | NEQ_ | GT_ | GTE_ | LT_ | LTE_
- ;
-
-argRange
- : LP_ (NEGETIVE_INFINITY_|INTEGER_) RANGE_ (INTEGER_|POSITIVE_INFINITY_)
RP_ | LBT_ INTEGER_ RANGE_ INTEGER_ RBT_
- ;
-
-argList
- : (LP_|LBT_)? INTEGER_ (COMMA_ INTEGER_)* (RP_|RBT_)?
- ;
-
-argRangeList
- : argRange (COMMA_ argRange)*
- ;
-
-type
- : BIGINT | INTEGER | VARCHAR | DATE | VARCHAR_ZH
- ;
-
-string_zh
- : UTF_ STRING_
- ;
-
-VARCHAR_ZH
- : VARCHAR (('\\'. | '""' | ~('"'| '\\' | ','))* | ('\\'. | '\'\'' | ~('\''
| '\\' | ','))*)
- ;
-
-WS
- : [ \t]+ -> skip
- ;
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
index 2ba772bc30c..f8ac2cdfd68 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
@@ -19,8 +19,6 @@ package
org.apache.shardingsphere.sqlfederation.executor.enumerable;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
-import org.apache.calcite.adapter.java.JavaTypeFactory;
-import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.linq4j.AbstractEnumerable;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Enumerator;
@@ -74,7 +72,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
-import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@@ -83,10 +80,6 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public final class EnumerableScanExecutor {
- private static final JavaTypeFactory JAVA_TYPE_FACTORY = new
JavaTypeFactoryImpl();
-
- private static final Pattern COLUMN_INFORMATION_PATTERN =
Pattern.compile("\\{.*}");
-
private final DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection>
prepareEngine;
private final JDBCExecutor jdbcExecutor;
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/row/SQLFederationRowEnumerator.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/row/SQLFederationRowEnumerator.java
index 4b787bb96e1..844b2c6b88d 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/row/SQLFederationRowEnumerator.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/row/SQLFederationRowEnumerator.java
@@ -71,7 +71,6 @@ public final class SQLFederationRowEnumerator implements
Enumerator<Object> {
@Override
public void reset() {
- System.out.println("reset");
}
@Override
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/util/SQLOptimizerRexNodeVisitor.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/util/SQLOptimizerRexNodeVisitor.java
deleted file mode 100644
index a21d5d14103..00000000000
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/util/SQLOptimizerRexNodeVisitor.java
+++ /dev/null
@@ -1,342 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.shardingsphere.sqlfederation.executor.util;
-
-import com.google.common.collect.BoundType;
-import com.google.common.collect.ImmutableRangeSet;
-import com.google.common.collect.Range;
-import com.google.common.collect.RangeSet;
-import com.google.common.collect.TreeRangeSet;
-import lombok.AllArgsConstructor;
-import org.antlr.v4.runtime.tree.TerminalNode;
-import org.apache.calcite.adapter.java.JavaTypeFactory;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rex.RexBuilder;
-import org.apache.calcite.rex.RexNode;
-import org.apache.calcite.rex.RexUnknownAs;
-import org.apache.calcite.sql.SqlOperator;
-import org.apache.calcite.sql.fun.SqlStdOperatorTable;
-import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.util.DateString;
-import org.apache.calcite.util.Sarg;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeBaseVisitor;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.ArgListContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.ArgRangeContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.ArgRangeListContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.CastContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.ConstantContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.ExpressionContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.InputContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.InputRefContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.OpContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.ParamWithTypeContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.ParameterContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.SearchArgsContext;
-import
org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser.TypeContext;
-import
org.apache.shardingsphere.sqlfederation.exception.OptimizationSQLRexNodeException;
-
-import java.math.BigDecimal;
-import java.sql.Date;
-import java.sql.Types;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * SQL optimizer rex node visitor.
- */
-@AllArgsConstructor
-public final class SQLOptimizerRexNodeVisitor extends
SQLOptimizerRexNodeBaseVisitor<RexNode> {
-
- private RexBuilder rexBuilder;
-
- private JavaTypeFactory typeFactory;
-
- private Map<String, Object> parameters;
-
- private Map<Integer, Integer> columnMap;
-
- @Override
- public RexNode visitExpression(final ExpressionContext ctx) {
- SqlOperator operator = getOp(ctx.op());
- RexNode firstNode = visitParameter(ctx.parameter(0));
- RexNode secondNode = visitParameter(ctx.parameter(1));
- return rexBuilder.makeCall(operator, firstNode, secondNode);
- }
-
- private SqlOperator getOp(final OpContext ctx) {
- if (null != ctx.LIKE()) {
- return SqlStdOperatorTable.LIKE;
- }
- if (null != ctx.SEARCH()) {
- return SqlStdOperatorTable.SEARCH;
- }
- if (null != ctx.AND()) {
- return SqlStdOperatorTable.AND;
- }
- if (null != ctx.OR()) {
- return SqlStdOperatorTable.OR;
- }
- if (null != ctx.NOT()) {
- return SqlStdOperatorTable.NOT;
- }
- if (null != ctx.EQ_()) {
- return SqlStdOperatorTable.EQUALS;
- }
- if (null != ctx.LT_()) {
- return SqlStdOperatorTable.LESS_THAN;
- }
- if (null != ctx.LTE_()) {
- return SqlStdOperatorTable.LESS_THAN_OR_EQUAL;
- }
- if (null != ctx.GT_()) {
- return SqlStdOperatorTable.GREATER_THAN;
- }
- if (null != ctx.GTE_()) {
- return SqlStdOperatorTable.GREATER_THAN_OR_EQUAL;
- }
- if (null != ctx.NEQ_()) {
- return SqlStdOperatorTable.NOT_EQUALS;
- }
- throw new OptimizationSQLRexNodeException(ctx.getText());
- }
-
- @Override
- public RexNode visitParameter(final ParameterContext ctx) {
- if (null != ctx.expression()) {
- return visitExpression(ctx.expression());
- }
- if (null != ctx.input()) {
- return visitInput(ctx.input());
- }
- throw new OptimizationSQLRexNodeException(ctx.getText());
- }
-
- @Override
- public RexNode visitInput(final InputContext ctx) {
- if (null != ctx.inputRef()) {
- return visitInputRef(ctx.inputRef());
- }
- if (null != ctx.searchArgs()) {
- return visitSearchArgs(ctx.searchArgs());
- }
- if (null != ctx.constant()) {
- return visitConstant(ctx.constant());
- }
- if (null != ctx.cast()) {
- return visitCast(ctx.cast());
- }
- if (null != ctx.paramWithType()) {
- return visitParamWithType(ctx.paramWithType());
- }
- throw new OptimizationSQLRexNodeException(ctx.getText());
- }
-
- @Override
- public RexNode visitInputRef(final InputRefContext ctx) {
- Integer index = Integer.valueOf(ctx.INTEGER_().getText());
- if (null != columnMap.get(index)) {
- Class<?> dataType = getClass(columnMap.get(index));
- return
rexBuilder.makeInputRef(typeFactory.createJavaType(dataType), index);
- }
- if (ctx.getParent() instanceof CastContext) {
- String sign = ctx.getParent().getStop().getText();
- return makeCastInputRef(sign, index);
- }
- return
rexBuilder.makeInputRef(typeFactory.createJavaType(Integer.class), index);
- }
-
- private RexNode makeCastInputRef(final String sign, final Integer index) {
- if (sign.contains("VARCHAR")) {
- return
rexBuilder.makeInputRef(typeFactory.createJavaType(String.class), index);
- } else if ("INTEGER".equals(sign)) {
- return
rexBuilder.makeInputRef(typeFactory.createJavaType(Integer.class), index);
- } else if ("BIGINT".equals(sign)) {
- return
rexBuilder.makeInputRef(typeFactory.createJavaType(Long.class), index);
- } else if ("DATE".equals(sign)) {
- return
rexBuilder.makeInputRef(typeFactory.createJavaType(Date.class), index);
- }
- throw new OptimizationSQLRexNodeException(sign);
- }
-
- /**
- * Switch sql type to java type, reference to java.sql.Types.
- *
- * @param dataType sql type
- * @return java type
- */
- private Class<?> getClass(final int dataType) {
- switch (dataType) {
- case Types.BIGINT:
- return Long.class;
- case Types.CHAR:
- return String.class;
- case Types.INTEGER:
- return Integer.class;
- case Types.SMALLINT:
- return Short.class;
- case Types.FLOAT:
- return Float.class;
- case Types.DOUBLE:
- return Double.class;
- case Types.VARCHAR:
- return String.class;
- case Types.DATE:
- return Date.class;
- default:
- return String.class;
- }
- }
-
- @Override
- public RexNode visitSearchArgs(final SearchArgsContext ctx) {
- Sarg<BigDecimal> sarg;
- if (null != ctx.argList()) {
- sarg = getArgList(ctx.argList());
- } else if (null != ctx.argRange()) {
- sarg = getArgRange(ctx.argRange());
- } else if (null != ctx.argRangeList()) {
- sarg = getArgRangeList(ctx.argRangeList());
- } else {
- throw new OptimizationSQLRexNodeException(ctx.getText());
- }
- RelDataType sargType = typeFactory.createSqlType(SqlTypeName.DECIMAL);
- return rexBuilder.makeSearchArgumentLiteral(sarg, sargType);
- }
-
- @Override
- public RexNode visitConstant(final ConstantContext ctx) {
- if (null != ctx.INTEGER_()) {
- Integer number = Integer.valueOf(ctx.INTEGER_().getText());
- RelDataType nonNullableInt =
typeFactory.createSqlType(SqlTypeName.INTEGER);
- return rexBuilder.makeLiteral(number, nonNullableInt, false);
- }
- if (null != ctx.STRING_()) {
- String literalValue = ctx.STRING_().getText().replace("\"",
"").replace("'", "");
- return rexBuilder.makeLiteral(literalValue,
typeFactory.createSqlType(SqlTypeName.VARCHAR), false);
- }
- if (null != ctx.DATE_()) {
- String data = ctx.DATE_().getText();
- DateString value = new DateString(data);
- return rexBuilder.makeLiteral(value,
typeFactory.createSqlType(SqlTypeName.DATE), false);
- }
- if (null != ctx.PLACEHOLDER_()) {
- return makeLiteral(ctx.PLACEHOLDER_().getText());
- }
- if (null != ctx.string_zh().STRING_()) {
- String literalValue =
ctx.string_zh().STRING_().getText().replace("\"", "").replace("'", "");
- return rexBuilder.makeLiteral(literalValue,
typeFactory.createSqlType(SqlTypeName.VARCHAR), false);
- }
- throw new OptimizationSQLRexNodeException(ctx.getText());
- }
-
- private RexNode makeLiteral(final String text) {
- Class<?> parameterType = parameters.get(text).getClass();
- Object parameter = parameters.get(text);
- if (parameterType.equals(Integer.class)) {
- return rexBuilder.makeLiteral(parameter,
typeFactory.createSqlType(SqlTypeName.INTEGER), false);
- } else if (parameterType.equals(Long.class)) {
- return rexBuilder.makeLiteral(parameter,
typeFactory.createSqlType(SqlTypeName.BIGINT), false);
- } else if (parameterType.equals(String.class)) {
- return rexBuilder.makeLiteral(parameter,
typeFactory.createSqlType(SqlTypeName.VARCHAR), false);
- } else if (parameterType.equals(Date.class)) {
- Date data = (Date) parameter;
- DateString value = new DateString(data.toString());
- return rexBuilder.makeLiteral(value,
typeFactory.createSqlType(SqlTypeName.DATE), true);
- } else {
- return rexBuilder.makeLiteral(parameter.toString(),
typeFactory.createSqlType(SqlTypeName.VARCHAR), false);
- }
- }
-
- @Override
- public RexNode visitCast(final CastContext ctx) {
- RexNode inputRef = visitInputRef(ctx.inputRef());
- RelDataType type = getType(ctx.type());
- return rexBuilder.makeCast(type, inputRef);
- }
-
- @Override
- public RexNode visitParamWithType(final ParamWithTypeContext ctx) {
- RelDataType type = getType(ctx.type());
- return null == ctx.INTEGER_() ?
rexBuilder.makeLiteral(ctx.STRING_().getText(), type) :
rexBuilder.makeLiteral(Integer.valueOf(ctx.INTEGER_().getText()), type);
- }
-
- private Sarg<BigDecimal> getArgRange(final ArgRangeContext ctx) {
- BigDecimal lowerValue =
BigDecimal.valueOf(Long.parseLong(ctx.INTEGER_(0).getText()));
- BigDecimal upperValue =
BigDecimal.valueOf(Long.parseLong(ctx.INTEGER_(1).getText()));
- Range.range(lowerValue, BoundType.OPEN, upperValue, BoundType.OPEN);
- return null == ctx.LP_()
- ? Sarg.of(RexUnknownAs.UNKNOWN,
ImmutableRangeSet.of(Range.range(lowerValue, BoundType.CLOSED, upperValue,
BoundType.CLOSED)))
- : Sarg.of(RexUnknownAs.UNKNOWN,
ImmutableRangeSet.of(Range.range(lowerValue, BoundType.OPEN, upperValue,
BoundType.OPEN)));
- }
-
- private Sarg<BigDecimal> getArgList(final ArgListContext ctx) {
- RangeSet<BigDecimal> rangeSet = TreeRangeSet.create();
- for (TerminalNode each : ctx.INTEGER_()) {
- BigDecimal value =
BigDecimal.valueOf(Long.parseLong(each.getText()));
- rangeSet.add(Range.singleton(value));
- }
- return Sarg.of(RexUnknownAs.UNKNOWN, rangeSet);
- }
-
- private Sarg<BigDecimal> getArgRangeList(final ArgRangeListContext ctx) {
- List<Range<BigDecimal>> rangeList = new LinkedList<>();
- for (ArgRangeContext each : ctx.argRange()) {
- BigDecimal lowerValue = BigDecimal.valueOf(Long.MIN_VALUE);
- BigDecimal upperValue = BigDecimal.valueOf(Long.MAX_VALUE);
- if (null != each.NEGETIVE_INFINITY_() && null != each.INTEGER_(0))
{
- String upper = each.INTEGER_(0).getText();
- upperValue = BigDecimal.valueOf(Long.parseLong(upper));
- }
- if (null != each.POSITIVE_INFINITY_() && null != each.INTEGER_(0))
{
- String lower = each.INTEGER_(0).getText();
- lowerValue = BigDecimal.valueOf(Long.parseLong(lower));
- }
- if (null == each.NEGETIVE_INFINITY_() && null ==
each.POSITIVE_INFINITY_()) {
- String lower = each.INTEGER_(0).getText();
- String upper = each.INTEGER_(1).getText();
- lowerValue = BigDecimal.valueOf(Long.parseLong(lower));
- upperValue = BigDecimal.valueOf(Long.parseLong(upper));
- }
- if (null == each.LP_()) {
- Range<BigDecimal> range = Range.range(lowerValue,
BoundType.CLOSED, upperValue, BoundType.CLOSED);
- rangeList.add(range);
- } else {
- Range<BigDecimal> range = Range.range(lowerValue,
BoundType.OPEN, upperValue, BoundType.OPEN);
- rangeList.add(range);
- }
- }
- return Sarg.of(RexUnknownAs.UNKNOWN,
ImmutableRangeSet.copyOf(rangeList));
- }
-
- private RelDataType getType(final TypeContext ctx) {
- if (null != ctx.INTEGER()) {
- return typeFactory.createSqlType(SqlTypeName.INTEGER);
- }
- if (null != ctx.DATE()) {
- return typeFactory.createSqlType(SqlTypeName.DATE);
- }
- if (null != ctx.BIGINT()) {
- return typeFactory.createSqlType(SqlTypeName.BIGINT);
- }
- if (null != ctx.VARCHAR()) {
- return typeFactory.createSqlType(SqlTypeName.VARCHAR);
- }
- return typeFactory.createSqlType(SqlTypeName.VARCHAR);
- }
-}
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/util/StringToRexNodeUtils.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/util/StringToRexNodeUtils.java
deleted file mode 100644
index 0d46def3950..00000000000
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/util/StringToRexNodeUtils.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.shardingsphere.sqlfederation.executor.util;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.antlr.v4.runtime.CharStream;
-import org.antlr.v4.runtime.CharStreams;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.tree.ParseTree;
-import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
-import org.apache.calcite.rel.type.RelDataTypeSystem;
-import org.apache.calcite.rex.RexBuilder;
-import org.apache.calcite.rex.RexNode;
-import org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeLexer;
-import org.apache.shardingsphere.rexnode.autogen.SQLOptimizerRexNodeParser;
-
-import java.util.Map;
-
-/**
- * Parsing string and generate rex node utility class.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class StringToRexNodeUtils {
-
- /**
- * Parse string and generate rex node.
- *
- * @param filterValue filter condition
- * @param rexBuilder used to build rex node
- * @param parameters parameters for SQL placeholder
- * @param columnMap mapping of column id and column type
- * @return rex node
- */
- public static RexNode buildRexNode(final String filterValue, final
RexBuilder rexBuilder, final Map<String, Object> parameters, final Map<Integer,
Integer> columnMap) {
- CharStream input = CharStreams.fromString(filterValue);
- SQLOptimizerRexNodeLexer lexer = new SQLOptimizerRexNodeLexer(input);
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- SQLOptimizerRexNodeParser parser = new
SQLOptimizerRexNodeParser(tokens);
- ParseTree tree = parser.expression();
- SQLOptimizerRexNodeVisitor visitor = new
SQLOptimizerRexNodeVisitor(rexBuilder, new
JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT), parameters, columnMap);
- return visitor.visit(tree);
- }
-}