You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/11 02:34:32 UTC

[GitHub] [shardingsphere] jingshanglu commented on a change in pull request #6769: PostgreSQL DDL

jingshanglu commented on a change in pull request #6769:
URL: https://github.com/apache/shardingsphere/pull/6769#discussion_r468289768



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/PostgreSQLKeyword.g4
##########
@@ -1380,3 +1380,39 @@ VERBOSE
 PARAM
     : P A R A M
     ;
+
+LC_COLLATE
+    : L C UL_ C O L L A T E
+    ;
+
+LC_CTYPE
+    : L C UL_ C T Y P E
+    ;
+
+IS_TEMPLATE
+    : I S UL_ T E M P L A T E
+    ;
+
+ALLOW_CONNECTIONS
+    : A L L O W UL_ C O N N E C T I O N S
+    ;
+
+REPLACCE
+    : R E P L A C C E
+    ;
+
+TMP
+    : T M P
+    ;
+
+TMPORARY
+    : T M P O R A R Y
+    ;

Review comment:
       Are this word keyword?

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/BaseRule.g4
##########
@@ -1351,3 +1351,320 @@ ignoredIdentifier_
 ignoredIdentifiers_
     : ignoredIdentifier_ (COMMA_ ignoredIdentifier_)*
     ;
+
+signedIconst
+    : NUMBER_
+    | PLUS_ NUMBER_
+    | MINUS_ NUMBER_
+    ;
+
+optBooleanOrString
+    : TRUE
+    | FALSE
+    | ON
+    | nonReservedWord
+    | STRING_
+    ;
+
+nonReservedWord
+    : identifier
+    | unreservedWord
+    | colNameKeyword
+    | typeFuncNameKeyword
+    ;
+
+colNameKeyword
+    : BETWEEN
+    | BIGINT
+    | BIT
+    | BOOLEAN
+    | CHAR
+    | CHARACTER
+    | COALESCE
+    | DEC
+    | DECIMAL
+    | EXISTS
+    | EXTRACT
+    | FLOAT
+    | GREATEST
+    | GROUPING
+    | INOUT
+    | INT
+    | INTEGER
+    | INTERVAL
+    | LEAST
+    | NATIONAL
+    | NCHAR
+    | NONE
+    | NULLIF
+    | NUMERIC
+    | OUT
+    | OVERLAY
+    | POSITION
+    | PRECISION
+    | REAL
+    | ROW
+    | SETOF
+    | SMALLINT
+    | SUBSTRING
+    | TIME
+    | TIMESTAMP
+    | TREAT
+    | TRIM
+    | VALUES
+    | VARCHAR
+    | XMLATTRIBUTES
+    | XMLCONCAT
+    | XMLELEMENT
+    | XMLEXISTS
+    | XMLFOREST
+    | XMLNAMESPACES
+    | XMLPARSE
+    | XMLPI
+    | XMLROOT
+    | XMLSERIALIZE
+    | XMLTABLE
+    ;
+
+databaseName
+    : colId
+    ;
+
+roleSpec
+    : identifier
+    | nonReservedWord
+    | CURRENT_USER
+    | SESSION_USER
+    ;
+
+varName
+    : colId
+    | varName DOT_ colId
+    ;
+
+varList
+    : varValue
+    | varList COMMA_ varValue
+    ;
+
+varValue
+    : identifier
+    ;
+
+zoneValue
+    : STRING_
+    | identifier
+    | INTERVAL STRING_ optInterval
+    | INTERVAL LP_ NUMBER_ RP_ STRING_
+    | numericOnly
+    | DEFAULT
+    | LOCAL
+    ;
+
+numericOnly
+    : NUMBER_
+    | PLUS_ NUMBER_
+    | MINUS_ NUMBER_
+    ;
+
+isoLevel
+    : READ UNCOMMITTED
+    | READ COMMITTED
+    | REPEATABLE READ
+    | SERIALIZABLE
+    ;
+
+columnDef
+    : colId typeName createGenericOptions colQualList
+    ;
+
+colQualList
+    : colConstraint*
+    ;
+
+colConstraint
+    : CONSTRAINT name colConstraintElem
+    | colConstraintElem
+    | constraintAttr
+    | COLLATE anyName
+    ;
+
+constraintAttr
+    : DEFERRABLE
+    | NOT DEFERRABLE
+    | INITIALLY DEFERRED
+    | INITIALLY IMMEDIATE
+    ;
+
+colConstraintElem
+    : NOT NULL
+    | NULL
+    | UNIQUE optDefinition optConsTableSpace
+    | PRIMARY KEY optDefinition optConsTableSpace
+    | CHECK LP_ aExpr RP_ optNoInherit
+    | DEFAULT bExpr
+    | GENERATED generatedWhen AS IDENTITY optParenthesizedSeqOptList
+    | GENERATED generatedWhen AS LP_ aExpr RP_ STORED
+    | REFERENCES qualifiedName optColumnList keyMatch keyActions
+    ;
+
+optParenthesizedSeqOptList
+    : (LP_ seqOptList RP_)?
+    ;
+
+seqOptList
+    : seqOptElem+
+    ;
+
+seqOptElem
+    : AS simpleTypeName
+    | CACHE numericOnly
+    | CYCLE
+    | NO CYCLE
+    | INCREMENT (BY)? numericOnly
+    | MAXVALUE numericOnly
+    | MINVALUE numericOnly
+    | NO MAXVALUE
+    | NO MINVALUE
+    | OWNED BY anyName
+    | SEQUENCE NAME anyName
+    | START (WITH)? numericOnly
+    | RESTART
+    | RESTART (WITH)? numericOnly
+    ;
+
+optColumnList
+    : LP_ columnList RP_
+    ;
+
+columnElem
+    : colId
+    ;
+
+columnList
+    : columnElem
+    | columnList COMMA_ columnElem
+    ;
+
+generatedWhen
+    : ALWAYS
+    | BY DEFAULT
+    ;
+
+optNoInherit
+    : (NO INHERIT)?
+    ;
+
+optConsTableSpace
+    : (USING INDEX TABLESPACE name)?
+    ;
+
+optDefinition
+    : (WITH definition)?
+    ;

