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

zhaojinchao 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 48ef0c32a03 Refactor MySQL, PostgreSQL and openGaus join statement 
parse and support convert to SqlNode (#20221)
48ef0c32a03 is described below

commit 48ef0c32a038773721430e7c691b12b08dfdf187
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Aug 16 20:06:15 2022 +0800

    Refactor MySQL, PostgreSQL and openGaus join statement parse and support 
convert to SqlNode (#20221)
---
 .../segment/from/impl/JoinTableConverter.java      | 30 +-------------
 .../statement/impl/MySQLStatementSQLVisitor.java   | 47 ++++++++++++----------
 .../main/antlr4/imports/opengauss/DMLStatement.g4  | 29 +++++++------
 .../impl/OpenGaussStatementSQLVisitor.java         | 45 ++++++++++++++++++---
 .../main/antlr4/imports/postgresql/DMLStatement.g4 | 33 +++++++++------
 .../impl/PostgreSQLStatementSQLVisitor.java        | 45 ++++++++++++++++++---
 .../sql/parser/sql/common/constant/JoinType.java   | 23 +----------
 .../SQLNodeConvertEngineParameterizedTest.java     |  1 +
 8 files changed, 147 insertions(+), 106 deletions(-)

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/JoinTableConverter.java
 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/JoinTableConverter.java
index 89e81cbdfc5..6c71dc90748 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/JoinTableConverter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/converter/segment/from/impl/JoinTableConverter.java
@@ -35,14 +35,6 @@ import java.util.Optional;
  */
 public final class JoinTableConverter implements 
SQLSegmentConverter<JoinTableSegment, SqlJoin> {
     
-    private static final String JOIN_TYPE_INNER = "INNER";
-    
-    private static final String JOIN_TYPE_LEFT = "LEFT";
-    
-    private static final String JOIN_TYPE_RIGHT = "RIGHT";
-    
-    private static final String JOIN_TYPE_FULL = "FULL";
-    
     @Override
     public Optional<SqlJoin> convert(final JoinTableSegment segment) {
         SqlNode left = new 
TableConverter().convert(segment.getLeft()).orElseThrow(IllegalStateException::new);
@@ -50,25 +42,7 @@ public final class JoinTableConverter implements 
SQLSegmentConverter<JoinTableSe
         Optional<SqlNode> condition = new 
ExpressionConverter().convert(segment.getCondition());
         SqlLiteral conditionType = condition.isPresent() ? 
JoinConditionType.ON.symbol(SqlParserPos.ZERO) : 
JoinConditionType.NONE.symbol(SqlParserPos.ZERO);
         return Optional.of(
-                new SqlJoin(SqlParserPos.ZERO, left, 
SqlLiteral.createBoolean(false, SqlParserPos.ZERO), 
convertJoinType(segment.getJoinType()), right, conditionType, 
condition.orElse(null)));
-    }
-    
-    private SqlLiteral convertJoinType(final String joinType) {
-        if (null == joinType) {
-            return JoinType.COMMA.symbol(SqlParserPos.ZERO);
-        }
-        if (JOIN_TYPE_INNER.equals(joinType)) {
-            return JoinType.INNER.symbol(SqlParserPos.ZERO);
-        }
-        if (JOIN_TYPE_LEFT.equals(joinType)) {
-            return JoinType.LEFT.symbol(SqlParserPos.ZERO);
-        }
-        if (JOIN_TYPE_RIGHT.equals(joinType)) {
-            return JoinType.RIGHT.symbol(SqlParserPos.ZERO);
-        }
-        if (JOIN_TYPE_FULL.equals(joinType)) {
-            return JoinType.FULL.symbol(SqlParserPos.ZERO);
-        }
-        throw new UnsupportedOperationException("unsupported join type " + 
joinType);
+                new SqlJoin(SqlParserPos.ZERO, left, 
SqlLiteral.createBoolean(false, SqlParserPos.ZERO), 
JoinType.valueOf(segment.getJoinType()).symbol(SqlParserPos.ZERO), right, 
conditionType,
+                        condition.orElse(null)));
     }
 }
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 5cda32848a9..76dbf0e5251 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
@@ -79,6 +79,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LockCla
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LockClauseListContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.MatchExpressionContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.MultipleTablesClauseContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.NaturalJoinTypeContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.NullValueLiteralsContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.NumberLiteralsContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OnDuplicateKeyClauseContext;
@@ -147,6 +148,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.Se
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.InsertColumnsSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.OnDuplicateKeyColumnsSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.combine.CombineSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.CollateExpression;
@@ -183,7 +185,6 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.li
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.HavingSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.LockSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
-import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.combine.CombineSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeLengthSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment;
@@ -1558,39 +1559,41 @@ public abstract class MySQLStatementSQLVisitor extends 
MySQLStatementBaseVisitor
         result.setJoinType(getJoinType(ctx));
         TableSegment right = null != ctx.tableFactor() ? (TableSegment) 
visit(ctx.tableFactor()) : (TableSegment) visit(ctx.tableReference());
         result.setRight(right);
-        if (null != ctx.joinSpecification()) {
-            result = visitJoinSpecification(ctx.joinSpecification(), result);
-        }
-        return result;
+        return null != ctx.joinSpecification() ? 
visitJoinSpecification(ctx.joinSpecification(), result) : result;
     }
     
     private String getJoinType(final JoinedTableContext ctx) {
-        String joinType = null;
         if (null != ctx.innerJoinType()) {
-            joinType = ctx.innerJoinType().JOIN() != null ? 
JoinType.MYSQL_INNER_JOIN.getJoinType() : 
JoinType.MYSQL_STRAIGHT_JOIN.getJoinType();
-        } else if (null != ctx.outerJoinType()) {
-            joinType = ctx.outerJoinType().LEFT() != null ? 
JoinType.MYSQL_LEFT_JOIN.getJoinType() : 
JoinType.MYSQL_RIGHT_JOIN.getJoinType();
-        } else if (null != ctx.naturalJoinType()) {
-            if (null != ctx.naturalJoinType().LEFT()) {
-                joinType = JoinType.MYSQL_NATURAL_LEFT_JOIN.getJoinType();
-            } else if (null != ctx.naturalJoinType().RIGHT()) {
-                joinType = JoinType.MYSQL_NATURAL_RIGHT_JOIN.getJoinType();
-            } else {
-                joinType = JoinType.MYSQL_NATURAL_INNER_JOIN.getJoinType();
-            }
+            return JoinType.INNER.name();
+        }
+        if (null != ctx.outerJoinType()) {
+            return ctx.outerJoinType().LEFT() != null ? JoinType.LEFT.name() : 
JoinType.RIGHT.name();
+        }
+        if (null != ctx.naturalJoinType()) {
+            return getNaturalJoinType(ctx.naturalJoinType());
+        }
+        return JoinType.COMMA.name();
+    }
+    
+    private static String getNaturalJoinType(final NaturalJoinTypeContext ctx) 
{
+        if (null != ctx.LEFT()) {
+            return JoinType.LEFT.name();
+        } else if (null != ctx.RIGHT()) {
+            return JoinType.RIGHT.name();
+        } else {
+            return JoinType.INNER.name();
         }
-        return joinType;
     }
     
