Skip to content

Commit 0ef1e95

Browse files
authored
Merge pull request #491 from liuxy0551/fix_487
fix(hive): support hyphenated config property names in SET statement (#487)
2 parents 1e853da + 7df4e56 commit 0ef1e95

8 files changed

Lines changed: 5724 additions & 5474 deletions

File tree

src/grammar/hive/HiveSqlParser.g4

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ execStatement
8686
| KW_MERGE QUERY_HINT? KW_INTO tableName (KW_AS? id_)? KW_USING joinSourcePart KW_ON expression whenClauses
8787
| KW_PREPARE id_ KW_FROM queryStatementExpression
8888
| KW_EXECUTE id_ KW_USING constantList
89-
| KW_SET configPropertiesItem ((DOT | COLON) configPropertiesItem)* EQUAL .*?
89+
| KW_SET configProperty EQUAL .*?
9090
;
9191

9292
loadStatement
@@ -2265,6 +2265,16 @@ sql11ReservedKeywordsUsedAsFunctionName
22652265
| KW_TIMESTAMP
22662266
;
22672267

2268+
configProperty
2269+
: configPropertyPart ((DOT | COLON) configPropertyPart)*
2270+
;
2271+
2272+
configPropertyPart
2273+
: configPropertiesItem (
2274+
{this.isNextTokenAdjacent()}? MINUS {this.isNextTokenAdjacent()}? configPropertiesItem
2275+
)*
2276+
;
2277+
22682278
configPropertiesItem
22692279
: id_
22702280
| KW_SELECT

src/lib/SQLParserBase.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,22 @@ export abstract class SQLParserBase<T = antlr.ParserRuleContext> extends antlr.P
5656
// This allows ANTLR to report errors naturally
5757
return false;
5858
}
59+
60+
/**
61+
* Semantic predicate to check whether the previous token and the next token
62+
* are adjacent (no whitespace in between).
63+
*
64+
* Used to support hyphens inside Hive SET config property names, e.g.
65+
* `set tez.grouping.max-size = 1`, while still rejecting invalid spacing
66+
* like `set hive.a - b = 1`.
67+
*/
68+
public isNextTokenAdjacent(): boolean {
69+
const previousToken = this.tokenStream.LT(-1);
70+
const nextToken = this.tokenStream.LT(1);
71+
return (
72+
previousToken !== null &&
73+
nextToken !== null &&
74+
previousToken.stop + 1 === nextToken.start
75+
);
76+
}
5977
}

src/lib/hive/HiveSqlParser.interp

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)