Review comment:
       Maybe ,it is good like that
   ```
   consTableSpace
       : (USING INDEX TABLESPACE name)?
       ;
   
    definition
       : (WITH definition)?
       ;
   
   xxx
       : consTableSpace?
   ```
   The same applies to others.

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/impl/PostgreSQLDDLVisitor.java
##########
@@ -101,7 +102,7 @@ public ASTNode visitCreateDefinitionClause(final CreateDefinitionClauseContext c
         }
         return result;
     }
-    
+

Review comment:
       Keep the original format,Modify the other lines as well.

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DDLStatement.g4
##########
@@ -17,34 +17,187 @@
 
 grammar DDLStatement;
 
-import Symbol, Keyword, PostgreSQLKeyword, Literals, BaseRule;
+import Symbol, Keyword, PostgreSQLKeyword, Literals, BaseRule,DMLStatement;
 
 createTable
-    : CREATE createTableSpecification_ TABLE tableNotExistClause_ tableName createDefinitionClause inheritClause_
+    : CREATE createTableSpecification_ TABLE tableNotExistClause_ tableName
+      createDefinitionClause
+      (OF anyName optTypedTableElementList)?
+      (PARTITION OF qualifiedName optTypedTableElementList partitionBoundSpec)?
+      inheritClause_ optPartitionSpec_ tableAccessMethodClause optWith onCommitOption optTableSpace
+      (AS select optWithData)?
+      (EXECUTE name executeParamClause optWithData)?
+    ;
+
+executeParamClause
+    : LP_ exprList RP_
+    ;
+
+partitionBoundSpec
+    : FOR VALUES WITH LP_ hashPartbound RP_
+    | FOR VALUES IN LP_ exprList RP_
+    | FOR VALUES FROM LP_ exprList RP_ TO LP_ exprList RP_
+    | DEFAULT
+    ;
+
+hashPartbound
+    : hashPartboundElem
+    | hashPartbound COMMA_ hashPartboundElem
+    ;
+
+hashPartboundElem
+    : nonReservedWord NUMBER_
+    ;
+
+optTypedTableElementList
+     : LP_ typedTableElementList RP_
+     ;
+
+typedTableElementList
+    : typedTableElement
+    | typedTableElementList COMMA_ typedTableElement
+    ;

Review comment:
       Maybe, it is good like that
   ```
   typedTableElementList
       : typedTableElement*
       ;
   ```
   it can reduce recursion and looks simple. it is same as others.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org