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 eda0fc2  assign JoinTableSegment joinType (#11212)
eda0fc2 is described below

commit eda0fc2a1180dc7d04b60a3e9ee1de04be64db32
Author: tuichenchuxin <[email protected]>
AuthorDate: Tue Jul 13 08:12:29 2021 +0800

    assign JoinTableSegment joinType (#11212)
    
    * assign JoinTableSegment joinType
    
    * assign JoinTableSegment joinType
    
    * assign JoinTableSegment joinType
    
    * Assign JoinTableSegment joinType.
    
    * Assign JoinTableSegment joinType.
    
    * Assign JoinTableSegment joinType.
---
 .../SelectStatementSqlNodeConverterTest.java       |  3 ++
 .../statement/impl/MySQLStatementSQLVisitor.java   | 24 ++++++++++-
 .../sql/parser/sql/common/constant/JoinType.java   | 46 ++++++++++++++++++++++
 3 files changed, 71 insertions(+), 2 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/convert/SelectStatementSqlNodeConverterTest.java
 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/convert/SelectStatementSqlNodeConverterTest.java
index 332b038..ef50e96 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/convert/SelectStatementSqlNodeConverterTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-optimize/src/test/java/org/apache/shardingsphere/infra/optimize/core/convert/SelectStatementSqlNodeConverterTest.java
@@ -23,7 +23,9 @@ import org.apache.calcite.sql.SqlSelect;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -149,6 +151,7 @@ public final class SelectStatementSqlNodeConverterTest 
extends BaseSqlNodeConver
                 + "o1.order_id = o2.order_id where o1.status='FINISHED' and 
o2.order_item_id > 1024 and 1=1 order by "
                 + "o1.order_id desc";
         SQLStatement sqlStatement = sqlStatementParserEngine.parse(sql, false);
+        assertEquals("INNER", ((JoinTableSegment) ((MySQLSelectStatement) 
sqlStatement).getFrom()).getJoinType());
         SqlNode sqlNode = SqlNodeConvertEngine.convert(sqlStatement);
         assertThat(sqlNode, instanceOf(SqlSelect.class));
         SqlSelect sqlSelect = (SqlSelect) sqlNode;
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 484900f..a161f783 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
@@ -120,6 +120,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WhereCl
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WindowClauseContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WindowFunctionContext;
 import 
org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+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.segment.ddl.constraint.ConstraintSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
@@ -198,7 +199,7 @@ import java.util.Properties;
 @NoArgsConstructor
 @Getter(AccessLevel.PROTECTED)
 public abstract class MySQLStatementSQLVisitor extends 
MySQLStatementBaseVisitor<ASTNode> {
-    
+
     private int currentParameterIndex;
     
     public MySQLStatementSQLVisitor(final Properties props) {
@@ -1362,6 +1363,7 @@ public abstract class MySQLStatementSQLVisitor extends 
MySQLStatementBaseVisitor
         result.setLeft(tableSegment);
         result.setStartIndex(tableSegment.getStartIndex());
         result.setStopIndex(ctx.stop.getStopIndex());
+        result.setJoinType(getJoinType(ctx));
         TableSegment right = null != ctx.tableFactor() ? (TableSegment) 
visit(ctx.tableFactor()) : (TableSegment) visit(ctx.tableReference());
         result.setRight(right);
         if (null != ctx.joinSpecification()) {
@@ -1369,7 +1371,25 @@ public abstract class MySQLStatementSQLVisitor extends 
MySQLStatementBaseVisitor
         }
         return 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;
+    }
+
     private JoinTableSegment visitJoinSpecification(final 
JoinSpecificationContext ctx, final JoinTableSegment joinTableSource) {
         if (null != ctx.expr()) {
             ExpressionSegment condition = (ExpressionSegment) 
visit(ctx.expr());
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
new file mode 100644
index 0000000..f00d6c6
--- /dev/null
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/JoinType.java
@@ -0,0 +1,46 @@
+/*
+ * 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.sql.parser.sql.common.constant;
+
+/**
+ * Join type enum.
+ */
+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;
+    }
+}

Reply via email to