-    private JoinTableSegment visitJoinSpecification(final 
JoinSpecificationContext ctx, final JoinTableSegment joinTableSource) {
+    private JoinTableSegment visitJoinSpecification(final 
JoinSpecificationContext ctx, final JoinTableSegment result) {
         if (null != ctx.expr()) {
             ExpressionSegment condition = (ExpressionSegment) 
visit(ctx.expr());
-            joinTableSource.setCondition(condition);
+            result.setCondition(condition);
         }
         if (null != ctx.USING()) {
-            
joinTableSource.setUsing(ctx.columnNames().columnName().stream().map(each -> 
(ColumnSegment) visit(each)).collect(Collectors.toList()));
+            result.setUsing(ctx.columnNames().columnName().stream().map(each 
-> (ColumnSegment) visit(each)).collect(Collectors.toList()));
         }
-        return joinTableSource;
+        return result;
     }
     
     @Override
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
index e97dd1a47ad..a53968ecdd6 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/antlr4/imports/opengauss/DMLStatement.g4
@@ -385,22 +385,27 @@ tableReference
     ;
 
 joinedTable
-    : CROSS JOIN tableReference
-    | joinType JOIN tableReference joinQual
-    | JOIN tableReference joinQual
-    | NATURAL joinType JOIN tableReference
-    | NATURAL JOIN tableReference
+    : crossJoinType tableReference
+    | innerJoinType tableReference joinQual
+    | outerJoinType tableReference
+    | naturalJoinType tableReference
     ;
 
-joinType
-    : FULL joinOuter?
-    | LEFT joinOuter?
-    | RIGHT joinOuter?
-    | INNER
+crossJoinType
+    : CROSS JOIN
     ;
 
-joinOuter
-    : OUTER
+innerJoinType
+    : INNER? JOIN
+    ;
+
+outerJoinType
+    : (FULL | LEFT | RIGHT) OUTER? JOIN
+    ;
+    
+naturalJoinType
+    : NATURAL INNER? JOIN
+    | NATURAL (FULL | LEFT | RIGHT) OUTER? JOIN
     ;
 
 joinQual
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
index 1840a618893..344c5f85bdb 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussStatementSQLVisitor.java
@@ -69,8 +69,10 @@ import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.Joi
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.JoinedTableContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.LimitClauseContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NameListContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NaturalJoinTypeContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.NumberLiteralsContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.OptOnDuplicateKeyContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.OuterJoinTypeContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.OwnerContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ParameterMarkerContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.QualifiedNameContext;
@@ -104,6 +106,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.Whe
 import 
org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.WindowClauseContext;
 import 
org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
 import org.apache.shardingsphere.sql.parser.sql.common.constant.CombineType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.JoinType;
 import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
 import 
org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
@@ -1075,13 +1078,45 @@ public abstract class OpenGaussStatementSQLVisitor 
extends OpenGaussStatementBas
     }
     
     private JoinTableSegment visitJoinedTable(final JoinedTableContext ctx, 
final JoinTableSegment tableSegment) {
-        JoinTableSegment result = tableSegment;
         TableSegment right = (TableSegment) visit(ctx.tableReference());
-        result.setRight(right);
-        if (null != ctx.joinQual()) {
-            result = visitJoinQual(ctx.joinQual(), result);
+        tableSegment.setRight(right);
+        tableSegment.setJoinType(getJoinType(ctx));
+        return null != ctx.joinQual() ? visitJoinQual(ctx.joinQual(), 
tableSegment) : tableSegment;
+    }
+    
+    private String getJoinType(final JoinedTableContext ctx) {
+        if (null != ctx.crossJoinType()) {
+            return JoinType.CROSS.name();
+        }
+        if (null != ctx.innerJoinType()) {
+            return JoinType.INNER.name();
+        }
+        if (null != ctx.outerJoinType()) {
+            return getOutJoinType(ctx.outerJoinType());
+        }
+        if (null != ctx.naturalJoinType()) {
+            return getNaturalJoinType(ctx.naturalJoinType());
+        }
+        return JoinType.COMMA.name();
+    }
+    
+    private static String getOutJoinType(final OuterJoinTypeContext ctx) {
+        if (null != ctx.FULL()) {
+            return JoinType.FULL.name();
+        }
+        return null != ctx.LEFT() ? JoinType.LEFT.name() : 
JoinType.RIGHT.name();
+    }
+    
+    private static String getNaturalJoinType(final NaturalJoinTypeContext ctx) 
{
+        if (null != ctx.INNER()) {
+            return JoinType.INNER.name();
+        } else if (null != ctx.FULL()) {
+            return JoinType.FULL.name();
+        } else if (null != ctx.LEFT()) {
+            return JoinType.LEFT.name();
+        } else {
+            return JoinType.RIGHT.name();
         }
-        return result;
     }
     
     private JoinTableSegment visitJoinQual(final JoinQualContext ctx, final 
JoinTableSegment joinTableSource) {
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
index 5ca159e9e0c..8a458c2cebd 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
@@ -388,18 +388,27 @@ tableReference
     ;
 
 joinedTable
-    : CROSS JOIN tableReference
-    | joinType JOIN tableReference joinQual
-    | JOIN tableReference joinQual
-    | NATURAL joinType JOIN tableReference
-    | NATURAL JOIN tableReference
-    ;
-
-joinType
-    : FULL joinOuter?
-    | LEFT joinOuter?
-    | RIGHT joinOuter?
-    | INNER
+    : crossJoinType tableReference
+    | innerJoinType tableReference joinQual
+    | outerJoinType tableReference
+    | naturalJoinType tableReference
+    ;
+
+crossJoinType
+    : CROSS JOIN
+    ;
+
+innerJoinType
+    : INNER? JOIN
+    ;
+
+outerJoinType
+    : (FULL | LEFT | RIGHT) OUTER? JOIN
+    ;
+    
+naturalJoinType
+    : NATURAL INNER? JOIN
+    | NATURAL (FULL | LEFT | RIGHT) OUTER? JOIN
     ;
 
 joinOuter
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index 9c7087de2b0..fb4bb77589f 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -68,7 +68,9 @@ import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Jo
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.LimitClauseContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NameListContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NaturalJoinTypeContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.NumberLiteralsContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.OuterJoinTypeContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.OwnerContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.ParameterMarkerContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.QualifiedNameContext;
@@ -103,6 +105,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.Wi
 import 
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParserBaseVisitor;
 import 
org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
 import org.apache.shardingsphere.sql.parser.sql.common.constant.CombineType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.JoinType;
 import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
 import 
org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment;
@@ -1041,13 +1044,45 @@ public abstract class PostgreSQLStatementSQLVisitor 
extends PostgreSQLStatementP
     }
     
     private JoinTableSegment visitJoinedTable(final JoinedTableContext ctx, 
final JoinTableSegment tableSegment) {
-        JoinTableSegment result = tableSegment;
         TableSegment right = (TableSegment) visit(ctx.tableReference());
-        result.setRight(right);
-        if (null != ctx.joinQual()) {
-            result = visitJoinQual(ctx.joinQual(), result);
+        tableSegment.setRight(right);
+        tableSegment.setJoinType(getJoinType(ctx));
+        return null != ctx.joinQual() ? visitJoinQual(ctx.joinQual(), 
tableSegment) : tableSegment;
+    }
+    
+    private String getJoinType(final JoinedTableContext ctx) {
+        if (null != ctx.crossJoinType()) {
+            return JoinType.CROSS.name();
         }
-        return result;
+        if (null != ctx.innerJoinType()) {
+            return JoinType.INNER.name();
+        }
+        if (null != ctx.outerJoinType()) {
+            return getOutJoinType(ctx.outerJoinType());
+        }
+        if (null != ctx.naturalJoinType()) {
+            return getNaturalJoinType(ctx.naturalJoinType());
+        }
+        return JoinType.COMMA.name();
+    }
+    
+    private static String getNaturalJoinType(final NaturalJoinTypeContext ctx) 
{
+        if (null != ctx.INNER()) {
+            return JoinType.INNER.name();
+        } else if (null != ctx.FULL()) {
+            return JoinType.FULL.name();
+        } else if (null != ctx.LEFT()) {
+            return JoinType.LEFT.name();
+        } else {
+            return JoinType.RIGHT.name();
+        }
+    }
+    
+    private static String getOutJoinType(final OuterJoinTypeContext ctx) {
+        if (null != ctx.FULL()) {
+            return JoinType.FULL.name();
+        }
+        return null != ctx.LEFT() ? JoinType.LEFT.name() : 
JoinType.RIGHT.name();
     }
     
     private JoinTableSegment visitJoinQual(final JoinQualContext ctx, final 
JoinTableSegment joinTableSource) {
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/JoinType.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/JoinType.java
index c43ed084064..d1cb7cfa51f 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/JoinType.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/JoinType.java
@@ -22,26 +22,5 @@ package 
org.apache.shardingsphere.sql.parser.sql.common.constant;
  */
 public enum JoinType {
     
-    MYSQL_INNER_JOIN("INNER"),
-    MYSQL_STRAIGHT_JOIN("STRAIGHT"),
-    MYSQL_LEFT_JOIN("LEFT"),
-    MYSQL_RIGHT_JOIN("RIGHT"),
-    MYSQL_NATURAL_INNER_JOIN("NATURAL_INNER"),
-    MYSQL_NATURAL_LEFT_JOIN("NATURAL_LEFT"),
-    MYSQL_NATURAL_RIGHT_JOIN("NATURAL_RIGHT");
-    
-    private final String joinType;
-    
-    JoinType(final String joinType) {
-        this.joinType = joinType;
-    }
-    
-    /**
-     * Get join type.
-     *
-     * @return table join type
-     */
-    public String getJoinType() {
-        return joinType;
-    }
+    INNER, FULL, CROSS, LEFT, RIGHT, COMMA;
 }
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 d544d412620..f455b52eb2d 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
@@ -96,6 +96,7 @@ public final class SQLNodeConvertEngineParameterizedTest {
         SUPPORTED_SQL_CASE_IDS.add("select_order_by_asc_and_index_desc");
         SUPPORTED_SQL_CASE_IDS.add("select_group_by_with_having_count");
         SUPPORTED_SQL_CASE_IDS.add("select_constant_without_table");
+        
SUPPORTED_SQL_CASE_IDS.add("select_count_with_binding_tables_with_join");
     }
     
     private final String sqlCaseId;

Reply via email to