未验证 提交 43e94893 编写于 作者: J JingShang Lu 提交者: GitHub

Merge pull request #7035 from jingshanglu/mydev

fix create table parser and throw exception when parser error
...@@ -584,7 +584,7 @@ collectionOptions ...@@ -584,7 +584,7 @@ collectionOptions
; ;
characterSet_ characterSet_
: (CHARACTER | CHAR) SET EQ_? ignoredIdentifier_ : (CHARSET | CHAR SET) EQ_? ignoredIdentifier_
; ;
collateClause_ collateClause_
......
...@@ -24,7 +24,7 @@ createTable ...@@ -24,7 +24,7 @@ createTable
; ;
createIndex createIndex
: CREATE createIndexSpecification_ INDEX indexName ON tableName columnNameWithSort : CREATE createIndexSpecification_ INDEX indexName ON tableName columnNamesWithSort
; ;
alterTable alterTable
...@@ -314,14 +314,6 @@ constraintForColumn ...@@ -314,14 +314,6 @@ constraintForColumn
: (CONSTRAINT ignoredIdentifier_)? DEFAULT simpleExpr FOR columnName : (CONSTRAINT ignoredIdentifier_)? DEFAULT simpleExpr FOR columnName
; ;
columnNameWithSortsWithParen
: LP_ columnNameWithSort (COMMA_ columnNameWithSort)* RP_
;
columnNameWithSort
: columnName (ASC | DESC)?
;
generatedColumnNamesClause generatedColumnNamesClause
: generatedColumnNameClause COMMA_ periodClause | periodClause COMMA_ generatedColumnNameClause : generatedColumnNameClause COMMA_ periodClause | periodClause COMMA_ generatedColumnNameClause
; ;
...@@ -415,7 +407,7 @@ indexWithName ...@@ -415,7 +407,7 @@ indexWithName
; ;
indexNonClusterClause indexNonClusterClause
: NONCLUSTERED (hashWithBucket | columnNameWithSortsWithParen alterTableIndexOnClause?) : NONCLUSTERED (hashWithBucket | columnNamesWithSort alterTableIndexOnClause?)
; ;
alterTableIndexOnClause alterTableIndexOnClause
......
...@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sql.parser.core.parser; ...@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sql.parser.core.parser;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.antlr.v4.runtime.BailErrorStrategy; import org.antlr.v4.runtime.BailErrorStrategy;
import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.atn.PredictionMode; import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.misc.ParseCancellationException; import org.antlr.v4.runtime.misc.ParseCancellationException;
...@@ -59,7 +58,7 @@ public final class SQLParserExecutor { ...@@ -59,7 +58,7 @@ public final class SQLParserExecutor {
return (ParseASTNode) sqlParser.parse(); return (ParseASTNode) sqlParser.parse();
} catch (final ParseCancellationException ex) { } catch (final ParseCancellationException ex) {
((Parser) sqlParser).reset(); ((Parser) sqlParser).reset();
((Parser) sqlParser).setErrorHandler(new DefaultErrorStrategy()); ((Parser) sqlParser).setErrorHandler(new BailErrorStrategy());
((Parser) sqlParser).getInterpreter().setPredictionMode(PredictionMode.LL); ((Parser) sqlParser).getInterpreter().setPredictionMode(PredictionMode.LL);
return (ParseASTNode) sqlParser.parse(); return (ParseASTNode) sqlParser.parse();
} }
......
...@@ -26,6 +26,16 @@ ...@@ -26,6 +26,16 @@
<column name="status" /> <column name="status" />
</column-definition> </column-definition>
</create-table> </create-table>
<create-table sql-case-id="create_table_with_engin_charset">
<table name="t_log" start-index="13" stop-index="17" />
<column-definition type="int" primary-key="true" start-index="19" stop-index="36">
<column name="id" />
</column-definition>
<column-definition type="varchar" start-index="39" stop-index="56">
<column name="status" />
</column-definition>
</create-table>
<create-table sql-case-id="create_table_with_keyword"> <create-table sql-case-id="create_table_with_keyword">
<table name="t_log" start-index="13" stop-index="17" /> <table name="t_log" start-index="13" stop-index="17" />
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<sql-cases> <sql-cases>
<sql-case id="create_table" value="CREATE TABLE t_log(id int PRIMARY KEY, status varchar(10))" /> <sql-case id="create_table" value="CREATE TABLE t_log(id int PRIMARY KEY, status varchar(10))" />
<sql-case id="create_table_with_engin_charset" value="CREATE TABLE t_log(id int PRIMARY KEY, status varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" db-types="MySQL" />
<sql-case id="create_table_with_keyword" value="CREATE TABLE t_log(id int PRIMARY KEY, status boolean)" db-types="PostgreSQL" /> <sql-case id="create_table_with_keyword" value="CREATE TABLE t_log(id int PRIMARY KEY, status boolean)" db-types="PostgreSQL" />
<sql-case id="create_table_if_not_exists" value="CREATE TABLE IF NOT EXISTS t_log(id int, status varchar(10))" db-types="MySQL,PostgreSQL" /> <sql-case id="create_table_if_not_exists" value="CREATE TABLE IF NOT EXISTS t_log(id int, status varchar(10))" db-types="MySQL,PostgreSQL" />
<sql-case id="create_temporary_table_if_not_exists" value="CREATE TEMPORARY TABLE IF NOT EXISTS t_temp_log(id int, status varchar(10))" db-types="MySQL,PostgreSQL" /> <sql-case id="create_temporary_table_if_not_exists" value="CREATE TEMPORARY TABLE IF NOT EXISTS t_temp_log(id int, status varchar(10))" db-types="MySQL,PostgreSQL" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册