-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复mysql语句中partition和别名的顺序问题 #5351
- Loading branch information
Showing
2 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
core/src/test/java/com/alibaba/druid/bvt/sql/mysql/select/MySqlSelectTest_partition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.alibaba.druid.bvt.sql.mysql.select; | ||
|
||
import java.util.List; | ||
|
||
import com.alibaba.druid.sql.MysqlTest; | ||
import com.alibaba.druid.sql.ast.SQLStatement; | ||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; | ||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; | ||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; | ||
|
||
public class MySqlSelectTest_partition extends MysqlTest { | ||
public void test_0() throws Exception { | ||
String sql = "select\n" | ||
+ " p.id as id,\n" | ||
+ " c.template_no as templateNo\n" | ||
+ " from\n" | ||
+ " contract_relation_party partition(p0) p\n" | ||
+ " left join\n" | ||
+ " contract partition(p0) c\n" | ||
+ " on\n" | ||
+ " p.contract_sn = c.contract_sn\n" | ||
+ " and p.contract_id_no = c.id_no\n" | ||
+ " where p.seal_type is null\n" | ||
+ " order by p.update_time asc\n" | ||
+ " limit 5"; | ||
|
||
//System.out.println(sql); | ||
|
||
MySqlStatementParser parser = new MySqlStatementParser(sql); | ||
List<SQLStatement> statementList = parser.parseStatementList(); | ||
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0); | ||
|
||
assertEquals(1, statementList.size()); | ||
//System.out.println(stmt.toString()); | ||
assertEquals("SELECT p.id AS id, c.template_no AS templateNo\n" | ||
+ "FROM contract_relation_party PARTITION (p0) p\n" | ||
+ "\tLEFT JOIN contract PARTITION (p0) c\n" | ||
+ "\tON p.contract_sn = c.contract_sn\n" | ||
+ "\t\tAND p.contract_id_no = c.id_no\n" | ||
+ "WHERE p.seal_type IS NULL\n" | ||
+ "ORDER BY p.update_time ASC\n" | ||
+ "LIMIT 5", stmt.toString()); | ||
} | ||
} |