Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/grammar/hive/HiveSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ execStatement
| KW_MERGE QUERY_HINT? KW_INTO tableName (KW_AS? id_)? KW_USING joinSourcePart KW_ON expression whenClauses
| KW_PREPARE id_ KW_FROM queryStatementExpression
| KW_EXECUTE id_ KW_USING constantList
| KW_SET configPropertiesItem ((DOT | COLON) configPropertiesItem)* EQUAL .*?
| KW_SET configProperty EQUAL .*?
;

loadStatement
Expand Down Expand Up @@ -2265,6 +2265,16 @@ sql11ReservedKeywordsUsedAsFunctionName
| KW_TIMESTAMP
;

configProperty
: configPropertyPart ((DOT | COLON) configPropertyPart)*
;

configPropertyPart
: configPropertiesItem (
{this.isNextTokenAdjacent()}? MINUS {this.isNextTokenAdjacent()}? configPropertiesItem
)*
;

configPropertiesItem
: id_
| KW_SELECT
Expand Down
18 changes: 18 additions & 0 deletions src/lib/SQLParserBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,22 @@ export abstract class SQLParserBase<T = antlr.ParserRuleContext> extends antlr.P
// This allows ANTLR to report errors naturally
return false;
}

/**
* Semantic predicate to check whether the previous token and the next token
* are adjacent (no whitespace in between).
*
* Used to support hyphens inside Hive SET config property names, e.g.
* `set tez.grouping.max-size = 1`, while still rejecting invalid spacing
* like `set hive.a - b = 1`.
*/
public isNextTokenAdjacent(): boolean {
const previousToken = this.tokenStream.LT(-1);
const nextToken = this.tokenStream.LT(1);
return (
previousToken !== null &&
nextToken !== null &&
previousToken.stop + 1 === nextToken.start
);
}
}
4 changes: 3 additions & 1 deletion src/lib/hive/HiveSqlParser.interp

Large diffs are not rendered by default.

Loading
Loading