-
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.
Merge pull request #5795 from lizongbo/master
增强postgresql create index 的解析能力 #5780
- Loading branch information
Showing
5 changed files
with
115 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- | ||
please follow the issue template below for bug reports and feature requests | ||
for example, if you are reporting a bug, please provide the following information: | ||
dbtype: mysql | ||
dbversion: 5.7 | ||
duird version: 1.2.22 | ||
error sql: select * from test | ||
error info: error message | ||
--> | ||
**dbtype:** | ||
**dbversion:** | ||
**druid verion:** | ||
**error sql:** | ||
**testcase code:** | ||
**stacktrace info:** | ||
**error info:** | ||
--- | ||
<!-- | ||
Thanks for taking the time to create an issue. Please read the following: | ||
- For bugs, specify affected versions and explain what you are trying to do. | ||
- For enhancements, provide context and describe the problem. | ||
Issue or Pull Request? Create only one, not both. GitHub treats them as the same. | ||
If unsure, start with an issue, and if you submit a pull request later, the | ||
issue will be closed as superseded. | ||
--> |
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
59 changes: 59 additions & 0 deletions
59
core/src/test/java/com/alibaba/druid/bvt/sql/postgresql/issues/Issue5780.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,59 @@ | ||
package com.alibaba.druid.bvt.sql.postgresql.issues; | ||
|
||
import java.util.List; | ||
|
||
import com.alibaba.druid.DbType; | ||
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/5780">Issue来源</a> | ||
* @see <a href="https://www.postgresql.org/docs/current/sql-altertable.html">ALTER TABLE</a> | ||
* @see <a href="https://www.postgresql.org/docs/current/sql-createindex.html">CREATE INDEX</a> | ||
*/ | ||
public class Issue5780 { | ||
|
||
@Test | ||
public void test_parse_alter_table_sql() { | ||
for (DbType dbType : new DbType[]{DbType.postgresql, DbType.greenplum, DbType.edb}) { | ||
|
||
for (String sql : new String[]{ | ||
"CREATE INDEX \"index_log\" ON \"public\".\"check_log\" USING btree (\n" + | ||
" \"t_no\" COLLATE \"pg_catalog\".\"default\" \"pg_catalog\".\"text_ops\" ASC NULLS LAST\n" + | ||
");", | ||
//"CREATE UNIQUE INDEX title_idx ON films (title);", | ||
//"CREATE UNIQUE INDEX title_idx ON films (title) INCLUDE (director, rating);", | ||
// "CREATE INDEX title_idx ON films (title) WITH (deduplicate_items = off);", | ||
// "CREATE INDEX ON films ((lower(title)));", | ||
// "CREATE INDEX title_idx_german ON films (title COLLATE \"de_DE\");", | ||
// "CREATE INDEX title_idx_nulls_low ON films (title NULLS FIRST);", | ||
// "CREATE UNIQUE INDEX title_idx ON films (title) WITH (fillfactor = 70);", | ||
// "CREATE INDEX gin_idx ON documents_table USING GIN (locations) WITH (fastupdate = off);", | ||
// "CREATE INDEX code_idx ON films (code) TABLESPACE indexspace;", | ||
// "CREATE INDEX pointloc\n" | ||
// + " ON points USING gist (box(location,location));", | ||
// "CREATE INDEX CONCURRENTLY sales_quantity_index ON sales_table (quantity);", | ||
}) { | ||
System.out.println("原始的sql===" + sql); | ||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType); | ||
List<SQLStatement> statementList = parser.parseStatementList(); | ||
System.out.println("生成的sql===" + statementList); | ||
StringBuilder sb = new StringBuilder(); | ||
for (SQLStatement statement : statementList) { | ||
sb.append(statement.toString()).append(";"); | ||
} | ||
sb.deleteCharAt(sb.length() - 1); | ||
parser = SQLParserUtils.createSQLStatementParser(sb.toString(), dbType); | ||
List<SQLStatement> statementListNew = parser.parseStatementList(); | ||
System.out.println("重新解析再生成的sql===" + statementListNew); | ||
assertEquals(statementList.toString(), statementListNew.toString()); | ||
} | ||
} | ||
} | ||
} |