ExpressionBuilder
Class: ExpressionBuilder
Defined in: packages/ql/src/query.ts:324
ANTLR parse tree visitor that builds an optimized Expression AST from the parsed tokens
Converts the ANTLR parse tree into a flat, evaluatable expression tree. Automatically flattens nested AND/OR expressions of the same type to reduce depth.
Extends
AbstractParseTreeVisitor<Query>
Extended by
Implements
WebdaQLParserVisitor<any>
Constructors
Constructor
new ExpressionBuilder():
ExpressionBuilder
Returns
ExpressionBuilder
Inherited from
AbstractParseTreeVisitor<Query>.constructor
Properties
limit
limit:
number
Defined in: packages/ql/src/query.ts:328
Parsed LIMIT value, if present
offset
offset:
string
Defined in: packages/ql/src/query.ts:332
Parsed OFFSET continuation token, if present
orderBy
orderBy:
OrderBy[]
Defined in: packages/ql/src/query.ts:336
Parsed ORDER BY clauses, if present
Methods
aggregateResult()
protectedaggregateResult(aggregate,nextResult):Query
Defined in: node_modules/.pnpm/antlr4ts@0.5.0-alpha.4/node_modules/antlr4ts/tree/AbstractParseTreeVisitor.d.ts:77
Aggregates the results of visiting multiple children of a node. After
either all children are visited or #shouldVisitNextChild returns
false, the aggregate value is returned as the result of
#visitChildren.
The default implementation returns nextResult, meaning
#visitChildren will return the result of the last child visited
(or return the initial value if the node has no children).
Parameters
aggregate
The previous aggregate value. In the default
implementation, the aggregate value is initialized to
#defaultResult, which is passed as the aggregate argument
to this method after the first child node is visited.
nextResult
The result of the immediately preceeding call to visit a child node.
Returns
The updated aggregate result.
Inherited from
AbstractParseTreeVisitor.aggregateResult
buildQuery()
protectedbuildQuery(type,expression,ctx):Query
Defined in: packages/ql/src/query.ts:564
Build the Query of a statement or filter query: its condition and its ORDER BY, LIMIT and OFFSET clauses
Parameters
type
the statement type
expression
ExpressionContext | undefined
the condition, if any
ctx
FilterQueryContext | DeleteStatementContext | UpdateStatementContext | SelectStatementContext
the statement context holding the optional clauses
Returns
the Query
defaultResult()
protecteddefaultResult():Query
Defined in: packages/ql/src/query.ts:342
Default result when no expression is matched (empty AND, always true)
Returns
an empty AND query
Overrides
AbstractParseTreeVisitor.defaultResult
getComparison()
getComparison(
ctx):any[]
Defined in: packages/ql/src/query.ts:599
Recursively flatten nested logical expressions of the same type
ANTLR produces right-recursive trees like a AND (b AND (c AND d)).
This method flattens them into [a, b, c, d] so a single LogicalExpression
holds all children at one level.
Parameters
ctx
AndLogicExpressionContext | OrLogicExpressionContext
an AND or OR logical expression context
Returns
any[]
flat array of child parse tree nodes
getLimit()
getLimit():
number
Defined in: packages/ql/src/query.ts:362
Get parsed LIMIT value
Returns
number
the limit value
getOffset()
getOffset():
string
Defined in: packages/ql/src/query.ts:354
Get parsed OFFSET continuation token
Returns
string
the offset token
shouldVisitNextChild()
protectedshouldVisitNextChild(node,currentResult):boolean
Defined in: node_modules/.pnpm/antlr4ts@0.5.0-alpha.4/node_modules/antlr4ts/tree/AbstractParseTreeVisitor.d.ts:102
This method is called after visiting each child in
#visitChildren. This method is first called before the first
child is visited; at that point currentResult will be the initial
value (in the default implementation, the initial value is returned by a
call to #defaultResult. This method is not called after the last
child is visited.
The default implementation always returns true, indicating that
visitChildren should only return after all children are visited.
One reason to override this method is to provide a "short circuit"
evaluation option for situations where the result of visiting a single
child has the potential to determine the result of the visit operation as
a whole.
Parameters
node
RuleNode
The RuleNode whose children are currently being visited.
currentResult
The current aggregate result of the children visited to the current point.
Returns
boolean
true to continue visiting children. Otherwise return
false to stop visiting children and immediately return the
current aggregate result from #visitChildren.
Inherited from
AbstractParseTreeVisitor.shouldVisitNextChild
visit()
visit(
tree):Query
Defined in: node_modules/.pnpm/antlr4ts@0.5.0-alpha.4/node_modules/antlr4ts/tree/AbstractParseTreeVisitor.d.ts:17
The default implementation calls ParseTree#accept on the specified tree.
Parameters
tree
ParseTree
Returns
Implementation of
WebdaQLParserVisitor.visit
Inherited from
AbstractParseTreeVisitor.visit
visitAndLogicExpression()
visitAndLogicExpression(
ctx):Expression
Defined in: packages/ql/src/query.ts:631
Get the AndExpression, regrouping all the parameters
By default the parser is doing a AND (b AND (c AND d)) creating 3 depth expressions This visitor simplify to a AND b AND c AND d with only one Expression
Parameters
ctx
AndLogicExpressionContext
the AND logic expression context
Returns
the flattened AndExpression
Implementation of
WebdaQLParserVisitor.visitAndLogicExpression
visitAssignment()
visitAssignment(
ctx):Assignment
Defined in: packages/ql/src/query.ts:498
Read one field = value of an UPDATE SET
Parameters
ctx
AssignmentContext
the assignment context
Returns
the assignment
Implementation of
WebdaQLParserVisitor.visitAssignment
visitAtomExpression()
visitAtomExpression(
ctx):Expression
Defined in: packages/ql/src/query.ts:735
A bare atom used as an expression: only TRUE / FALSE are valid
Parameters
ctx
AtomExpressionContext
the atom expression context
Returns
the constant expression
Throws
for identifiers, numbers and strings
Implementation of
WebdaQLParserVisitor.visitAtomExpression
visitBinaryComparisonExpression()
visitBinaryComparisonExpression(
ctx):ComparisonExpression<ComparisonOperator>
Defined in: packages/ql/src/query.ts:643
Implement the BinaryComparison with all methods managed
Parameters
ctx
BinaryComparisonExpressionContext
the binary comparison context
Returns
ComparisonExpression<ComparisonOperator>
the comparison expression
Implementation of
WebdaQLParserVisitor.visitBinaryComparisonExpression
visitBooleanLiteral()
visitBooleanLiteral(
ctx):boolean
Defined in: packages/ql/src/query.ts:757
Read the boolean literal
Parameters
ctx
BooleanLiteralContext
the boolean literal context
Returns
boolean
the boolean value
Implementation of
WebdaQLParserVisitor.visitBooleanLiteral
visitChildren()
visitChildren(
node):Query
Defined in: node_modules/.pnpm/antlr4ts@0.5.0-alpha.4/node_modules/antlr4ts/tree/AbstractParseTreeVisitor.d.ts:33
The default implementation initializes the aggregate result to
#defaultResult defaultResult(). Before visiting each child, it
calls #shouldVisitNextChild shouldVisitNextChild; if the result
is false no more children are visited and the current aggregate
result is returned. After visiting a child, the aggregate result is
updated by calling #aggregateResult aggregateResult with the
previous aggregate result and the result of visiting the child.
The default implementation is not safe for use in visitors that modify the tree structure. Visitors that modify the tree should override this method to behave properly in respect to the specific algorithm in use.
Parameters
node
RuleNode
Returns
Implementation of
WebdaQLParserVisitor.visitChildren
Inherited from
AbstractParseTreeVisitor.visitChildren
visitContainsExpression()
visitContainsExpression(
ctx):ComparisonExpression<"CONTAINS">
Defined in: packages/ql/src/query.ts:689
Map the a CONTAINS 'b'
Parameters
ctx
ContainsExpressionContext
the CONTAINS expression context
Returns
ComparisonExpression<"CONTAINS">
the comparison expression
Implementation of
WebdaQLParserVisitor.visitContainsExpression
visitDeleteStatement()
visitDeleteStatement(
ctx):Query
Defined in: packages/ql/src/query.ts:441
Visit DELETE [WHERE ...] [LIMIT n]
Parameters
ctx
DeleteStatementContext
the DELETE statement context
Returns
the built Query
Implementation of
WebdaQLParserVisitor.visitDeleteStatement
visitErrorNode()
visitErrorNode(
node):Query
Defined in: node_modules/.pnpm/antlr4ts@0.5.0-alpha.4/node_modules/antlr4ts/tree/AbstractParseTreeVisitor.d.ts:47
The default implementation returns the result of #defaultResult defaultResult.
Parameters
node
ErrorNode
Returns
Implementation of
WebdaQLParserVisitor.visitErrorNode
Inherited from
AbstractParseTreeVisitor.visitErrorNode
visitFieldList()
visitFieldList(
ctx):object
Defined in: packages/ql/src/query.ts:520
Read the field list of a SELECT: plain fields and aggregate metrics
Parameters
ctx
FieldListContext
the field list context
Returns
object
the field paths and the metrics by alias
fields
fields:
string[]
metrics
metrics:
Record<string,Metric>
Implementation of
WebdaQLParserVisitor.visitFieldList
visitFilterQuery()
visitFilterQuery(
ctx):Query
Defined in: packages/ql/src/query.ts:432
Visit a plain filter query: an implicit SELECT of every field
Parses filter expression, ORDER BY, LIMIT, and OFFSET clauses. Returns an empty AND expression (always true) when no filter is present.
Parameters
ctx
FilterQueryContext
the filter query context
Returns
the built Query
Implementation of
WebdaQLParserVisitor.visitFilterQuery
visitInExpression()
visitInExpression(
ctx):ComparisonExpression<"IN">
Defined in: packages/ql/src/query.ts:677
Map the a IN ['b','c']
Parameters
ctx
InExpressionContext
the IN expression context
Returns
ComparisonExpression<"IN">
the comparison expression
Implementation of
WebdaQLParserVisitor.visitInExpression
visitIntegerLiteral()
visitIntegerLiteral(
ctx):number
Defined in: packages/ql/src/query.ts:766
Read the number literal
Parameters
ctx
IntegerLiteralContext
the integer literal context
Returns
number
the parsed integer value
Implementation of
WebdaQLParserVisitor.visitIntegerLiteral
visitIsNotNullExpression()
visitIsNotNullExpression(
ctx):ComparisonExpression<"IS NOT NULL">
Defined in: packages/ql/src/query.ts:710
Map the a IS NOT NULL
Parameters
ctx
IsNotNullExpressionContext
the IS NOT NULL expression context
Returns
ComparisonExpression<"IS NOT NULL">
the comparison expression
Implementation of
WebdaQLParserVisitor.visitIsNotNullExpression
visitIsNullExpression()
visitIsNullExpression(
ctx):ComparisonExpression<"IS NULL">
Defined in: packages/ql/src/query.ts:701
Map the a IS NULL
Parameters
ctx
IsNullExpressionContext
the IS NULL expression context
Returns
ComparisonExpression<"IS NULL">
the comparison expression
Implementation of
WebdaQLParserVisitor.visitIsNullExpression
visitLikeExpression()
visitLikeExpression(
ctx):ComparisonExpression<"LIKE">
Defined in: packages/ql/src/query.ts:665
Visit a LIKE expression (e.g. field LIKE '%pattern_')
Parameters
ctx
LikeExpressionContext
the LIKE expression context
Returns
ComparisonExpression<"LIKE">
the comparison expression
Implementation of
WebdaQLParserVisitor.visitLikeExpression
visitLimitExpression()
visitLimitExpression(
ctx):void
Defined in: packages/ql/src/query.ts:370
Visit a LIMIT clause and store the integer value
Parameters
ctx
LimitExpressionContext
the limit expression context
Returns
void
Implementation of
WebdaQLParserVisitor.visitLimitExpression
visitNowFunction()
visitNowFunction(
ctx):NowValue
Defined in: packages/ql/src/query.ts:784
Visit a NOW() function call with optional duration offset
Parameters
ctx
NowFunctionContext
the now function context
Returns
the NowValue
Implementation of
WebdaQLParserVisitor.visitNowFunction
visitNumberLiteral()
visitNumberLiteral(
ctx):number
Defined in: packages/ql/src/query.ts:775
Read a signed or decimal number literal
Parameters
ctx
NumberLiteralContext
the number literal context
Returns
number
the parsed number
Implementation of
WebdaQLParserVisitor.visitNumberLiteral
visitOffsetExpression()
visitOffsetExpression(
ctx):void
Defined in: packages/ql/src/query.ts:378
Visit an OFFSET clause and store the string continuation token
Parameters
ctx
OffsetExpressionContext
the offset expression context
Returns
void
Implementation of
WebdaQLParserVisitor.visitOffsetExpression
visitOrderExpression()
visitOrderExpression(
ctx):void
Defined in: packages/ql/src/query.ts:398
Read the order by values
Parameters
ctx
OrderExpressionContext
the order expression context
Returns
void
Implementation of
WebdaQLParserVisitor.visitOrderExpression
visitOrderFieldExpression()
visitOrderFieldExpression(
ctx):OrderBy
Defined in: packages/ql/src/query.ts:387
Visit a order field expression
Parameters
ctx
OrderFieldExpressionContext
the order field expression context
Returns
the parsed OrderBy
Implementation of
WebdaQLParserVisitor.visitOrderFieldExpression
visitOrLogicExpression()
visitOrLogicExpression(
ctx):Expression
Defined in: packages/ql/src/query.ts:722
Get the OrExpression, regrouping all the parameters
By default the parser is doing a OR (b OR (c OR d)) creating 3 depth expressions This visitor simplify to a OR b OR c OR d with only one Expression
Parameters
ctx
OrLogicExpressionContext
the OR logic expression context
Returns
the flattened OrExpression
Implementation of
WebdaQLParserVisitor.visitOrLogicExpression
visitParameter()
visitParameter(
ctx):never
Defined in: packages/ql/src/query.ts:813
A ? or :name placeholder reaching evaluation was never bound
Parameters
ctx
ParameterContext
the parameter context
Returns
never
Throws
always: use bind() or pass the parameters to query()
Implementation of
WebdaQLParserVisitor.visitParameter
visitSelectStatement()
visitSelectStatement(
ctx):Query
Defined in: packages/ql/src/query.ts:465
Visit a SELECT statement: a field list, or an aggregation when it has metrics or a GROUP BY
Parameters
ctx
SelectStatementContext
the select statement context
Returns
the query
Implementation of
WebdaQLParserVisitor.visitSelectStatement
visitSetExpression()
visitSetExpression(
ctx):value[]
Defined in: packages/ql/src/query.ts:656
Visit each value of the [..., ..., ...] set
Parameters
ctx
SetExpressionContext
the set expression context
Returns
value[]
the array of values
Implementation of
WebdaQLParserVisitor.visitSetExpression
visitStatement()
visitStatement(
ctx):Query
Defined in: packages/ql/src/query.ts:420
Visit a DELETE, UPDATE or SELECT statement
Parameters
ctx
StatementContext
the statement context
Returns
the built Query
Implementation of
WebdaQLParserVisitor.visitStatement
visitStringLiteral()
visitStringLiteral(
ctx):string
Defined in: packages/ql/src/query.ts:748
Read a string literal, stripping the surrounding single or double quotes
Parameters
ctx
StringLiteralContext
the string literal context
Returns
string
the unquoted string value
Implementation of
WebdaQLParserVisitor.visitStringLiteral
visitSubExpression()
visitSubExpression(
ctx):Expression
Defined in: packages/ql/src/query.ts:553
Visit a parenthesised expression: the inner expression
Parameters
ctx
SubExpressionContext
the sub expression context
Returns
the inner expression
Implementation of
WebdaQLParserVisitor.visitSubExpression
visitTerminal()
visitTerminal(
node):Query
Defined in: node_modules/.pnpm/antlr4ts@0.5.0-alpha.4/node_modules/antlr4ts/tree/AbstractParseTreeVisitor.d.ts:40
The default implementation returns the result of #defaultResult defaultResult.
Parameters
node
TerminalNode
Returns
Implementation of
WebdaQLParserVisitor.visitTerminal
Inherited from
AbstractParseTreeVisitor.visitTerminal
visitUpdateStatement()
visitUpdateStatement(
ctx):Query
Defined in: packages/ql/src/query.ts:450
Visit UPDATE SET a = v, ... [WHERE ...] [LIMIT n]
Parameters
ctx
UpdateStatementContext
the UPDATE statement context
Returns
the built Query
Implementation of
WebdaQLParserVisitor.visitUpdateStatement
visitWebdaql()
visitWebdaql(
ctx):Query
Defined in: packages/ql/src/query.ts:409
Visit the root webdaql rule and build the complete Query: a statement or a plain filter query
Parameters
ctx
WebdaqlContext
the webdaql parse context
Returns
the built Query
Implementation of
WebdaQLParserVisitor.visitWebdaql