This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 2ea140b  support cast function, union method, LIKE keyword (#13891)
2ea140b is described below

commit 2ea140b2e9b64670ae550ec45358f49f16c69cb2
Author: liguoping <[email protected]>
AuthorDate: Tue Dec 14 19:34:43 2021 +0800

    support cast function, union method, LIKE keyword (#13891)
    
    * support select_constant_without_table
    
    * SimpleTableConverter has owner
    
    * SimpleTableConverter has owner convertToSQLSegment
    
    * support select_with_schema
    
    * convertToSQLStatement support union
    
    * convertToSQLNode support union
    
    * support LIKE
    
    * FunctionSegment use parameters use SQLSegment instead of ExpressionSegment
    
    * update visitCastFunction method logic
    
    * update select_cast_function in select-special-function.xml
    
    * FunctionSegment parameters filter ExpressionSegment
    
    * support select_cast_function
    
    * data type assert
---
 .../converter/SQLNodeConverterEngine.java          | 44 ++++++++++++++++++-
 .../segment/expression/ExpressionConverter.java    |  6 ++-
 .../impl/BinaryOperationExpressionConverter.java   | 20 ++++++---
 .../segment/expression/impl/FunctionConverter.java | 46 ++++++++++++++++----
 .../segment/from/impl/SimpleTableConverter.java    | 17 +++++++-
 .../segment/projection/ProjectionsConverter.java   |  3 +-
 .../impl/ExpressionProjectionConverter.java        | 32 +++++++++++++-
 .../statement/impl/MySQLStatementSQLVisitor.java   | 10 ++++-
 .../statement/impl/OracleStatementSQLVisitor.java  | 10 ++++-
 .../statement/impl/SQL92StatementSQLVisitor.java   | 10 ++++-
 .../impl/SQLServerStatementSQLVisitor.java         | 10 ++++-
 .../common/segment/generic/DataTypeSegment.java    |  4 +-
 .../SQLNodeConvertEngineParameterizedTest.java     |  4 ++
 .../segment/expression/ExpressionAssert.java       |  7 ++-
 .../asserts/segment/generic/DataTypeAssert.java    | 50 ++++++++++++++++++++++
 .../segment/impl/expr/ExpectedExpression.java      |  4 ++
 .../segment/impl/generic/ExpectedDataType.java     | 20 ++++-----
 .../resources/case/dml/select-special-function.xml |  9 +++-
 .../src/main/resources/case/dml/select.xml         | 18 +++++++-
 19 files changed, 280 insertions(+), 44 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/SQLNodeConverterEngine.java
 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/SQLNodeConverterEngine.java
index 96efe9d..7497e1a 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/SQLNodeConverterEngine.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/SQLNodeConverterEngine.java
@@ -17,21 +17,42 @@
 
 package org.apache.shardingsphere.infra.federation.optimizer.converter;
 
+import com.google.common.base.Preconditions;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import org.apache.calcite.sql.SqlBasicCall;
+import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
 import org.apache.calcite.sql.SqlOrderBy;
 import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserPos;
 import 
org.apache.shardingsphere.infra.federation.optimizer.converter.statement.SelectStatementConverter;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.UnionType;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.union.UnionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
 
+import java.util.Map;
+import java.util.TreeMap;
+
 /**
  * SQL node converter engine.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class SQLNodeConverterEngine {
     
+    private static final Map<UnionType, SqlOperator> REGISTRY = new 
TreeMap<>();
+    
+    static {
+        registerUnion();
+    }
+    
+    private static void registerUnion() {
+        REGISTRY.put(UnionType.UNION_DISTINCT, SqlStdOperatorTable.UNION);
+    }
+    
     /**
      * Convert SQL statement to SQL node.
      * 
@@ -40,7 +61,14 @@ public final class SQLNodeConverterEngine {
      */
     public static SqlNode convertToSQLNode(final SQLStatement statement) {
         if (statement instanceof SelectStatement) {
-            return new 
SelectStatementConverter().convertToSQLNode((SelectStatement) statement);
+            SqlNode sqlNode = new 
SelectStatementConverter().convertToSQLNode((SelectStatement) statement);
+            if (null != ((SelectStatement) statement).getUnionSegments()) {
+                for (final UnionSegment unionSegment : ((SelectStatement) 
statement).getUnionSegments()) {
+                    SqlNode unionSqlNode = 
convertToSQLNode(unionSegment.getSelectStatement());
+                    return new 
SqlBasicCall(convertUnionOperator(unionSegment.getUnionType()), new 
SqlNode[]{sqlNode, unionSqlNode}, SqlParserPos.ZERO);
+                }
+            }
+            return sqlNode;
         }
         throw new UnsupportedOperationException("Unsupported SQL node 
conversion.");
     }
@@ -55,6 +83,20 @@ public final class SQLNodeConverterEngine {
         if (sqlNode instanceof SqlOrderBy || sqlNode instanceof SqlSelect) {
             return new 
SelectStatementConverter().convertToSQLStatement(sqlNode);
         }
+        if (sqlNode instanceof SqlBasicCall && null != ((SqlBasicCall) 
sqlNode).getOperator() && SqlKind.UNION == ((SqlBasicCall) 
sqlNode).getOperator().getKind()) {
+            SqlNode leftSqlNode = ((SqlBasicCall) 
sqlNode).getOperandList().get(0);
+            SqlNode rightSqlNode = ((SqlBasicCall) 
sqlNode).getOperandList().get(1);
+            SelectStatement leftSelectStatement = (SelectStatement) 
convertToSQLStatement(leftSqlNode);
+            SelectStatement rightSelectStatement = (SelectStatement) 
convertToSQLStatement(rightSqlNode);
+            leftSelectStatement.getUnionSegments().add(new 
UnionSegment(UnionType.UNION_DISTINCT, rightSelectStatement, 
rightSqlNode.getParserPosition().getColumnNum() - 7, 
+                    rightSqlNode.getParserPosition().getEndColumnNum() - 1));
+            return leftSelectStatement;
+        }
         throw new UnsupportedOperationException("Unsupported SQL statement 
conversion.");
     }
+    
+    private static SqlOperator convertUnionOperator(final UnionType unionType) 
{
+        Preconditions.checkState(REGISTRY.containsKey(unionType), "Unsupported 
unionType: `%s`", unionType);
+        return REGISTRY.get(unionType);
+    }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/ExpressionConverter.java
 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/ExpressionConverter.java
index 54d5ad4..ee594af 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/ExpressionConverter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/ExpressionConverter.java
@@ -26,7 +26,9 @@ import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlOperator;
 import org.apache.calcite.sql.SqlSelect;
 import org.apache.calcite.sql.fun.SqlBetweenOperator;
+import org.apache.calcite.sql.fun.SqlCastFunction;
 import org.apache.calcite.sql.fun.SqlInOperator;
+import org.apache.calcite.sql.fun.SqlLikeOperator;
 import org.apache.calcite.sql.fun.SqlPositionFunction;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.SQLSegmentConverter;
@@ -132,10 +134,10 @@ public final class ExpressionConverter implements 
SQLSegmentConverter<Expression
         if (operator.getName().equals(SqlStdOperatorTable.EXISTS.getName())) {
             return new 
ExistsSubqueryExpressionConverter(not).convertToSQLSegment(sqlBasicCall).map(optional
 -> optional);
         }
-        if (operator instanceof SqlBinaryOperator) {
+        if (operator instanceof SqlBinaryOperator || operator instanceof 
SqlLikeOperator) {
             return new 
BinaryOperationExpressionConverter().convertToSQLSegment(sqlBasicCall).map(optional
 -> optional);
         }
-        if (operator instanceof SqlPositionFunction) {
+        if (operator instanceof SqlPositionFunction || operator instanceof 
SqlCastFunction) {
             return new 
FunctionConverter().convertToSQLSegment(sqlBasicCall).map(optional -> optional);
         }
         return Optional.empty();
diff --git 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
index 21e2000..3d823a9 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/impl/BinaryOperationExpressionConverter.java
@@ -19,14 +19,16 @@ package 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.e
 
 import com.google.common.base.Preconditions;
 import org.apache.calcite.sql.SqlBasicCall;
-import org.apache.calcite.sql.SqlBinaryOperator;
+import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.SQLSegmentConverter;
 import 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.expression.ExpressionConverter;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression;
 
 import java.util.Map;
 import java.util.Optional;
@@ -37,7 +39,7 @@ import java.util.TreeMap;
  */
 public final class BinaryOperationExpressionConverter implements 
SQLSegmentConverter<BinaryOperationExpression, SqlBasicCall> {
     
-    private static final Map<String, SqlBinaryOperator> REGISTRY = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+    private static final Map<String, SqlOperator> REGISTRY = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
     
     static {
         register();
@@ -57,10 +59,11 @@ public final class BinaryOperationExpressionConverter 
implements SQLSegmentConve
         register(SqlStdOperatorTable.MINUS);
         register(SqlStdOperatorTable.MULTIPLY);
         register(SqlStdOperatorTable.DIVIDE);
+        register(SqlStdOperatorTable.LIKE);
     }
     
-    private static void register(final SqlBinaryOperator sqlBinaryOperator) {
-        REGISTRY.put(sqlBinaryOperator.getName(), sqlBinaryOperator);
+    private static void register(final SqlOperator sqlOperator) {
+        REGISTRY.put(sqlOperator.getName(), sqlOperator);
     }
     
     private static void registerAlias() {
@@ -69,7 +72,7 @@ public final class BinaryOperationExpressionConverter 
implements SQLSegmentConve
     
     @Override
     public Optional<SqlBasicCall> convertToSQLNode(final 
BinaryOperationExpression segment) {
-        SqlBinaryOperator operator = convertOperator(segment.getOperator());
+        SqlOperator operator = convertOperator(segment.getOperator());
         SqlNode left = new 
ExpressionConverter().convertToSQLNode(segment.getLeft()).orElseThrow(IllegalStateException::new);
         SqlNode right = new 
ExpressionConverter().convertToSQLNode(segment.getRight()).orElseThrow(IllegalStateException::new);
         return Optional.of(new SqlBasicCall(operator, new SqlNode[] {left, 
right}, SqlParserPos.ZERO));
@@ -82,10 +85,15 @@ public final class BinaryOperationExpressionConverter 
implements SQLSegmentConve
         ExpressionSegment right = 
expressionConverter.convertToSQLSegment(sqlBasicCall.getOperandList().get(1)).orElseThrow(IllegalStateException::new);
         String operator = sqlBasicCall.getOperator().getName();
         String text = sqlBasicCall.toString();
+        if (SqlKind.LIKE == sqlBasicCall.getOperator().getKind()) {
+            ListExpression listExpression = new 
ListExpression(getStartIndex(sqlBasicCall.getOperandList().get(1)), 
getStopIndex(sqlBasicCall.getOperandList().get(1)));
+            listExpression.getItems().add(right);
+            return Optional.of(new 
BinaryOperationExpression(getStartIndex(sqlBasicCall), 
getStopIndex(sqlBasicCall), left, listExpression, operator, text));
+        }
         return Optional.of(new 
BinaryOperationExpression(getStartIndex(sqlBasicCall), 
getStopIndex(sqlBasicCall), left, right, operator, text));
     }
     
-    private SqlBinaryOperator convertOperator(final String operator) {
+    private SqlOperator convertOperator(final String operator) {
         Preconditions.checkState(REGISTRY.containsKey(operator), "Unsupported 
SQL operator: `%s`", operator);
         return REGISTRY.get(operator);
     }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/impl/FunctionConverter.java
 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/impl/FunctionConverter.java
index 39fc58a..f1c79bf 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/impl/FunctionConverter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/expression/impl/FunctionConverter.java
@@ -18,20 +18,24 @@
 package 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.expression.impl;
 
 import org.apache.calcite.sql.SqlBasicCall;
+import org.apache.calcite.sql.SqlCharStringLiteral;
+import org.apache.calcite.sql.SqlDataTypeSpec;
 import org.apache.calcite.sql.SqlLiteral;
 import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlUserDefinedTypeNameSpec;
+import org.apache.calcite.sql.fun.SqlCastFunction;
 import org.apache.calcite.sql.fun.SqlPositionFunction;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.SQLSegmentConverter;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
-import java.util.stream.Collectors;
 
 /**
  * Function converter.
@@ -41,7 +45,10 @@ public final class FunctionConverter implements 
SQLSegmentConverter<FunctionSegm
     @Override
     public Optional<SqlBasicCall> convertToSQLNode(final FunctionSegment 
segment) {
         if ("POSITION".equalsIgnoreCase(segment.getFunctionName())) {
-            return Optional.of(new SqlBasicCall(new SqlPositionFunction(), 
getPositionSqlNodes(segment.getParameters()), SqlParserPos.ZERO));
+            return Optional.of(new SqlBasicCall(new SqlPositionFunction(), 
getSqlNodes(segment.getParameters()), SqlParserPos.ZERO));
+        }
+        if ("CAST".equalsIgnoreCase(segment.getFunctionName())) {
+            return Optional.of(new SqlBasicCall(new SqlCastFunction(), 
getSqlNodes(segment.getParameters()), SqlParserPos.ZERO));
         }
         return Optional.empty();
     }
@@ -51,21 +58,42 @@ public final class FunctionConverter implements 
SQLSegmentConverter<FunctionSegm
         if (null == sqlBasicCall) {
             return Optional.empty();
         }
-        FunctionSegment functionSegment = new 
FunctionSegment(getStartIndex(sqlBasicCall), getStopIndex(sqlBasicCall), 
sqlBasicCall.getOperator().getName(), sqlBasicCall.toString());
+        FunctionSegment functionSegment = new 
FunctionSegment(getStartIndex(sqlBasicCall), getStopIndex(sqlBasicCall), 
sqlBasicCall.getOperator().getName(), getFunctionText(sqlBasicCall));
         functionSegment.getParameters().addAll(getParameters(sqlBasicCall));
         return Optional.of(functionSegment);
     }
     
+    private String getFunctionText(final SqlBasicCall sqlBasicCall) {
+        if (null != sqlBasicCall.getOperator() && sqlBasicCall.getOperator() 
instanceof SqlCastFunction) {
+            return sqlBasicCall.toString().replace("`", "");
+        }
+        return sqlBasicCall.toString();
+    }
+    
     private List<ExpressionSegment> getParameters(final SqlBasicCall 
sqlBasicCall) {
-        return sqlBasicCall.getOperandList().stream()
-                .map(operand -> new 
LiteralExpressionSegment(getStartIndex(operand), getStopIndex(operand), 
operand.toString().replace("'", ""))).collect(Collectors.toList());
+        List<ExpressionSegment> result = new ArrayList<>();
+        sqlBasicCall.getOperandList().forEach(operand -> {
+            if (operand instanceof SqlDataTypeSpec) {
+                DataTypeSegment dataTypeSegment = new DataTypeSegment();
+                dataTypeSegment.setStartIndex(getStartIndex(operand));
+                dataTypeSegment.setStopIndex(getStopIndex(operand));
+                
dataTypeSegment.setDataTypeName(operand.toString().replace("`", ""));
+                result.add(dataTypeSegment);
+            } else if (operand instanceof SqlCharStringLiteral) {
+                result.add(new 
LiteralExpressionSegment(getStartIndex(operand), getStopIndex(operand), 
operand.toString().replace("'", "")));
+            }
+        });
+        return result;
     }
     
-    private SqlNode[] getPositionSqlNodes(final Collection<ExpressionSegment> 
expressionSegments) {
+    private SqlNode[] getSqlNodes(final Collection<ExpressionSegment> 
sqlSegments) {
         List<SqlNode> sqlNodes = new ArrayList<>();
-        expressionSegments.forEach(expressionSegment -> {
-            if (expressionSegment instanceof LiteralExpressionSegment) {
-                
sqlNodes.add(SqlLiteral.createCharString(((LiteralExpressionSegment) 
expressionSegment).getLiterals().toString(), SqlParserPos.ZERO));
+        sqlSegments.forEach(sqlSegment -> {
+            if (sqlSegment instanceof LiteralExpressionSegment) {
+                
sqlNodes.add(SqlLiteral.createCharString(((LiteralExpressionSegment) 
sqlSegment).getLiterals().toString(), SqlParserPos.ZERO));
+            }
+            if (sqlSegment instanceof DataTypeSegment) {
+                sqlNodes.add(new SqlDataTypeSpec(new 
SqlUserDefinedTypeNameSpec(((DataTypeSegment) sqlSegment).getDataTypeName(), 
SqlParserPos.ZERO), SqlParserPos.ZERO));
             }
         });
         return sqlNodes.toArray(new SqlNode[0]);
diff --git 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/SimpleTableConverter.java
 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/SimpleTableConverter.java
index 92a737e..c342e49 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/SimpleTableConverter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/SimpleTableConverter.java
@@ -24,10 +24,13 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.SQLSegmentConverter;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Optional;
 
 /**
@@ -38,7 +41,12 @@ public final class SimpleTableConverter implements 
SQLSegmentConverter<SimpleTab
     @Override
     public Optional<SqlNode> convertToSQLNode(final SimpleTableSegment 
segment) {
         TableNameSegment tableName = segment.getTableName();
-        SqlNode tableNameSQLNode = new 
SqlIdentifier(tableName.getIdentifier().getValue(), SqlParserPos.ZERO);
+        List<String> names = new ArrayList<>();
+        if (segment.getOwner().isPresent()) {
+            names.add(segment.getOwner().get().getIdentifier().getValue());
+        }
+        names.add(tableName.getIdentifier().getValue());
+        SqlNode tableNameSQLNode = new SqlIdentifier(names, SqlParserPos.ZERO);
         if (segment.getAlias().isPresent()) {
             SqlNode aliasSQLNode = new SqlIdentifier(segment.getAlias().get(), 
SqlParserPos.ZERO);
             return Optional.of(new SqlBasicCall(SqlStdOperatorTable.AS, new 
SqlNode[] {tableNameSQLNode, aliasSQLNode}, SqlParserPos.ZERO));
@@ -59,7 +67,12 @@ public final class SimpleTableConverter implements 
SQLSegmentConverter<SimpleTab
             }
         }
         if (sqlNode instanceof SqlIdentifier) {
-            return Optional.of(new SimpleTableSegment(new 
TableNameSegment(getStartIndex(sqlNode), getStopIndex(sqlNode), new 
IdentifierValue(((SqlIdentifier) sqlNode).names.get(0)))));
+            List<String> names = ((SqlIdentifier) sqlNode).names;
+            SimpleTableSegment simpleTableSegment = new SimpleTableSegment(new 
TableNameSegment(getStartIndex(sqlNode), getStopIndex(sqlNode), new 
IdentifierValue(names.get(names.size() - 1))));
+            if (2 == names.size()) {
+                simpleTableSegment.setOwner(new 
OwnerSegment(getStartIndex(sqlNode), getStartIndex(sqlNode) + 
names.get(0).length() - 1, new IdentifierValue(names.get(0))));
+            }
+            return Optional.of(simpleTableSegment);
         }
         return Optional.empty();
     }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/projection/ProjectionsConverter.java
 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/projection/ProjectionsConverter.java
index 4c39524..c77f53d 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/projection/ProjectionsConverter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/projection/ProjectionsConverter.java
@@ -22,6 +22,7 @@ import org.apache.calcite.sql.SqlIdentifier;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlNumericLiteral;
 import org.apache.calcite.sql.SqlOrderBy;
 import org.apache.calcite.sql.SqlSelect;
 import org.apache.calcite.sql.parser.SqlParserPos;
@@ -108,7 +109,7 @@ public final class ProjectionsConverter implements 
SQLSegmentConverter<Projectio
             if 
(AggregationType.isAggregationType(sqlBasicCall.getOperator().getName()) || 
AggregationProjectionConverter.isAsOperatorAggregationType(sqlBasicCall)) {
                 return new 
AggregationProjectionConverter().convertToSQLSegment(sqlBasicCall).map(optional 
-> optional);
             }
-            if (null != sqlBasicCall.getOperator() && SqlKind.AS == 
sqlBasicCall.getOperator().getKind()) {
+            if (null != sqlBasicCall.getOperator() && SqlKind.AS == 
sqlBasicCall.getOperator().getKind() && !(sqlBasicCall.getOperandList().get(0) 
instanceof SqlNumericLiteral)) {
                 return new 
ColumnProjectionConverter().convertToSQLSegment(sqlNode).map(optional -> 
optional);
             }
             return new 
ExpressionProjectionConverter().convertToSQLSegment(sqlNode).map(optional -> 
optional);
diff --git 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/projection/impl/ExpressionProjectionConverter.java
 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/projection/impl/ExpressionProjectionConverter.java
index 7b6800c..443bc17 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/projection/impl/ExpressionProjectionConverter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/projection/impl/ExpressionProjectionConverter.java
@@ -18,12 +18,21 @@
 package 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.projection.impl;
 
 import org.apache.calcite.sql.SqlBasicCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNumericLiteral;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserPos;
 import 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.SQLSegmentConverter;
 import 
org.apache.shardingsphere.infra.federation.optimizer.converter.segment.expression.ExpressionConverter;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 
+import java.util.Collections;
 import java.util.Optional;
 
 /**
@@ -33,14 +42,33 @@ public final class ExpressionProjectionConverter implements 
SQLSegmentConverter<
     
     @Override
     public Optional<SqlNode> convertToSQLNode(final 
ExpressionProjectionSegment segment) {
-        return null == segment ? Optional.empty() : new 
ExpressionConverter().convertToSQLNode(segment.getExpr());
+        if (null == segment) {
+            return Optional.empty();
+        }
+        Optional<SqlNode> exprSqlNode = new 
ExpressionConverter().convertToSQLNode(segment.getExpr());
+        if (exprSqlNode.isPresent() && segment.getAlias().isPresent()) {
+            return Optional.of(new SqlBasicCall(SqlStdOperatorTable.AS, new 
SqlNode[]{exprSqlNode.get(),
+                    
SqlIdentifier.star(Collections.singletonList(segment.getAlias().get()), 
SqlParserPos.ZERO, Collections.singletonList(SqlParserPos.ZERO))}, 
SqlParserPos.ZERO));
+        }
+        return exprSqlNode;
     }
     
     @Override
     public Optional<ExpressionProjectionSegment> convertToSQLSegment(final 
SqlNode sqlNode) {
         if (sqlNode instanceof SqlBasicCall) {
+            SqlBasicCall sqlBasicCall = (SqlBasicCall) sqlNode;
+            if (SqlKind.AS == sqlBasicCall.getOperator().getKind() && 
sqlBasicCall.getOperandList().get(0) instanceof SqlNumericLiteral) {
+                SqlNode exprSqlNode = sqlBasicCall.getOperandList().get(0);
+                SqlNode aliasSqlNode = sqlBasicCall.getOperandList().get(1);
+                ExpressionSegment expressionSegment = new 
ExpressionConverter().convertToSQLSegment(exprSqlNode).orElse(null);
+                ExpressionProjectionSegment expressionProjectionSegment = new 
ExpressionProjectionSegment(getStartIndex(sqlBasicCall),
+                        getStopIndex(sqlBasicCall), exprSqlNode.toString(), 
expressionSegment);
+                expressionProjectionSegment.setAlias(new 
AliasSegment(getStartIndex(aliasSqlNode), getStopIndex(aliasSqlNode), new 
IdentifierValue(aliasSqlNode.toString())));
+                return Optional.of(expressionProjectionSegment);
+            }
             ExpressionSegment expressionSegment = new 
ExpressionConverter().convertToSQLSegment(sqlNode).orElse(null);
-            return Optional.of(new 
ExpressionProjectionSegment(getStartIndex(sqlNode), getStopIndex(sqlNode), 
sqlNode.toString(), expressionSegment));
+            String text = expressionSegment instanceof FunctionSegment ? 
((FunctionSegment) expressionSegment).getText() : sqlNode.toString();
+            return Optional.of(new 
ExpressionProjectionSegment(getStartIndex(sqlNode), getStopIndex(sqlNode), 
text, expressionSegment));
         }
         return Optional.empty();
     }
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
index d11a65d..bd8400f 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
@@ -797,7 +797,15 @@ public abstract class MySQLStatementSQLVisitor extends 
MySQLStatementBaseVisitor
     @Override
     public final ASTNode visitCastFunction(final CastFunctionContext ctx) {
         calculateParameterCount(Collections.singleton(ctx.expr()));
-        return new FunctionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), ctx.CAST().getText(), getOriginalText(ctx));
+        FunctionSegment result = new 
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), 
ctx.CAST().getText(), getOriginalText(ctx));
+        ASTNode exprSegment = visit(ctx.expr());
+        if (exprSegment instanceof ColumnSegment) {
+            result.getParameters().add((ColumnSegment) exprSegment);
+        } else if (exprSegment instanceof LiteralExpressionSegment) {
+            result.getParameters().add((LiteralExpressionSegment) exprSegment);
+        }
+        result.getParameters().add((DataTypeSegment) visit(ctx.dataType()));
+        return result;
     }
     
     @Override
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
index 320e08a..29f7ff0 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java
@@ -501,7 +501,15 @@ public abstract class OracleStatementSQLVisitor extends 
OracleStatementBaseVisit
     @Override
     public final ASTNode visitCastFunction(final CastFunctionContext ctx) {
         calculateParameterCount(Collections.singleton(ctx.expr()));
-        return new FunctionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), ctx.CAST().getText(), getOriginalText(ctx));
+        FunctionSegment result = new 
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), 
ctx.CAST().getText(), getOriginalText(ctx));
+        ASTNode exprSegment = visit(ctx.expr());
+        if (exprSegment instanceof ColumnSegment) {
+            result.getParameters().add((ColumnSegment) exprSegment);
+        } else if (exprSegment instanceof LiteralExpressionSegment) {
+            result.getParameters().add((LiteralExpressionSegment) exprSegment);
+        }
+        result.getParameters().add((DataTypeSegment) visit(ctx.dataType()));
+        return result;
     }
     
     @Override
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92StatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92StatementSQLVisitor.java
index e43ee53..80d2dfa 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92StatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/impl/SQL92StatementSQLVisitor.java
@@ -443,7 +443,15 @@ public abstract class SQL92StatementSQLVisitor extends 
SQL92StatementBaseVisitor
     @Override
     public final ASTNode visitCastFunction(final CastFunctionContext ctx) {
         calculateParameterCount(Collections.singleton(ctx.expr()));
-        return new FunctionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), ctx.CAST().getText(), getOriginalText(ctx));
+        FunctionSegment result = new 
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), 
ctx.CAST().getText(), getOriginalText(ctx));
+        ASTNode exprSegment = visit(ctx.expr());
+        if (exprSegment instanceof ColumnSegment) {
+            result.getParameters().add((ColumnSegment) exprSegment);
+        } else if (exprSegment instanceof LiteralExpressionSegment) {
+            result.getParameters().add((LiteralExpressionSegment) exprSegment);
+        }
+        result.getParameters().add((DataTypeSegment) visit(ctx.dataType()));
+        return result;
     }
     
     @Override
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
index 4ed8da4..88a7282 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
@@ -548,7 +548,15 @@ public abstract class SQLServerStatementSQLVisitor extends 
SQLServerStatementBas
     @Override
     public final ASTNode visitCastFunction(final CastFunctionContext ctx) {
         calculateParameterCount(Collections.singleton(ctx.expr()));
-        return new FunctionSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), ctx.CAST().getText(), getOriginalText(ctx));
+        FunctionSegment result = new 
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), 
ctx.CAST().getText(), getOriginalText(ctx));
+        ASTNode exprSegment = visit(ctx.expr());
+        if (exprSegment instanceof ColumnSegment) {
+            result.getParameters().add((ColumnSegment) exprSegment);
+        } else if (exprSegment instanceof LiteralExpressionSegment) {
+            result.getParameters().add((LiteralExpressionSegment) exprSegment);
+        }
+        result.getParameters().add((DataTypeSegment) visit(ctx.dataType()));
+        return result;
     }
     
     @Override
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/generic/DataTypeSegment.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/generic/DataTypeSegment.java
index 803698e..9751f71 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/generic/DataTypeSegment.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/generic/DataTypeSegment.java
@@ -19,11 +19,11 @@ package 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic;
 
 import lombok.Getter;
 import lombok.Setter;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
 
 @Getter
 @Setter
-public final class DataTypeSegment implements SQLSegment {
+public final class DataTypeSegment implements ExpressionSegment {
     
     private int startIndex;
     
diff --git 
a/shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConvertEngineParameterizedTest.java
 
b/shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConvertEngineParameterizedTest.java
index 5313108..fc09404 100644
--- 
a/shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConvertEngineParameterizedTest.java
+++ 
b/shardingsphere-test/shardingsphere-optimize-test/src/test/java/org/apache/shardingsphere/infra/federation/converter/parameterized/engine/SQLNodeConvertEngineParameterizedTest.java
@@ -90,6 +90,10 @@ public final class SQLNodeConvertEngineParameterizedTest {
         
SUPPORTED_SQL_CASE_IDS.add("select_distinct_with_single_count_group_by");
         SUPPORTED_SQL_CASE_IDS.add("select_bit_xor");
         SUPPORTED_SQL_CASE_IDS.add("select_position");
+        SUPPORTED_SQL_CASE_IDS.add("select_constant_without_table");
+        SUPPORTED_SQL_CASE_IDS.add("select_with_schema");
+        SUPPORTED_SQL_CASE_IDS.add("select_with_union");
+        SUPPORTED_SQL_CASE_IDS.add("select_cast_function");
     }
     
     private final String sqlCaseId;
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/expression/ExpressionAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/expression/ExpressionAssert.java
index 1ed0208..179010b 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/expression/ExpressionAssert.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/expression/ExpressionAssert.java
@@ -36,9 +36,11 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.SQLSegmentAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.column.ColumnAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.generic.DataTypeAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.owner.OwnerAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.projection.ProjectionAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dml.impl.SelectStatementAssert;
@@ -326,8 +328,9 @@ public final class ExpressionAssert {
             assertSubqueryExpression(assertContext,
                     (SubqueryExpressionSegment) actual, 
expected.getSubquery());
         } else if (actual instanceof ColumnSegment) {
-            ColumnAssert.assertIs(assertContext,
-                    (ColumnSegment) actual, expected.getColumn());
+            ColumnAssert.assertIs(assertContext, (ColumnSegment) actual, 
expected.getColumn());
+        } else if (actual instanceof DataTypeSegment) {
+            DataTypeAssert.assertIs(assertContext, (DataTypeSegment) actual, 
expected.getDataType());
         } else if (actual instanceof LiteralExpressionSegment) {
             assertLiteralExpression(assertContext,
                     (LiteralExpressionSegment) actual, 
expected.getLiteralExpression());
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/generic/DataTypeAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/generic/DataTypeAssert.java
new file mode 100644
index 0000000..573df42
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/generic/DataTypeAssert.java
@@ -0,0 +1,50 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.segment.generic;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.generic.ExpectedDataType;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ *  Data type assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DataTypeAssert {
+    
+    /**
+     * Assert actual data type segment is correct with expected date type.
+     *
+     * @param assertContext assert context
+     * @param actual actual data type statement
+     * @param expected expected data type
+     */
+    public static void assertIs(final SQLCaseAssertContext assertContext, 
final DataTypeSegment actual, final ExpectedDataType expected) {
+        assertThat(assertContext.getText(String.format("%s name assertion 
error: ", "dataType")),
+                actual.getDataTypeName(), is(expected.getValue()));
+        assertThat(assertContext.getText(String.format("%s start index 
assertion error: ", "dataType")),
+                actual.getStartIndex(), is(expected.getStartIndex()));
+        assertThat(assertContext.getText(String.format("%s end index assertion 
error: ", "dataType")),
+                actual.getStopIndex(), is(expected.getStopIndex()));
+    }
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/expr/ExpectedExpression.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/expr/ExpectedExpression.java
index d8286bb..727a283 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/expr/ExpectedExpression.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/expr/ExpectedExpression.java
@@ -26,6 +26,7 @@ import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.expr.simple.ExpectedParameterMarkerExpression;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.expr.simple.ExpectedSubquery;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.function.ExpectedFunction;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.generic.ExpectedDataType;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.projection.impl.aggregation.ExpectedAggregationProjection;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.projection.impl.expression.ExpectedExpressionProjection;
 
@@ -47,6 +48,9 @@ public final class ExpectedExpression extends 
AbstractExpectedSQLSegment {
     @XmlElement(name = "column")
     private ExpectedColumn column;
     
+    @XmlElement(name = "data-type")
+    private ExpectedDataType dataType;
+    
     @XmlElement(name = "common-expression")
     private ExpectedCommonExpression commonExpression;
     
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/generic/DataTypeSegment.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/generic/ExpectedDataType.java
similarity index 66%
copy from 
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/generic/DataTypeSegment.java
copy to 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/generic/ExpectedDataType.java
index 803698e..760ef16 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/generic/DataTypeSegment.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/generic/ExpectedDataType.java
@@ -15,21 +15,21 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.sql.parser.sql.common.segment.generic;
+package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.generic;
 
 import lombok.Getter;
 import lombok.Setter;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.expr.simple.ExpectedBaseSimpleExpression;
 
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * Expected data type.
+ */
 @Getter
 @Setter
-public final class DataTypeSegment implements SQLSegment {
-    
-    private int startIndex;
-    
-    private int stopIndex;
-    
-    private String dataTypeName;
+public final class ExpectedDataType extends ExpectedBaseSimpleExpression {
     
-    private DataTypeLengthSegment dataLength;
+    @XmlAttribute
+    private String value;
 }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-special-function.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-special-function.xml
index a5387f5..459dbf3 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-special-function.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select-special-function.xml
@@ -46,7 +46,14 @@
         <projections start-index="7" stop-index="27">
             <expression-projection text="CAST('1' AS UNSIGNED)" 
start-index="7" stop-index="27">
                 <expr>
-                    <function function-name="CAST" start-index="7" 
stop-index="27" text="CAST('1' AS UNSIGNED)" />
+                    <function function-name="CAST" start-index="7" 
stop-index="27" text="CAST('1' AS UNSIGNED)">
+                        <parameter>
+                            <literal-expression value="1" start-index="12" 
stop-index="14"/>
+                        </parameter>
+                        <parameter>
+                            <data-type value="UNSIGNED" start-index="19" 
stop-index="26"/>
+                        </parameter>
+                    </function>
                 </expr>
             </expression-projection>
         </projections>
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
index 763be36..4d7296f 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/select.xml
@@ -3192,7 +3192,14 @@
             <column-projection name="user_id" start-index="7" stop-index="13"/>
             <expression-projection text="CAST(order_id AS SIGNED)" 
start-index="15" stop-index="38">
                 <expr>
-                    <function function-name="CAST" start-index="15" 
stop-index="38" text="CAST(order_id AS SIGNED)" />
+                    <function function-name="CAST" start-index="15" 
stop-index="38" text="CAST(order_id AS SIGNED)" >
+                        <parameter>
+                            <column name="order_id" start-index="20" 
stop-index="27"/>
+                        </parameter>
+                        <parameter>
+                            <data-type value="SIGNED" start-index="32" 
stop-index="37"/>
+                        </parameter>
+                    </function>
                 </expr>
             </expression-projection>
         </projections>
@@ -3205,7 +3212,14 @@
         <projections start-index="7" stop-index="40">
             <expression-projection text="CAST(order_id AS UNSIGNED)" 
start-index="7" stop-index="32">
                 <expr>
-                    <function function-name="CAST" start-index="7" 
stop-index="32" text="CAST(order_id AS UNSIGNED)" />
+                    <function function-name="CAST" start-index="7" 
stop-index="32" text="CAST(order_id AS UNSIGNED)" >
+                        <parameter>
+                            <column name="order_id" start-index="12" 
stop-index="19"/>
+                        </parameter>
+                        <parameter>
+                            <data-type value="UNSIGNED" start-index="24" 
stop-index="31"/>
+                        </parameter>
+                    </function>
                 </expr>
             </expression-projection>
             <column-projection name="user_id" start-index="34" 
stop-index="40"/>

Reply via email to