Feat/hive ddl (#150)

* test: test cases about Alter Either Table or Partition

* feat: support alter protection and correct alter compact

* feat: improve keyword rules

* feat: recompile hive grammar
This commit is contained in:
Hayden 2023-08-30 17:58:20 +08:00 committed by GitHub
parent f1b9b80056
commit af1d71c576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 11423 additions and 11265 deletions

View File

@ -42,7 +42,7 @@ KW_AST : 'AST';
KW_AT : 'AT';
KW_AUTHORIZATION : 'AUTHORIZATION';
KW_AUTOCOMMIT : 'AUTOCOMMIT';
KW_BATCH : 'KW_BATCH';
KW_BATCH : 'BATCH';
KW_BEFORE : 'BEFORE';
KW_BETWEEN : 'BETWEEN';
KW_BIGINT : 'BIGINT';
@ -93,7 +93,7 @@ KW_DATACONNECTORS : 'CONNECTORS';
KW_DATE : 'DATE';
KW_DATETIME : 'DATETIME';
KW_DAY : 'DAY' 'S'?;
KW_DAYOFWEEK : 'KW_DAYOFWEEK';
KW_DAYOFWEEK : 'DAYOFWEEK';
KW_DBPROPERTIES : 'DBPROPERTIES';
KW_DCPROPERTIES : 'DCPROPERTIES';
KW_DDL : 'DDL';
@ -116,7 +116,6 @@ KW_DISTRIBUTE : 'DISTRIBUTE';
KW_DISTRIBUTED : 'DISTRIBUTED';
KW_DO : 'DO';
KW_DOUBLE : 'DOUBLE';
KW_DOW : 'DAYOFWEEK';
KW_DROP : 'DROP';
KW_DUMP : 'DUMP';
KW_ELEM_TYPE : '$ELEM$';
@ -161,7 +160,7 @@ KW_GRANT : 'GRANT';
KW_GROUP : 'GROUP';
KW_GROUPING : 'GROUPING';
KW_HAVING : 'HAVING';
KW_HOLD_DDLTIME : 'KW_HOLD_DDLTIME';
KW_HOLD_DDLTIME : 'HOLD_DDLTIME';
KW_HOUR : 'HOUR' 'S'?;
KW_IDXPROPERTIES : 'IDXPROPERTIES';
KW_IF : 'IF';
@ -227,11 +226,11 @@ KW_NORELY : 'NORELY';
KW_NOSCAN : 'NOSCAN';
KW_NOT : 'NOT' | '!';
KW_NOVALIDATE : 'NOVALIDATE';
KW_NO_DROP : 'KW_NO_DROP';
KW_NO_DROP : 'NO_DROP';
KW_NULL : 'NULL';
KW_NULLS : 'NULLS';
KW_OF : 'OF';
KW_OFFLINE : 'KW_OFFLINE';
KW_OFFLINE : 'OFFLINE';
KW_OFFSET : 'OFFSET';
KW_ON : 'ON';
KW_ONLY : 'ONLY';
@ -263,7 +262,7 @@ KW_PRESERVE : 'PRESERVE';
KW_PRIMARY : 'PRIMARY';
KW_PRINCIPALS : 'PRINCIPALS';
KW_PROCEDURE : 'PROCEDURE';
KW_PROTECTION : 'KW_PROTECTION';
KW_PROTECTION : 'PROTECTION';
KW_PURGE : 'PURGE';
KW_QUALIFY : 'QUALIFY';
KW_QUARTER : 'QUARTER';
@ -271,7 +270,7 @@ KW_QUERY : 'QUERY';
KW_QUERY_PARALLELISM : 'QUERY_PARALLELISM';
KW_RANGE : 'RANGE';
KW_READ : 'READ';
KW_READONLY : 'KW_READONLY';
KW_READONLY : 'READONLY';
KW_READS : 'READS';
KW_REAL : 'REAL';
KW_REBUILD : 'REBUILD';
@ -347,7 +346,7 @@ KW_THEN : 'THEN';
KW_TIME : 'TIME';
KW_TIMESTAMP : 'TIMESTAMP';
KW_TIMESTAMPLOCALTZ : 'TIMESTAMPLOCALTZ';
KW_TIMESTAMPTZ : 'KW_TIMESTAMPTZ';
KW_TIMESTAMPTZ : 'TIMESTAMPTZ';
KW_TINYINT : 'TINYINT';
KW_TO : 'TO';
KW_TOUCH : 'TOUCH';
@ -503,6 +502,7 @@ QuotedIdentifier
fragment
Letter
: 'A'..'Z'
| 'a'..'z'
;
fragment

View File

@ -1369,6 +1369,7 @@ alterTblPartitionStatementSuffix
| alterStatementSuffixRenameCol
| alterStatementSuffixAddCol
| alterStatementSuffixUpdateColumns
| alterStatementSuffixProtections
;
alterStatementPartitionKeyType
@ -1435,6 +1436,11 @@ alterStatementSuffixUpdateColumns
: KW_UPDATE KW_COLUMNS restrictOrCascade?
;
alterStatementSuffixProtections
: enableSpecification KW_NO_DROP KW_CASCADE?
| enableSpecification KW_OFFLINE
;
alterStatementSuffixDropConstraint
: KW_DROP KW_CONSTRAINT cName=id_
;
@ -1569,7 +1575,7 @@ compactPool
;
alterStatementSuffixCompact
: KW_COMPACT compactType=StringLiteral tableImplBuckets? blocking? compactPool? (KW_WITH KW_OVERWRITE KW_TBLPROPERTIES tableProperties)?
: KW_COMPACT compactType=StringLiteral blocking? tableImplBuckets? orderByClause? compactPool? (KW_WITH KW_OVERWRITE KW_TBLPROPERTIES tableProperties)?
;
alterStatementSuffixSetOwner
@ -2184,7 +2190,6 @@ timeQualifiers
| KW_MONTH
| KW_WEEK
| KW_DAY
| KW_DOW
| KW_HOUR
| KW_MINUTE
| KW_SECOND
@ -2641,7 +2646,6 @@ nonReserved
| KW_DISTRIBUTE
| KW_DISTRIBUTED
| KW_DO
| KW_DOW
| KW_DUMP
| KW_ELEM_TYPE
| KW_ENABLE

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -256,6 +256,7 @@ import { AlterStatementSuffixRenameContext } from "./HiveSqlParser";
import { AlterStatementSuffixAddColContext } from "./HiveSqlParser";
import { AlterStatementSuffixAddConstraintContext } from "./HiveSqlParser";
import { AlterStatementSuffixUpdateColumnsContext } from "./HiveSqlParser";
import { AlterStatementSuffixProtectionsContext } from "./HiveSqlParser";
import { AlterStatementSuffixDropConstraintContext } from "./HiveSqlParser";
import { AlterStatementSuffixRenameColContext } from "./HiveSqlParser";
import { AlterStatementSuffixUpdateStatsColContext } from "./HiveSqlParser";
@ -3295,6 +3296,17 @@ export interface HiveSqlParserListener extends ParseTreeListener {
*/
exitAlterStatementSuffixUpdateColumns?: (ctx: AlterStatementSuffixUpdateColumnsContext) => void;
/**
* Enter a parse tree produced by `HiveSqlParser.alterStatementSuffixProtections`.
* @param ctx the parse tree
*/
enterAlterStatementSuffixProtections?: (ctx: AlterStatementSuffixProtectionsContext) => void;
/**
* Exit a parse tree produced by `HiveSqlParser.alterStatementSuffixProtections`.
* @param ctx the parse tree
*/
exitAlterStatementSuffixProtections?: (ctx: AlterStatementSuffixProtectionsContext) => void;
/**
* Enter a parse tree produced by `HiveSqlParser.alterStatementSuffixDropConstraint`.
* @param ctx the parse tree

View File

@ -256,6 +256,7 @@ import { AlterStatementSuffixRenameContext } from "./HiveSqlParser";
import { AlterStatementSuffixAddColContext } from "./HiveSqlParser";
import { AlterStatementSuffixAddConstraintContext } from "./HiveSqlParser";
import { AlterStatementSuffixUpdateColumnsContext } from "./HiveSqlParser";
import { AlterStatementSuffixProtectionsContext } from "./HiveSqlParser";
import { AlterStatementSuffixDropConstraintContext } from "./HiveSqlParser";
import { AlterStatementSuffixRenameColContext } from "./HiveSqlParser";
import { AlterStatementSuffixUpdateStatsColContext } from "./HiveSqlParser";
@ -2286,6 +2287,13 @@ export interface HiveSqlParserVisitor<Result> extends ParseTreeVisitor<Result> {
*/
visitAlterStatementSuffixUpdateColumns?: (ctx: AlterStatementSuffixUpdateColumnsContext) => Result;
/**
* Visit a parse tree produced by `HiveSqlParser.alterStatementSuffixProtections`.
* @param ctx the parse tree
* @return the visitor result
*/
visitAlterStatementSuffixProtections?: (ctx: AlterStatementSuffixProtectionsContext) => Result;
/**
* Visit a parse tree produced by `HiveSqlParser.alterStatementSuffixDropConstraint`.
* @param ctx the parse tree

View File

@ -105,13 +105,64 @@ ALTER TABLE dr_tbl1 DROP PARTITION (`pt1`=1);
ALTER TABLE dr_tbl2 DROP IF EXISTS PARTITION (`pt2`=2) PURGE;
-- ALTER TABLE dr_tbl2 DROP IF EXISTS PARTITION (`pt2`=2) IGNORE PROTECTION PURGE;
-- Archive Partition
ALTER TABLE arch_pt_tbl1 ARCHIVE PARTITION (`pt1`=1);
ALTER TABLE arch_pt_tbl2 UNARCHIVE PARTITION (`pt2`=2) ;
-- Alter Table/Partition File Format
ALTER TABLE tbl1 SET FILEFORMAT orc;
ALTER TABLE tbl2 PARTITION (`pt1`=1) SET FILEFORMAT orc;
-- Alter Table/Partition Location
ALTER TABLE tbl3 SET LOCATION "new location";
ALTER TABLE tbl4 PARTITION (`pt1`=1) SET LOCATION "new location";
-- Alter Table/Partition Touch
ALTER TABLE tbl5 TOUCH;
ALTER TABLE tbl6 TOUCH PARTITION (`pt1`=1);
-- Alter Table/Partition Protections
ALTER TABLE tbl7 ENABLE NO_DROP CASCADE;
ALTER TABLE tbl8 PARTITION (`pt1`=1) DISABLE NO_DROP;
ALTER TABLE tbl9 DISABLE OFFLINE;
ALTER TABLE db1.tbl PARTITION (`pt1`=1) ENABLE OFFLINE;
-- Alter Table/Partition Compact
ALTER TABLE tbl_com COMPACT 'compaction_type';
ALTER TABLE tbl_com2 PARTITION (pt1 = 'partition_value')
COMPACT 'compaction_type' AND WAIT
CLUSTERED INTO 1 BUCKETS
ORDER BY col1
POOL 'pool1'
WITH OVERWRITE TBLPROPERTIES ("propKey1"="propVal");
-- Alter Table/Partition Concatenate
ALTER TABLE tbl22 CONCATENATE;
ALTER TABLE tbl23 PARTITION (pt1 = 'anyValue') CONCATENATE;
-- Alter Table/Partition Update columns
ALTER TABLE tbl24 UPDATE COLUMNS;
ALTER TABLE tbl24 PARTITION (pt1 = 'partition_value') UPDATE COLUMNS;
-- Change Column Name/Type/Position/Comment
ALTER TABLE test_change CHANGE COLUMN a a1 INT;
ALTER TABLE test_change PARTITION (pt1 = 'partition_value') CHANGE c c1 INT FIRST;
ALTER TABLE test_change CHANGE a1 a1 INT COMMENT 'this is column a1' RESTRICT;
ALTER TABLE test_change CHANGE a1 a2 STRING AFTER b CASCADE;
-- Add/Replace Columns
ALTER TABLE rp_col_tbl1 ADD COLUMNS (`col1` INT);
@ -121,3 +172,6 @@ ALTER TABLE rp_col_tbl2
PARTITION (`pt1`=1)
ADD COLUMNS (`col3` INT COMMENT 'a new col')
CASCADE;
-- Partial Partition Specification
ALTER TABLE foo PARTITION (ds='2008-04-08', hr=11) CHANGE COLUMN dec_column_name dec_column_name DECIMAL(38,18);