forked from alibaba/druid
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化cast array语法的解析逻辑 alibaba#5894
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
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
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
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
37 changes: 37 additions & 0 deletions
37
core/src/test/java/com/alibaba/druid/bvt/sql/mysql/issues/Issue5894.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,37 @@ | ||
package com.alibaba.druid.bvt.sql.mysql.issues; | ||
|
||
import java.util.List; | ||
|
||
import com.alibaba.druid.DbType; | ||
import com.alibaba.druid.sql.SQLParseAssertUtil; | ||
import com.alibaba.druid.sql.ast.SQLStatement; | ||
import com.alibaba.druid.sql.parser.SQLParserUtils; | ||
import com.alibaba.druid.sql.parser.SQLStatementParser; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author lizongbo | ||
* @see <a href="https://github.com/alibaba/druid/issues/5894>Issue来源</a> | ||
* @see <a href="https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast">CAST(expr AS type [ARRAY])</a> | ||
*/ | ||
public class Issue5894 { | ||
|
||
@Test | ||
public void test_parse_aschararray() { | ||
for (DbType dbType : new DbType[]{DbType.mysql}) { | ||
for (String sql : new String[]{ | ||
"alter table db1.rs_push_mall_data add key idx_bill_no_json((CAST(bill_no_json AS CHAR(50) ARRAY)));", | ||
}) { | ||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType); | ||
List<SQLStatement> statementList = parser.parseStatementList(); | ||
assertEquals(1, statementList.size()); | ||
assertEquals("ALTER TABLE db1.rs_push_mall_data\n" | ||
+ "\tADD KEY idx_bill_no_json (CAST(bill_no_json AS CHAR(50) ARRAY));", statementList.get(0).toString()); | ||
SQLParseAssertUtil.assertParseSql(sql, dbType); | ||
} | ||
} | ||
} | ||
} |