0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 00:46:45 +01:00
posthog/hogql_parser/HogQLParserVisitor.h

237 lines
10 KiB
C
Raw Normal View History

perf: Parse HogQL with C++ for a huge speedup (#17659) * Add partial C++ parser of HogQL * Support all the rules and add proper error handling * Use `AlignAfterOpenBracket: BlockIndent` * Reuse all the parser tests for the C++ backend * Fix relationship between headers and implementations * Add more error handling and fix minor issues * Build both Python and C++ parsers in the package.json script * Update ARRAY JOIN error assertion * Improve timeit * Move the C extension to the top level * Refactor `vector_to_list_string` * Build the parser on Linux * Build wheels for the parser * Simplify Linux build and fix macOS * Fix Homebrew paths on x86 and don't fail fast in CI * Set MACOSX_DEPLOYMENT_TARGET for C++20 * Set up QEMU for Linux ARM builds * Publish the wheels on PyPI * Avoiding Linux ARM emulation in CI for now * Build sdist too * Revert Dockerfile changes * Fix PyPI publish * Add README and optimize sdist build * Use setup.py directly instead of build * Use PyPI hogql-parser instead of local * Also revert production-unit.Dockerfile * Fix sdist upload and add Linux ARM back * No Linux ARM build in the end * Fix artifact uploading * Do try building Linux ARM We need this for prod. * Use `npm` in `grammar:build` `pnpm` is not available in that job. * Fix formatting of hogql_parser * Build everything on macOS * Revert "Build everything on macOS" Not so fast actually. * Use hogql-parser=0.1.1 * Fix dylib in macOS wheel * Bump hogql-parser version * Fix missing module error * Delete timeit.py * Make error handling robust * Format the C++ * Use `hogql-parser==0.1.1` * Fix reserved keyword error assertions * Use HEAD hogql_paresr in CI * Fix `apt` usage * Add some sudo in CI * Ensure package will be releasable before build * Bump version to 0.1.3 * Cover C++ `unquote_string` with tests * Use BuildJet ARM runners for ARM builds * Add some instructions * Add HogQL version check to backend CI * Update requirements.txt * Use `setuptools` instead of the deprecated `distutils` * Fix working dir in backend CI * Align ANTLR versions * Add test for "mismatched input" This is thrown differently than other HogQLSyntaxExceptions in C++, so might help reveal what's going on with tests failing only on Linux CI and not macOS dev * Add types and bump version * Comment instead of failing version check * Automate hogql-release version bump * Fix checkout token * Don't build hogql-parser if there were no changes * Update query snapshots * Update query snapshots * Update query snapshots * Update query snapshots * Improve documentation * Use new hogql-parser version * Fix error start and end initialization * Note `antlr4-cpp-runtime` Co-authored-by: Marius Andra <marius.andra@gmail.com> * Also remove NUL chars in C++ * Check ANTLR4 runtime archive checksum for security * Note more decrefs to add * Add vector size checks * Use new hogql-parser version * Don't support the `start` arg in C++ `parse_expr` * Use new hogql-parser version --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Marius Andra <marius.andra@gmail.com>
2023-10-13 15:58:08 +02:00
// Generated from HogQLParser.g4 by ANTLR 4.13.1
perf: Parse HogQL with C++ for a huge speedup (#17659) * Add partial C++ parser of HogQL * Support all the rules and add proper error handling * Use `AlignAfterOpenBracket: BlockIndent` * Reuse all the parser tests for the C++ backend * Fix relationship between headers and implementations * Add more error handling and fix minor issues * Build both Python and C++ parsers in the package.json script * Update ARRAY JOIN error assertion * Improve timeit * Move the C extension to the top level * Refactor `vector_to_list_string` * Build the parser on Linux * Build wheels for the parser * Simplify Linux build and fix macOS * Fix Homebrew paths on x86 and don't fail fast in CI * Set MACOSX_DEPLOYMENT_TARGET for C++20 * Set up QEMU for Linux ARM builds * Publish the wheels on PyPI * Avoiding Linux ARM emulation in CI for now * Build sdist too * Revert Dockerfile changes * Fix PyPI publish * Add README and optimize sdist build * Use setup.py directly instead of build * Use PyPI hogql-parser instead of local * Also revert production-unit.Dockerfile * Fix sdist upload and add Linux ARM back * No Linux ARM build in the end * Fix artifact uploading * Do try building Linux ARM We need this for prod. * Use `npm` in `grammar:build` `pnpm` is not available in that job. * Fix formatting of hogql_parser * Build everything on macOS * Revert "Build everything on macOS" Not so fast actually. * Use hogql-parser=0.1.1 * Fix dylib in macOS wheel * Bump hogql-parser version * Fix missing module error * Delete timeit.py * Make error handling robust * Format the C++ * Use `hogql-parser==0.1.1` * Fix reserved keyword error assertions * Use HEAD hogql_paresr in CI * Fix `apt` usage * Add some sudo in CI * Ensure package will be releasable before build * Bump version to 0.1.3 * Cover C++ `unquote_string` with tests * Use BuildJet ARM runners for ARM builds * Add some instructions * Add HogQL version check to backend CI * Update requirements.txt * Use `setuptools` instead of the deprecated `distutils` * Fix working dir in backend CI * Align ANTLR versions * Add test for "mismatched input" This is thrown differently than other HogQLSyntaxExceptions in C++, so might help reveal what's going on with tests failing only on Linux CI and not macOS dev * Add types and bump version * Comment instead of failing version check * Automate hogql-release version bump * Fix checkout token * Don't build hogql-parser if there were no changes * Update query snapshots * Update query snapshots * Update query snapshots * Update query snapshots * Improve documentation * Use new hogql-parser version * Fix error start and end initialization * Note `antlr4-cpp-runtime` Co-authored-by: Marius Andra <marius.andra@gmail.com> * Also remove NUL chars in C++ * Check ANTLR4 runtime archive checksum for security * Note more decrefs to add * Add vector size checks * Use new hogql-parser version * Don't support the `start` arg in C++ `parse_expr` * Use new hogql-parser version --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Marius Andra <marius.andra@gmail.com>
2023-10-13 15:58:08 +02:00
#pragma once
#include "antlr4-runtime.h"
#include "HogQLParser.h"
/**
* This class defines an abstract visitor for a parse tree
* produced by HogQLParser.
*/
class HogQLParserVisitor : public antlr4::tree::AbstractParseTreeVisitor {
public:
/**
* Visit parse trees produced by HogQLParser.
*/
virtual std::any visitSelect(HogQLParser::SelectContext *context) = 0;
virtual std::any visitSelectUnionStmt(HogQLParser::SelectUnionStmtContext *context) = 0;
virtual std::any visitSelectStmtWithParens(HogQLParser::SelectStmtWithParensContext *context) = 0;
virtual std::any visitSelectStmt(HogQLParser::SelectStmtContext *context) = 0;
virtual std::any visitWithClause(HogQLParser::WithClauseContext *context) = 0;
virtual std::any visitTopClause(HogQLParser::TopClauseContext *context) = 0;
virtual std::any visitFromClause(HogQLParser::FromClauseContext *context) = 0;
virtual std::any visitArrayJoinClause(HogQLParser::ArrayJoinClauseContext *context) = 0;
virtual std::any visitWindowClause(HogQLParser::WindowClauseContext *context) = 0;
virtual std::any visitPrewhereClause(HogQLParser::PrewhereClauseContext *context) = 0;
virtual std::any visitWhereClause(HogQLParser::WhereClauseContext *context) = 0;
virtual std::any visitGroupByClause(HogQLParser::GroupByClauseContext *context) = 0;
virtual std::any visitHavingClause(HogQLParser::HavingClauseContext *context) = 0;
virtual std::any visitOrderByClause(HogQLParser::OrderByClauseContext *context) = 0;
virtual std::any visitProjectionOrderByClause(HogQLParser::ProjectionOrderByClauseContext *context) = 0;
virtual std::any visitLimitAndOffsetClause(HogQLParser::LimitAndOffsetClauseContext *context) = 0;
virtual std::any visitOffsetOnlyClause(HogQLParser::OffsetOnlyClauseContext *context) = 0;
virtual std::any visitSettingsClause(HogQLParser::SettingsClauseContext *context) = 0;
virtual std::any visitJoinExprOp(HogQLParser::JoinExprOpContext *context) = 0;
virtual std::any visitJoinExprTable(HogQLParser::JoinExprTableContext *context) = 0;
virtual std::any visitJoinExprParens(HogQLParser::JoinExprParensContext *context) = 0;
virtual std::any visitJoinExprCrossOp(HogQLParser::JoinExprCrossOpContext *context) = 0;
virtual std::any visitJoinOpInner(HogQLParser::JoinOpInnerContext *context) = 0;
virtual std::any visitJoinOpLeftRight(HogQLParser::JoinOpLeftRightContext *context) = 0;
virtual std::any visitJoinOpFull(HogQLParser::JoinOpFullContext *context) = 0;
virtual std::any visitJoinOpCross(HogQLParser::JoinOpCrossContext *context) = 0;
virtual std::any visitJoinConstraintClause(HogQLParser::JoinConstraintClauseContext *context) = 0;
virtual std::any visitSampleClause(HogQLParser::SampleClauseContext *context) = 0;
virtual std::any visitOrderExprList(HogQLParser::OrderExprListContext *context) = 0;
virtual std::any visitOrderExpr(HogQLParser::OrderExprContext *context) = 0;
virtual std::any visitRatioExpr(HogQLParser::RatioExprContext *context) = 0;
virtual std::any visitSettingExprList(HogQLParser::SettingExprListContext *context) = 0;
virtual std::any visitSettingExpr(HogQLParser::SettingExprContext *context) = 0;
virtual std::any visitWindowExpr(HogQLParser::WindowExprContext *context) = 0;
virtual std::any visitWinPartitionByClause(HogQLParser::WinPartitionByClauseContext *context) = 0;
virtual std::any visitWinOrderByClause(HogQLParser::WinOrderByClauseContext *context) = 0;
virtual std::any visitWinFrameClause(HogQLParser::WinFrameClauseContext *context) = 0;
virtual std::any visitFrameStart(HogQLParser::FrameStartContext *context) = 0;
virtual std::any visitFrameBetween(HogQLParser::FrameBetweenContext *context) = 0;
virtual std::any visitWinFrameBound(HogQLParser::WinFrameBoundContext *context) = 0;
virtual std::any visitExpr(HogQLParser::ExprContext *context) = 0;
virtual std::any visitColumnTypeExprSimple(HogQLParser::ColumnTypeExprSimpleContext *context) = 0;
virtual std::any visitColumnTypeExprNested(HogQLParser::ColumnTypeExprNestedContext *context) = 0;
virtual std::any visitColumnTypeExprEnum(HogQLParser::ColumnTypeExprEnumContext *context) = 0;
virtual std::any visitColumnTypeExprComplex(HogQLParser::ColumnTypeExprComplexContext *context) = 0;
virtual std::any visitColumnTypeExprParam(HogQLParser::ColumnTypeExprParamContext *context) = 0;
virtual std::any visitColumnExprList(HogQLParser::ColumnExprListContext *context) = 0;
virtual std::any visitColumnExprTernaryOp(HogQLParser::ColumnExprTernaryOpContext *context) = 0;
virtual std::any visitColumnExprAlias(HogQLParser::ColumnExprAliasContext *context) = 0;
virtual std::any visitColumnExprExtract(HogQLParser::ColumnExprExtractContext *context) = 0;
virtual std::any visitColumnExprNegate(HogQLParser::ColumnExprNegateContext *context) = 0;
virtual std::any visitColumnExprSubquery(HogQLParser::ColumnExprSubqueryContext *context) = 0;
virtual std::any visitColumnExprLiteral(HogQLParser::ColumnExprLiteralContext *context) = 0;
virtual std::any visitColumnExprArray(HogQLParser::ColumnExprArrayContext *context) = 0;
virtual std::any visitColumnExprSubstring(HogQLParser::ColumnExprSubstringContext *context) = 0;
virtual std::any visitColumnExprCast(HogQLParser::ColumnExprCastContext *context) = 0;
virtual std::any visitColumnExprOr(HogQLParser::ColumnExprOrContext *context) = 0;
virtual std::any visitColumnExprPrecedence1(HogQLParser::ColumnExprPrecedence1Context *context) = 0;
virtual std::any visitColumnExprPrecedence2(HogQLParser::ColumnExprPrecedence2Context *context) = 0;
virtual std::any visitColumnExprPrecedence3(HogQLParser::ColumnExprPrecedence3Context *context) = 0;
virtual std::any visitColumnExprInterval(HogQLParser::ColumnExprIntervalContext *context) = 0;
virtual std::any visitColumnExprIsNull(HogQLParser::ColumnExprIsNullContext *context) = 0;
virtual std::any visitColumnExprWinFunctionTarget(HogQLParser::ColumnExprWinFunctionTargetContext *context) = 0;
virtual std::any visitColumnExprTrim(HogQLParser::ColumnExprTrimContext *context) = 0;
virtual std::any visitColumnExprTuple(HogQLParser::ColumnExprTupleContext *context) = 0;
virtual std::any visitColumnExprArrayAccess(HogQLParser::ColumnExprArrayAccessContext *context) = 0;
virtual std::any visitColumnExprBetween(HogQLParser::ColumnExprBetweenContext *context) = 0;
virtual std::any visitColumnExprPropertyAccess(HogQLParser::ColumnExprPropertyAccessContext *context) = 0;
virtual std::any visitColumnExprParens(HogQLParser::ColumnExprParensContext *context) = 0;
virtual std::any visitColumnExprTimestamp(HogQLParser::ColumnExprTimestampContext *context) = 0;
virtual std::any visitColumnExprNullish(HogQLParser::ColumnExprNullishContext *context) = 0;
virtual std::any visitColumnExprAnd(HogQLParser::ColumnExprAndContext *context) = 0;
virtual std::any visitColumnExprTupleAccess(HogQLParser::ColumnExprTupleAccessContext *context) = 0;
virtual std::any visitColumnExprCase(HogQLParser::ColumnExprCaseContext *context) = 0;
virtual std::any visitColumnExprDate(HogQLParser::ColumnExprDateContext *context) = 0;
virtual std::any visitColumnExprNot(HogQLParser::ColumnExprNotContext *context) = 0;
virtual std::any visitColumnExprWinFunction(HogQLParser::ColumnExprWinFunctionContext *context) = 0;
virtual std::any visitColumnExprIdentifier(HogQLParser::ColumnExprIdentifierContext *context) = 0;
virtual std::any visitColumnExprFunction(HogQLParser::ColumnExprFunctionContext *context) = 0;
virtual std::any visitColumnExprAsterisk(HogQLParser::ColumnExprAsteriskContext *context) = 0;
virtual std::any visitColumnArgList(HogQLParser::ColumnArgListContext *context) = 0;
virtual std::any visitColumnArgExpr(HogQLParser::ColumnArgExprContext *context) = 0;
virtual std::any visitColumnLambdaExpr(HogQLParser::ColumnLambdaExprContext *context) = 0;
virtual std::any visitWithExprList(HogQLParser::WithExprListContext *context) = 0;
virtual std::any visitWithExprSubquery(HogQLParser::WithExprSubqueryContext *context) = 0;
virtual std::any visitWithExprColumn(HogQLParser::WithExprColumnContext *context) = 0;
virtual std::any visitColumnIdentifier(HogQLParser::ColumnIdentifierContext *context) = 0;
virtual std::any visitNestedIdentifier(HogQLParser::NestedIdentifierContext *context) = 0;
virtual std::any visitTableExprIdentifier(HogQLParser::TableExprIdentifierContext *context) = 0;
virtual std::any visitTableExprPlaceholder(HogQLParser::TableExprPlaceholderContext *context) = 0;
virtual std::any visitTableExprSubquery(HogQLParser::TableExprSubqueryContext *context) = 0;
virtual std::any visitTableExprAlias(HogQLParser::TableExprAliasContext *context) = 0;
virtual std::any visitTableExprFunction(HogQLParser::TableExprFunctionContext *context) = 0;
virtual std::any visitTableFunctionExpr(HogQLParser::TableFunctionExprContext *context) = 0;
virtual std::any visitTableIdentifier(HogQLParser::TableIdentifierContext *context) = 0;
virtual std::any visitTableArgList(HogQLParser::TableArgListContext *context) = 0;
virtual std::any visitDatabaseIdentifier(HogQLParser::DatabaseIdentifierContext *context) = 0;
virtual std::any visitFloatingLiteral(HogQLParser::FloatingLiteralContext *context) = 0;
virtual std::any visitNumberLiteral(HogQLParser::NumberLiteralContext *context) = 0;
virtual std::any visitLiteral(HogQLParser::LiteralContext *context) = 0;
virtual std::any visitInterval(HogQLParser::IntervalContext *context) = 0;
virtual std::any visitKeyword(HogQLParser::KeywordContext *context) = 0;
virtual std::any visitKeywordForAlias(HogQLParser::KeywordForAliasContext *context) = 0;
virtual std::any visitAlias(HogQLParser::AliasContext *context) = 0;
virtual std::any visitIdentifier(HogQLParser::IdentifierContext *context) = 0;
virtual std::any visitEnumValue(HogQLParser::EnumValueContext *context) = 0;
};