mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -4,14 +4,14 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<version>1.2.2</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>druid-spring-boot-starter</name>
|
||||
<description>Spring Boot with Druid support,help you simplify Druid config in Spring Boot.</description>
|
||||
<url>https://github.com/alibaba/druid</url>
|
||||
|
||||
<properties>
|
||||
<druid.version>1.2.1</druid.version>
|
||||
<druid.version>1.2.2</druid.version>
|
||||
<spring-boot.version>1.5.12.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.2_preview_01</version>
|
||||
<version>1.2.2</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<name>druid</name>
|
||||
|
||||
@@ -37,6 +37,7 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLCrea
|
||||
protected List<SQLAssignItem> properties = new ArrayList<SQLAssignItem>();
|
||||
protected List<SQLAssignItem> tableProperties = new ArrayList<SQLAssignItem>();
|
||||
protected boolean storing;
|
||||
protected boolean ifNotExists;
|
||||
|
||||
public SQLCreateIndexStatement() {
|
||||
indexDefinition.setParent(this);
|
||||
@@ -162,6 +163,7 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLCrea
|
||||
public SQLCreateIndexStatement clone() {
|
||||
SQLCreateIndexStatement x = new SQLCreateIndexStatement();
|
||||
indexDefinition.cloneTo(x.indexDefinition);
|
||||
x.setIfNotExists(ifNotExists);
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -318,4 +320,12 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLCrea
|
||||
public List<SQLSelectOrderByItem> getColumns() {
|
||||
return indexDefinition.getColumns();
|
||||
}
|
||||
|
||||
public boolean isIfNotExists() {
|
||||
return ifNotExists;
|
||||
}
|
||||
|
||||
public void setIfNotExists(boolean ifNotExists) {
|
||||
this.ifNotExists = ifNotExists;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -608,6 +608,13 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
|
||||
accept(Token.INDEX);
|
||||
|
||||
if (lexer.token() == Token.IF) {
|
||||
lexer.nextToken();
|
||||
accept(Token.NOT);
|
||||
accept(Token.EXISTS);
|
||||
stmt.setIfNotExists(true);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CONCURRENTLY)) {
|
||||
lexer.nextToken();
|
||||
stmt.setConcurrently(true);
|
||||
|
||||
@@ -2401,6 +2401,10 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
|
||||
print0(ucase ? "INDEX" : "index");
|
||||
|
||||
if (x.isIfNotExists()) {
|
||||
print0(ucase ? " IF NOT EXISTS" : " if not exists");
|
||||
}
|
||||
|
||||
if (x.isConcurrently()) {
|
||||
print0(ucase ? " CONCURRENTLY" : " concurrently");
|
||||
}
|
||||
|
||||
@@ -3738,9 +3738,13 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
if (lexer.token == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
SQLExpr arg = this.expr();
|
||||
arg.setParent(charType);
|
||||
charType.addArgument(arg);
|
||||
if (typeNameHashCode == FnvHash.Constants.ENUM) {
|
||||
exprList(charType.getArguments(), charType);
|
||||
} else {
|
||||
SQLExpr arg = this.expr();
|
||||
arg.setParent(charType);
|
||||
charType.addArgument(arg);
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
@@ -3910,6 +3914,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|| hash == FnvHash.Constants.TEXT
|
||||
|| hash == FnvHash.Constants.MEDIUMTEXT
|
||||
|| hash == FnvHash.Constants.LONGTEXT
|
||||
|| hash == FnvHash.Constants.ENUM
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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 com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateFunctionTest_1 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "sql : \n" +
|
||||
" create function `test1`.`proc1`(`a` enum('1','2') charset utf8)\n" +
|
||||
" returns int(10)\n" +
|
||||
" DETERMINISTIC \n" +
|
||||
" BEGIN\n" +
|
||||
" return 0;\n" +
|
||||
" END ";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
// print(statementList);
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
System.out.println(SQLUtils.toMySqlString(stmt));
|
||||
|
||||
assertEquals("CREATE FUNCTION `test1`.`proc1` (\n" +
|
||||
"\t`a` enum('1', '2') CHARACTER SET utf8\n" +
|
||||
")\n" +
|
||||
"RETURNS int(10) DETERMINISTIC\n" +
|
||||
"BEGIN\n" +
|
||||
"\tRETURN 0;\n" +
|
||||
"END", SQLUtils.toMySqlString(stmt));
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+21
-37
@@ -17,7 +17,13 @@ package com.alibaba.druid.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLParameter;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateFunctionStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
@@ -26,46 +32,24 @@ import java.util.List;
|
||||
public class MySqlCreateProcedureTest15 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "CREATE DEFINER=`root`@`%` PROCEDURE `load_part_tab`()\n" +
|
||||
"BEGIN \n" +
|
||||
"DECLARE v INT DEFAULT 0; \n" +
|
||||
"WHILE v < 1 DO \n" +
|
||||
"INSERT INTO part_tab \n" +
|
||||
"VALUES (v,'testing partitions',ADDDATE('1995-01-01',(RAND(v)*36520) MOD 3652)); \n" +
|
||||
"SET v = v + 1; \n" +
|
||||
"END WHILE; \n" +
|
||||
"END";
|
||||
String sql = " create function `test1`.`proc1`(`a` enum('1','2') charset utf8)\n" +
|
||||
" returns int(10)\n" +
|
||||
" DETERMINISTIC \n" +
|
||||
" BEGIN\n" +
|
||||
" return 0;\n" +
|
||||
" END ";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
// print(statementList);
|
||||
assertEquals(1, statementList.size());
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL, false);
|
||||
SQLCreateFunctionStatement stmt = parser.parseCreateFunction();
|
||||
assertEquals(1, stmt.getParameters().size());
|
||||
|
||||
System.out.println(SQLUtils.toMySqlString(stmt));
|
||||
|
||||
assertEquals("CREATE PROCEDURE `load_part_tab` ()\n" +
|
||||
assertEquals("CREATE FUNCTION `test1`.`proc1` (\n" +
|
||||
"\t`a` enum('1', '2') CHARACTER SET utf8\n" +
|
||||
")\n" +
|
||||
"RETURNS int(10) DETERMINISTIC\n" +
|
||||
"BEGIN\n" +
|
||||
"\tDECLARE v INT DEFAULT 0;\n" +
|
||||
"\tWHILE v < 1 DO\n" +
|
||||
"\tINSERT INTO part_tab\n" +
|
||||
"\tVALUES (v, 'testing partitions', ADDDATE('1995-01-01', RAND(v) * 36520 % 3652));\n" +
|
||||
"\tSET v = v + 1;\n" +
|
||||
"\tEND WHILE;\n" +
|
||||
"END", SQLUtils.toMySqlString(stmt));
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
assertTrue(visitor.containsTable("part_tab"));
|
||||
"\tRETURN 0;\n" +
|
||||
"END", stmt.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-6
@@ -28,18 +28,18 @@ public class MySqlCreateTableTest150_eunm_set_with_charset extends TestCase {
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
assertEquals("CREATE TEMPORARY TABLE `tb_xx` (\n" +
|
||||
"\t`col_ttuap` enum('value1', 'value2') GENERATED ALWAYS AS (1 + 2) VIRTUAL CHARACTER SET utf8 COLLATE utf8_unicode_ci UNIQUE COMMENT 'comment' REFERENCES tb_fn (`col_qzqnqrrfyv`) MATCH PARTIAL\n" +
|
||||
"\t`col_ttuap` enum('value1', 'value2') CHARACTER SET utf8 COLLATE utf8_unicode_ci GENERATED ALWAYS AS (1 + 2) VIRTUAL UNIQUE COMMENT 'comment' REFERENCES tb_fn (`col_qzqnqrrfyv`) MATCH PARTIAL\n" +
|
||||
") MIN_ROWS = 1 CHECKSUM = 1 COMPRESSION = 'NONE'", stmt.toString());
|
||||
|
||||
assertEquals("create temporary table `tb_xx` (\n" +
|
||||
"\t`col_ttuap` enum('value1', 'value2') generated always as (1 + 2) virtual character set utf8 collate utf8_unicode_ci unique comment 'comment' references tb_fn (`col_qzqnqrrfyv`) match partial\n" +
|
||||
"\t`col_ttuap` enum('value1', 'value2') character set utf8 collate utf8_unicode_ci generated always as (1 + 2) virtual unique comment 'comment' references tb_fn (`col_qzqnqrrfyv`) match partial\n" +
|
||||
") min_rows = 1 checksum = 1 compression = 'NONE'", stmt.toLowerCaseString());
|
||||
}
|
||||
|
||||
public void test_1() {
|
||||
String sql = "create temporary table `tb_xx` (\n" +
|
||||
"`col_ttuap` set('value1','value2') character set utf8 collate utf8_unicode_ci generated always as ( 1+2 ) virtual unique comment 'comment' references tb_fn ( `col_qzqnqrrfyv` ) match partial\n" +
|
||||
") min_rows = 1 , checksum = 1 , compression 'NONE'";
|
||||
"\t`col_ttuap` enum('value1', 'value2') character set utf8 collate utf8_unicode_ci generated always as (1 + 2) virtual unique comment 'comment' references tb_fn (`col_qzqnqrrfyv`) match partial\n" +
|
||||
") min_rows = 1 checksum = 1 compression = 'NONE'";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
@@ -48,11 +48,11 @@ public class MySqlCreateTableTest150_eunm_set_with_charset extends TestCase {
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
assertEquals("CREATE TEMPORARY TABLE `tb_xx` (\n" +
|
||||
"\t`col_ttuap` set('value1', 'value2') GENERATED ALWAYS AS (1 + 2) VIRTUAL CHARACTER SET utf8 COLLATE utf8_unicode_ci UNIQUE COMMENT 'comment' REFERENCES tb_fn (`col_qzqnqrrfyv`) MATCH PARTIAL\n" +
|
||||
"\t`col_ttuap` enum('value1', 'value2') CHARACTER SET utf8 COLLATE utf8_unicode_ci GENERATED ALWAYS AS (1 + 2) VIRTUAL UNIQUE COMMENT 'comment' REFERENCES tb_fn (`col_qzqnqrrfyv`) MATCH PARTIAL\n" +
|
||||
") MIN_ROWS = 1 CHECKSUM = 1 COMPRESSION = 'NONE'", stmt.toString());
|
||||
|
||||
assertEquals("create temporary table `tb_xx` (\n" +
|
||||
"\t`col_ttuap` set('value1', 'value2') generated always as (1 + 2) virtual character set utf8 collate utf8_unicode_ci unique comment 'comment' references tb_fn (`col_qzqnqrrfyv`) match partial\n" +
|
||||
"\t`col_ttuap` enum('value1', 'value2') character set utf8 collate utf8_unicode_ci generated always as (1 + 2) virtual unique comment 'comment' references tb_fn (`col_qzqnqrrfyv`) match partial\n" +
|
||||
") min_rows = 1 checksum = 1 compression = 'NONE'", stmt.toLowerCaseString());
|
||||
}
|
||||
|
||||
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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 com.alibaba.druid.bvt.sql.mysql.select;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlSelectTest_316_json_table
|
||||
extends MysqlTest {
|
||||
public void test_0() throws Exception {
|
||||
String sql = "SELECT *\n" +
|
||||
"FROM\n" +
|
||||
"JSON_TABLE(\n" +
|
||||
" '[ {\"c1\": null} ]',\n" +
|
||||
" '$[*]' COLUMNS( c1 INT PATH '$.c1' ERROR ON ERROR )\n" +
|
||||
") as jt;";
|
||||
|
||||
SQLStatement stmt = SQLUtils
|
||||
.parseSingleStatement(sql, DbType.mysql);
|
||||
|
||||
System.out.println(stmt.toString());
|
||||
|
||||
assertEquals("SELECT *\n" +
|
||||
"FROM JSON_TABLE('[ {\"c1\": null} ]' '$[*]'\n" +
|
||||
"\tCOLUMNS (\n" +
|
||||
"\t\tc1 INT PATH '$.c1' DEFAULT ERROR ON ERROR\n" +
|
||||
"\t)\n" +
|
||||
") jt;", stmt.toString());
|
||||
|
||||
assertEquals("select *\n" +
|
||||
"from json_table('[ {\"c1\": null} ]' '$[*]'\n" +
|
||||
"\tcolumns (\n" +
|
||||
"\t\tc1 INT path '$.c1' default ERROR on error\n" +
|
||||
"\t)\n" +
|
||||
") jt;", stmt.toLowerCaseString());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
assertEquals(0, visitor.getOrderByColumns().size());
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
String sql = "SELECT *\n" +
|
||||
"FROM\n" +
|
||||
"JSON_TABLE(\n" +
|
||||
" '[{\"a\":\"3\"},{\"a\":2},{\"b\":1},{\"a\":0},{\"a\":[1,2]}]',\n" +
|
||||
" \"$[*]\"\n" +
|
||||
" COLUMNS(\n" +
|
||||
" rowid FOR ORDINALITY,\n" +
|
||||
" ac VARCHAR(100) PATH \"$.a\" DEFAULT '111' ON EMPTY DEFAULT '999' ON ERROR,\n" +
|
||||
" aj JSON PATH \"$.a\" DEFAULT '{\"x\": 333}' ON EMPTY,\n" +
|
||||
" bx INT EXISTS PATH \"$.b\"\n" +
|
||||
" )\n" +
|
||||
") AS tt;";
|
||||
|
||||
SQLStatement stmt = SQLUtils
|
||||
.parseSingleStatement(sql, DbType.mysql);
|
||||
|
||||
System.out.println(stmt.toString());
|
||||
|
||||
assertEquals("SELECT *\n" +
|
||||
"FROM JSON_TABLE('[{\"a\":\"3\"},{\"a\":2},{\"b\":1},{\"a\":0},{\"a\":[1,2]}]' '$[*]'\n" +
|
||||
"\tCOLUMNS (\n" +
|
||||
"\t\trowid, \n" +
|
||||
"\t\tac VARCHAR(100) PATH '$.a' DEFAULT '111' ON EMPTY DEFAULT '999' ON ERROR, \n" +
|
||||
"\t\taj JSON PATH '$.a' DEFAULT '{\"x\": 333}' ON EMPTY, \n" +
|
||||
"\t\tbx INT EXISTS PATH '$.b'\n" +
|
||||
"\t)\n" +
|
||||
") tt;", stmt.toString());
|
||||
|
||||
assertEquals("select *\n" +
|
||||
"from json_table('[{\"a\":\"3\"},{\"a\":2},{\"b\":1},{\"a\":0},{\"a\":[1,2]}]' '$[*]'\n" +
|
||||
"\tcolumns (\n" +
|
||||
"\t\trowid, \n" +
|
||||
"\t\tac VARCHAR(100) path '$.a' default '111' on empty default '999' on error, \n" +
|
||||
"\t\taj JSON path '$.a' default '{\"x\": 333}' on empty, \n" +
|
||||
"\t\tbx INT exists path '$.b'\n" +
|
||||
"\t)\n" +
|
||||
") tt;", stmt.toLowerCaseString());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
assertEquals(0, visitor.getOrderByColumns().size());
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
String sql = "SELECT *\n" +
|
||||
"FROM\n" +
|
||||
" JSON_TABLE(\n" +
|
||||
" '[{\"a\": 1, \"b\": [11,111]}, {\"a\": 2, \"b\": [22,222]}]',\n" +
|
||||
" '$[*]' COLUMNS(\n" +
|
||||
" a INT PATH '$.a',\n" +
|
||||
" NESTED PATH '$.b[*]' COLUMNS (b1 INT PATH '$'),\n" +
|
||||
" NESTED PATH '$.b[*]' COLUMNS (b2 INT PATH '$')\n" +
|
||||
" )\n" +
|
||||
") AS jt;";
|
||||
|
||||
SQLStatement stmt = SQLUtils
|
||||
.parseSingleStatement(sql, DbType.mysql);
|
||||
|
||||
System.out.println(stmt.toString());
|
||||
|
||||
assertEquals("SELECT *\n" +
|
||||
"FROM JSON_TABLE('[{\"a\": 1, \"b\": [11,111]}, {\"a\": 2, \"b\": [22,222]}]' '$[*]'\n" +
|
||||
"\tCOLUMNS (\n" +
|
||||
"\t\ta INT PATH '$.a', \n" +
|
||||
"\t\tNESTED PATH '$.b[*]' COLUMNS (b1 INT PATH '$'), \n" +
|
||||
"\t\tNESTED PATH '$.b[*]' COLUMNS (b2 INT PATH '$')\n" +
|
||||
"\t)\n" +
|
||||
") jt;", stmt.toString());
|
||||
|
||||
assertEquals("select *\n" +
|
||||
"from json_table('[{\"a\": 1, \"b\": [11,111]}, {\"a\": 2, \"b\": [22,222]}]' '$[*]'\n" +
|
||||
"\tcolumns (\n" +
|
||||
"\t\ta INT path '$.a', \n" +
|
||||
"\t\tNESTED path '$.b[*]' columns (b1 INT path '$'), \n" +
|
||||
"\t\tNESTED path '$.b[*]' columns (b2 INT path '$')\n" +
|
||||
"\t)\n" +
|
||||
") jt;", stmt.toLowerCaseString());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
assertEquals(0, visitor.getOrderByColumns().size());
|
||||
}
|
||||
|
||||
public void test_3() throws Exception {
|
||||
String sql = "SELECT *\n" +
|
||||
"FROM\n" +
|
||||
" JSON_TABLE(\n" +
|
||||
" '[{\"a\": \"a_val\",\n" +
|
||||
" \"b\": [{\"c\": \"c_val\", \"l\": [1,2]}]},\n" +
|
||||
" {\"a\": \"a_val\",\n" +
|
||||
" \"b\": [{\"c\": \"c_val\",\"l\": [11]}, {\"c\": \"c_val\", \"l\": [22]}]}]',\n" +
|
||||
" '$[*]' COLUMNS(\n" +
|
||||
" top_ord FOR ORDINALITY,\n" +
|
||||
" apath VARCHAR(10) PATH '$.a',\n" +
|
||||
" NESTED PATH '$.b[*]' COLUMNS (\n" +
|
||||
" bpath VARCHAR(10) PATH '$.c',\n" +
|
||||
" ord FOR ORDINALITY,\n" +
|
||||
" NESTED PATH '$.l[*]' COLUMNS (lpath varchar(10) PATH '$')\n" +
|
||||
" )\n" +
|
||||
" )\n" +
|
||||
") as jt;";
|
||||
|
||||
SQLStatement stmt = SQLUtils
|
||||
.parseSingleStatement(sql, DbType.mysql);
|
||||
|
||||
System.out.println(stmt.toString());
|
||||
|
||||
assertEquals("SELECT *\n" +
|
||||
"FROM JSON_TABLE('[{\"a\": \"a_val\",\n" +
|
||||
" \"b\": [{\"c\": \"c_val\", \"l\": [1,2]}]},\n" +
|
||||
" {\"a\": \"a_val\",\n" +
|
||||
" \"b\": [{\"c\": \"c_val\",\"l\": [11]}, {\"c\": \"c_val\", \"l\": [22]}]}]' '$[*]'\n" +
|
||||
"\tCOLUMNS (\n" +
|
||||
"\t\ttop_ord, \n" +
|
||||
"\t\tapath VARCHAR(10) PATH '$.a', \n" +
|
||||
"\t\tNESTED PATH '$.b[*]' COLUMNS (bpath VARCHAR(10) PATH '$.c', ord, NESTED PATH '$.l[*]' COLUMNS (lpath varchar(10) PATH '$'))\n" +
|
||||
"\t)\n" +
|
||||
") jt;", stmt.toString());
|
||||
|
||||
assertEquals("select *\n" +
|
||||
"from json_table('[{\"a\": \"a_val\",\n" +
|
||||
" \"b\": [{\"c\": \"c_val\", \"l\": [1,2]}]},\n" +
|
||||
" {\"a\": \"a_val\",\n" +
|
||||
" \"b\": [{\"c\": \"c_val\",\"l\": [11]}, {\"c\": \"c_val\", \"l\": [22]}]}]' '$[*]'\n" +
|
||||
"\tcolumns (\n" +
|
||||
"\t\ttop_ord, \n" +
|
||||
"\t\tapath VARCHAR(10) path '$.a', \n" +
|
||||
"\t\tNESTED path '$.b[*]' columns (bpath VARCHAR(10) path '$.c', ord, NESTED path '$.l[*]' columns (lpath varchar(10) path '$'))\n" +
|
||||
"\t)\n" +
|
||||
") jt;", stmt.toLowerCaseString());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
assertEquals(0, visitor.getOrderByColumns().size());
|
||||
}
|
||||
}
|
||||
@@ -52,4 +52,29 @@ public class PGCreateIndexTest_0 extends PGTest {
|
||||
assertEquals(1, visitor.getColumns().size() );
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
String sql = "CREATE INDEX if not exists \"calculate_measure_dataset_id_idx\" ON \"calculate_measure\" USING btree (\"dataset_id\");";
|
||||
|
||||
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals("CREATE INDEX IF NOT EXISTS \"calculate_measure_dataset_id_idx\" ON \"calculate_measure\" USING btree (\"dataset_id\");", SQLUtils.toPGString(stmt));
|
||||
|
||||
assertEquals("create index if not exists \"calculate_measure_dataset_id_idx\" on \"calculate_measure\" using btree (\"dataset_id\");", stmt.toLowerCaseString());
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
// System.out.println("fields : " + visitor.getColumns());
|
||||
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("public.city")));
|
||||
//
|
||||
// assertTrue(visitor.getTables().get(new TableStat.Name("public.city")).getCreateIndexCount() == 1);
|
||||
//
|
||||
// assertEquals(1, visitor.getColumns().size() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user