Skip to content

Commit 0e2691b

Browse files
author
zhaoge
committed
feat(sparksql): collect entity's attribute (comment,alias, colType)
1 parent ebc5ed0 commit 0e2691b

File tree

8 files changed

+227
-119
lines changed

8 files changed

+227
-119
lines changed

src/grammar/spark/SparkSqlParser.g4

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ statement
8585
| KW_ALTER (KW_TABLE tableName | KW_VIEW viewName) KW_SET KW_TBLPROPERTIES propertyList # setTableProperties
8686
| KW_ALTER (KW_TABLE tableName | KW_VIEW viewName) KW_UNSET KW_TBLPROPERTIES (ifExists)? propertyList # unsetTableProperties
8787
| KW_ALTER KW_TABLE table=tableName (KW_ALTER | KW_CHANGE) KW_COLUMN? column=columnName alterColumnAction? # alterTableAlterColumn
88-
| KW_ALTER KW_TABLE table=tableName partitionSpec? KW_CHANGE KW_COLUMN? colName=columnName colType colPosition? # hiveChangeColumn
88+
| KW_ALTER KW_TABLE table=tableName partitionSpec? KW_CHANGE KW_COLUMN? colName=columnName columnType colPosition? # hiveChangeColumn
8989
| KW_ALTER KW_TABLE table=tableName partitionSpec? KW_REPLACE KW_COLUMNS LEFT_PAREN qualifiedColTypeWithPositionSeqForReplace RIGHT_PAREN #
9090
hiveReplaceColumns
9191
| KW_ALTER KW_TABLE tableName (partitionSpec)? KW_SET KW_SERDE stringLit (
@@ -153,8 +153,8 @@ statement
153153
| (KW_DESC | KW_DESCRIBE) KW_DATABASE KW_EXTENDED? namespaceName # describeNamespace
154154
| (KW_DESC | KW_DESCRIBE) KW_TABLE? option=(KW_EXTENDED | KW_FORMATTED)? tableName partitionSpec? describeColName? # describeRelation
155155
| (KW_DESC | KW_DESCRIBE) KW_QUERY? query # describeQuery
156-
| KW_COMMENT KW_ON namespace namespaceName KW_IS comment # commentNamespace
157-
| KW_COMMENT KW_ON KW_TABLE tableName KW_IS comment # commentTable
156+
| KW_COMMENT KW_ON namespace namespaceName KW_IS commentStr # commentNamespace
157+
| KW_COMMENT KW_ON KW_TABLE tableName KW_IS commentStr # commentTable
158158
| KW_REFRESH KW_TABLE tableName # refreshTable
159159
| KW_REFRESH KW_FUNCTION functionName # refreshFunction
160160
| KW_REFRESH (stringLit | .*?) # refreshResource
@@ -269,7 +269,7 @@ locationSpec
269269
;
270270

271271
commentSpec
272-
: KW_COMMENT stringLit
272+
: KW_COMMENT comment=stringLit
273273
;
274274

275275
query
@@ -851,7 +851,7 @@ functionTable
851851
;
852852

853853
tableAlias
854-
: (KW_AS? strictIdentifier identifierList?)?
854+
: (KW_AS? alias=strictIdentifier identifierList?)?
855855
;
856856

857857
rowFormat
@@ -905,7 +905,7 @@ partitionFieldList
905905

906906
partitionField
907907
: transform
908-
| colType
908+
| columnType
909909
;
910910

911911
transform
@@ -1227,10 +1227,10 @@ variableDefaultExpression
12271227
;
12281228

12291229
colTypeList
1230-
: colType (COMMA colType)*
1230+
: columnType (COMMA columnType)*
12311231
;
12321232

1233-
colType
1233+
columnType
12341234
: colName=errorCapturingIdentifier dataType (KW_NOT KW_NULL)? commentSpec?
12351235
;
12361236

@@ -1239,7 +1239,7 @@ createOrReplaceTableColTypeList
12391239
;
12401240

12411241
createOrReplaceTableColType
1242-
: colName=columnNameCreate dataType colDefinitionOption*
1242+
: colName=columnNameCreate colType=dataType colDefinitionOption*
12431243
;
12441244

12451245
colDefinitionOption
@@ -1388,7 +1388,7 @@ stringLit
13881388
| DOUBLEQUOTED_STRING
13891389
;
13901390

1391-
comment
1391+
commentStr
13921392
: stringLit
13931393
| KW_NULL
13941394
;

src/lib/spark/SparkSqlParser.interp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ colDefinitionDescriptorWithPosition
959959
defaultExpression
960960
variableDefaultExpression
961961
colTypeList
962-
colType
962+
columnType
963963
createOrReplaceTableColTypeList
964964
createOrReplaceTableColType
965965
colDefinitionOption
@@ -986,7 +986,7 @@ backQuotedIdentifier
986986
number
987987
alterColumnAction
988988
stringLit
989-
comment
989+
commentStr
990990
version
991991
ansiNonReserved
992992
strictNonReserved

0 commit comments

Comments
 (0)