Skip to content

Commit

Permalink
clause
Browse files Browse the repository at this point in the history
  • Loading branch information
aspicer committed Oct 25, 2024
1 parent b1f75ee commit 82b4d63
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 53 deletions.
40 changes: 20 additions & 20 deletions hogql_parser/HogQLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void hogqlparserParserInitialize() {
"statement", "returnStmt", "throwStmt", "catchBlock", "tryCatchStmt",
"ifStmt", "whileStmt", "forStmt", "forInStmt", "funcStmt", "varAssignment",
"exprStmt", "emptyStmt", "block", "kvPair", "kvPairList", "select",
"selectStmtWithParens", "subsequentSelectSetStmt", "selectSetStmt",
"selectStmtWithParens", "subsequentSelectSetClause", "selectSetStmt",
"selectStmt", "withClause", "topClause", "fromClause", "arrayJoinClause",
"windowClause", "prewhereClause", "whereClause", "groupByClause",
"havingClause", "orderByClause", "projectionOrderByClause", "limitAndOffsetClause",
Expand Down Expand Up @@ -2837,48 +2837,48 @@ HogQLParser::SelectStmtWithParensContext* HogQLParser::selectStmtWithParens() {
return _localctx;
}

//----------------- SubsequentSelectSetStmtContext ------------------------------------------------------------------
//----------------- SubsequentSelectSetClauseContext ------------------------------------------------------------------

HogQLParser::SubsequentSelectSetStmtContext::SubsequentSelectSetStmtContext(ParserRuleContext *parent, size_t invokingState)
HogQLParser::SubsequentSelectSetClauseContext::SubsequentSelectSetClauseContext(ParserRuleContext *parent, size_t invokingState)
: ParserRuleContext(parent, invokingState) {
}

HogQLParser::SelectStmtWithParensContext* HogQLParser::SubsequentSelectSetStmtContext::selectStmtWithParens() {
HogQLParser::SelectStmtWithParensContext* HogQLParser::SubsequentSelectSetClauseContext::selectStmtWithParens() {
return getRuleContext<HogQLParser::SelectStmtWithParensContext>(0);
}

tree::TerminalNode* HogQLParser::SubsequentSelectSetStmtContext::EXCEPT() {
tree::TerminalNode* HogQLParser::SubsequentSelectSetClauseContext::EXCEPT() {
return getToken(HogQLParser::EXCEPT, 0);
}

tree::TerminalNode* HogQLParser::SubsequentSelectSetStmtContext::UNION() {
tree::TerminalNode* HogQLParser::SubsequentSelectSetClauseContext::UNION() {
return getToken(HogQLParser::UNION, 0);
}

tree::TerminalNode* HogQLParser::SubsequentSelectSetStmtContext::ALL() {
tree::TerminalNode* HogQLParser::SubsequentSelectSetClauseContext::ALL() {
return getToken(HogQLParser::ALL, 0);
}

tree::TerminalNode* HogQLParser::SubsequentSelectSetStmtContext::INTERSECT() {
tree::TerminalNode* HogQLParser::SubsequentSelectSetClauseContext::INTERSECT() {
return getToken(HogQLParser::INTERSECT, 0);
}


size_t HogQLParser::SubsequentSelectSetStmtContext::getRuleIndex() const {
return HogQLParser::RuleSubsequentSelectSetStmt;
size_t HogQLParser::SubsequentSelectSetClauseContext::getRuleIndex() const {
return HogQLParser::RuleSubsequentSelectSetClause;
}


std::any HogQLParser::SubsequentSelectSetStmtContext::accept(tree::ParseTreeVisitor *visitor) {
std::any HogQLParser::SubsequentSelectSetClauseContext::accept(tree::ParseTreeVisitor *visitor) {
if (auto parserVisitor = dynamic_cast<HogQLParserVisitor*>(visitor))
return parserVisitor->visitSubsequentSelectSetStmt(this);
return parserVisitor->visitSubsequentSelectSetClause(this);
else
return visitor->visitChildren(this);
}

HogQLParser::SubsequentSelectSetStmtContext* HogQLParser::subsequentSelectSetStmt() {
SubsequentSelectSetStmtContext *_localctx = _tracker.createInstance<SubsequentSelectSetStmtContext>(_ctx, getState());
enterRule(_localctx, 46, HogQLParser::RuleSubsequentSelectSetStmt);
HogQLParser::SubsequentSelectSetClauseContext* HogQLParser::subsequentSelectSetClause() {
SubsequentSelectSetClauseContext *_localctx = _tracker.createInstance<SubsequentSelectSetClauseContext>(_ctx, getState());
enterRule(_localctx, 46, HogQLParser::RuleSubsequentSelectSetClause);

#if __cplusplus > 201703L
auto onExit = finally([=, this] {
Expand Down Expand Up @@ -2938,12 +2938,12 @@ HogQLParser::SelectStmtWithParensContext* HogQLParser::SelectSetStmtContext::sel
return getRuleContext<HogQLParser::SelectStmtWithParensContext>(0);
}

std::vector<HogQLParser::SubsequentSelectSetStmtContext *> HogQLParser::SelectSetStmtContext::subsequentSelectSetStmt() {
return getRuleContexts<HogQLParser::SubsequentSelectSetStmtContext>();
std::vector<HogQLParser::SubsequentSelectSetClauseContext *> HogQLParser::SelectSetStmtContext::subsequentSelectSetClause() {
return getRuleContexts<HogQLParser::SubsequentSelectSetClauseContext>();
}

HogQLParser::SubsequentSelectSetStmtContext* HogQLParser::SelectSetStmtContext::subsequentSelectSetStmt(size_t i) {
return getRuleContext<HogQLParser::SubsequentSelectSetStmtContext>(i);
HogQLParser::SubsequentSelectSetClauseContext* HogQLParser::SelectSetStmtContext::subsequentSelectSetClause(size_t i) {
return getRuleContext<HogQLParser::SubsequentSelectSetClauseContext>(i);
}


Expand Down Expand Up @@ -2982,7 +2982,7 @@ HogQLParser::SelectSetStmtContext* HogQLParser::selectSetStmt() {

|| _la == HogQLParser::INTERSECT || _la == HogQLParser::UNION) {
setState(381);
subsequentSelectSetStmt();
subsequentSelectSetClause();
setState(386);
_errHandler->sync(this);
_la = _input->LA(1);
Expand Down
14 changes: 7 additions & 7 deletions hogql_parser/HogQLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HogQLParser : public antlr4::Parser {
RuleForStmt = 12, RuleForInStmt = 13, RuleFuncStmt = 14, RuleVarAssignment = 15,
RuleExprStmt = 16, RuleEmptyStmt = 17, RuleBlock = 18, RuleKvPair = 19,
RuleKvPairList = 20, RuleSelect = 21, RuleSelectStmtWithParens = 22,
RuleSubsequentSelectSetStmt = 23, RuleSelectSetStmt = 24, RuleSelectStmt = 25,
RuleSubsequentSelectSetClause = 23, RuleSelectSetStmt = 24, RuleSelectStmt = 25,
RuleWithClause = 26, RuleTopClause = 27, RuleFromClause = 28, RuleArrayJoinClause = 29,
RuleWindowClause = 30, RulePrewhereClause = 31, RuleWhereClause = 32,
RuleGroupByClause = 33, RuleHavingClause = 34, RuleOrderByClause = 35,
Expand Down Expand Up @@ -114,7 +114,7 @@ class HogQLParser : public antlr4::Parser {
class KvPairListContext;
class SelectContext;
class SelectStmtWithParensContext;
class SubsequentSelectSetStmtContext;
class SubsequentSelectSetClauseContext;
class SelectSetStmtContext;
class SelectStmtContext;
class WithClauseContext;
Expand Down Expand Up @@ -583,9 +583,9 @@ class HogQLParser : public antlr4::Parser {

SelectStmtWithParensContext* selectStmtWithParens();

class SubsequentSelectSetStmtContext : public antlr4::ParserRuleContext {
class SubsequentSelectSetClauseContext : public antlr4::ParserRuleContext {
public:
SubsequentSelectSetStmtContext(antlr4::ParserRuleContext *parent, size_t invokingState);
SubsequentSelectSetClauseContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
SelectStmtWithParensContext *selectStmtWithParens();
antlr4::tree::TerminalNode *EXCEPT();
Expand All @@ -598,15 +598,15 @@ class HogQLParser : public antlr4::Parser {

};

SubsequentSelectSetStmtContext* subsequentSelectSetStmt();
SubsequentSelectSetClauseContext* subsequentSelectSetClause();

class SelectSetStmtContext : public antlr4::ParserRuleContext {
public:
SelectSetStmtContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
SelectStmtWithParensContext *selectStmtWithParens();
std::vector<SubsequentSelectSetStmtContext *> subsequentSelectSetStmt();
SubsequentSelectSetStmtContext* subsequentSelectSetStmt(size_t i);
std::vector<SubsequentSelectSetClauseContext *> subsequentSelectSetClause();
SubsequentSelectSetClauseContext* subsequentSelectSetClause(size_t i);


virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
Expand Down
2 changes: 1 addition & 1 deletion hogql_parser/HogQLParser.interp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ kvPair
kvPairList
select
selectStmtWithParens
subsequentSelectSetStmt
subsequentSelectSetClause
selectSetStmt
selectStmt
withClause
Expand Down
2 changes: 1 addition & 1 deletion hogql_parser/HogQLParserBaseVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class HogQLParserBaseVisitor : public HogQLParserVisitor {
return visitChildren(ctx);
}

virtual std::any visitSubsequentSelectSetStmt(HogQLParser::SubsequentSelectSetStmtContext *ctx) override {
virtual std::any visitSubsequentSelectSetClause(HogQLParser::SubsequentSelectSetClauseContext *ctx) override {
return visitChildren(ctx);
}

Expand Down
2 changes: 1 addition & 1 deletion hogql_parser/HogQLParserVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class HogQLParserVisitor : public antlr4::tree::AbstractParseTreeVisitor {

virtual std::any visitSelectStmtWithParens(HogQLParser::SelectStmtWithParensContext *context) = 0;

virtual std::any visitSubsequentSelectSetStmt(HogQLParser::SubsequentSelectSetStmtContext *context) = 0;
virtual std::any visitSubsequentSelectSetClause(HogQLParser::SubsequentSelectSetClauseContext *context) = 0;

virtual std::any visitSelectSetStmt(HogQLParser::SelectSetStmtContext *context) = 0;

Expand Down
2 changes: 1 addition & 1 deletion hogql_parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ class HogQLParseTreeConverter : public HogQLParserBaseVisitor {
}

try {
for (auto subsequent : ctx->subsequentSelectSetStmt()) {
for (auto subsequent : ctx->subsequentSelectSetClause()) {
char* set_operator;
if (subsequent->UNION() && subsequent->ALL()) {
set_operator = "UNION ALL";
Expand Down
4 changes: 2 additions & 2 deletions posthog/hogql/grammar/HogQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ select: (selectSetStmt | selectStmt | hogqlxTagElement) EOF;

selectStmtWithParens: selectStmt | LPAREN selectSetStmt RPAREN | placeholder;

subsequentSelectSetStmt: (EXCEPT | UNION ALL | INTERSECT) selectStmtWithParens;
selectSetStmt: selectStmtWithParens (subsequentSelectSetStmt)*;
subsequentSelectSetClause: (EXCEPT | UNION ALL | INTERSECT) selectStmtWithParens;
selectSetStmt: selectStmtWithParens (subsequentSelectSetClause)*;

selectStmt:
with=withClause?
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/grammar/HogQLParser.interp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ kvPair
kvPairList
select
selectStmtWithParens
subsequentSelectSetStmt
subsequentSelectSetClause
selectSetStmt
selectStmt
withClause
Expand Down
26 changes: 13 additions & 13 deletions posthog/hogql/grammar/HogQLParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ class HogQLParser ( Parser ):
RULE_kvPairList = 20
RULE_select = 21
RULE_selectStmtWithParens = 22
RULE_subsequentSelectSetStmt = 23
RULE_subsequentSelectSetClause = 23
RULE_selectSetStmt = 24
RULE_selectStmt = 25
RULE_withClause = 26
Expand Down Expand Up @@ -713,7 +713,7 @@ class HogQLParser ( Parser ):
"tryCatchStmt", "ifStmt", "whileStmt", "forStmt", "forInStmt",
"funcStmt", "varAssignment", "exprStmt", "emptyStmt",
"block", "kvPair", "kvPairList", "select", "selectStmtWithParens",
"subsequentSelectSetStmt", "selectSetStmt", "selectStmt",
"subsequentSelectSetClause", "selectSetStmt", "selectStmt",
"withClause", "topClause", "fromClause", "arrayJoinClause",
"windowClause", "prewhereClause", "whereClause", "groupByClause",
"havingClause", "orderByClause", "projectionOrderByClause",
Expand Down Expand Up @@ -2599,7 +2599,7 @@ def selectStmtWithParens(self):
return localctx


class SubsequentSelectSetStmtContext(ParserRuleContext):
class SubsequentSelectSetClauseContext(ParserRuleContext):
__slots__ = 'parser'

def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
Expand All @@ -2623,21 +2623,21 @@ def INTERSECT(self):
return self.getToken(HogQLParser.INTERSECT, 0)

def getRuleIndex(self):
return HogQLParser.RULE_subsequentSelectSetStmt
return HogQLParser.RULE_subsequentSelectSetClause

def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitSubsequentSelectSetStmt" ):
return visitor.visitSubsequentSelectSetStmt(self)
if hasattr( visitor, "visitSubsequentSelectSetClause" ):
return visitor.visitSubsequentSelectSetClause(self)
else:
return visitor.visitChildren(self)




def subsequentSelectSetStmt(self):
def subsequentSelectSetClause(self):

localctx = HogQLParser.SubsequentSelectSetStmtContext(self, self._ctx, self.state)
self.enterRule(localctx, 46, self.RULE_subsequentSelectSetStmt)
localctx = HogQLParser.SubsequentSelectSetClauseContext(self, self._ctx, self.state)
self.enterRule(localctx, 46, self.RULE_subsequentSelectSetClause)
try:
self.enterOuterAlt(localctx, 1)
self.state = 376
Expand Down Expand Up @@ -2682,11 +2682,11 @@ def selectStmtWithParens(self):
return self.getTypedRuleContext(HogQLParser.SelectStmtWithParensContext,0)


def subsequentSelectSetStmt(self, i:int=None):
def subsequentSelectSetClause(self, i:int=None):
if i is None:
return self.getTypedRuleContexts(HogQLParser.SubsequentSelectSetStmtContext)
return self.getTypedRuleContexts(HogQLParser.SubsequentSelectSetClauseContext)
else:
return self.getTypedRuleContext(HogQLParser.SubsequentSelectSetStmtContext,i)
return self.getTypedRuleContext(HogQLParser.SubsequentSelectSetClauseContext,i)


def getRuleIndex(self):
Expand Down Expand Up @@ -2715,7 +2715,7 @@ def selectSetStmt(self):
_la = self._input.LA(1)
while _la==27 or _la==47 or _la==98:
self.state = 381
self.subsequentSelectSetStmt()
self.subsequentSelectSetClause()
self.state = 386
self._errHandler.sync(self)
_la = self._input.LA(1)
Expand Down
4 changes: 2 additions & 2 deletions posthog/hogql/grammar/HogQLParserVisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def visitSelectStmtWithParens(self, ctx:HogQLParser.SelectStmtWithParensContext)
return self.visitChildren(ctx)


# Visit a parse tree produced by HogQLParser#subsequentSelectSetStmt.
def visitSubsequentSelectSetStmt(self, ctx:HogQLParser.SubsequentSelectSetStmtContext):
# Visit a parse tree produced by HogQLParser#subsequentSelectSetClause.
def visitSubsequentSelectSetClause(self, ctx:HogQLParser.SubsequentSelectSetClauseContext):
return self.visitChildren(ctx)


Expand Down
5 changes: 1 addition & 4 deletions posthog/hogql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,12 @@ def visitBlock(self, ctx: HogQLParser.BlockContext):
def visitSelect(self, ctx: HogQLParser.SelectContext):
return self.visit(ctx.selectSetStmt() or ctx.selectStmt() or ctx.hogqlxTagElement())

def visitSubsequentSelectSetStmt(self, ctx: HogQLParser.SubsequentSelectSetStmtContext):
pass

def visitSelectSetStmt(self, ctx: HogQLParser.SelectSetStmtContext):
select_queries: list[SelectSetNode] = []

initial_query = self.visit(ctx.selectStmtWithParens())

for subsequent in ctx.subsequentSelectSetStmt():
for subsequent in ctx.subsequentSelectSetClause():
if subsequent.UNION() and subsequent.ALL():
union_type = "UNION ALL"
elif subsequent.INTERSECT():
Expand Down

0 comments on commit 82b4d63

Please sign in to comment.