Skip to main content

PartialExpressionBuilder

@webda/ql


Class: PartialExpressionBuilder

Defined in: packages/ql/src/query.ts:1742

Expression builder that creates PartialComparisonExpression nodes instead of regular ComparisonExpression nodes

Used by PartialValidator to support partial object matching.

Extends​

Constructors​

Constructor​

new PartialExpressionBuilder(): PartialExpressionBuilder

Returns​

PartialExpressionBuilder

Inherited from​

ExpressionBuilder.constructor

Properties​

limit​

limit: number

Defined in: packages/ql/src/query.ts:328

Parsed LIMIT value, if present

Inherited from​

ExpressionBuilder.limit


offset​

offset: string

Defined in: packages/ql/src/query.ts:332

Parsed OFFSET continuation token, if present

Inherited from​

ExpressionBuilder.offset


orderBy​

orderBy: OrderBy[]

Defined in: packages/ql/src/query.ts:336

Parsed ORDER BY clauses, if present

Inherited from​

ExpressionBuilder.orderBy


partial​

partial: boolean

Defined in: packages/ql/src/query.ts:1746

Whether partial mode is active (undefined attributes treated as matching)


partialMatch​

partialMatch: boolean

Defined in: packages/ql/src/query.ts:1750

Set to true during evaluation if any attribute was undefined and skipped

Methods​

aggregateResult()​

protected aggregateResult(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​

Query

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​

Query

The result of the immediately preceeding call to visit a child node.

Returns​

Query

The updated aggregate result.

Inherited from​

ExpressionBuilder.aggregateResult


buildQuery()​

protected buildQuery(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​

QueryType

the statement type

expression​

ExpressionContext | undefined

the condition, if any

ctx​

FilterQueryContext | DeleteStatementContext | UpdateStatementContext | SelectStatementContext

the statement context holding the optional clauses

Returns​

Query

the Query

Inherited from​

ExpressionBuilder.buildQuery


defaultResult()​

protected defaultResult(): Query

Defined in: packages/ql/src/query.ts:342

Default result when no expression is matched (empty AND, always true)

Returns​

Query

an empty AND query

Inherited from​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.getComparison


getLimit()​

getLimit(): number

Defined in: packages/ql/src/query.ts:362

Get parsed LIMIT value

Returns​

number

the limit value

Inherited from​

ExpressionBuilder.getLimit


getOffset()​

getOffset(): string

Defined in: packages/ql/src/query.ts:354

Get parsed OFFSET continuation token

Returns​

string

the offset token

Inherited from​

ExpressionBuilder.getOffset


setPartial()​

setPartial(partial): void

Defined in: packages/ql/src/query.ts:1756

Enable or disable partial evaluation mode

Parameters​

partial​

boolean

whether to enable partial mode

Returns​

void


setPartialMatch()​

setPartialMatch(partial): void

Defined in: packages/ql/src/query.ts:1764

Set the partial match flag (reset before each evaluation)

Parameters​

partial​

boolean

the partial match flag value

Returns​

void


shouldVisitNextChild()​

protected shouldVisitNextChild(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​

Query

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​

ExpressionBuilder.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​

Query

Inherited from​

ExpressionBuilder.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​

Expression

the flattened AndExpression

Inherited from​

ExpressionBuilder.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​

Assignment

the assignment

Inherited from​

ExpressionBuilder.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​

Expression

the constant expression

Throws​

for identifiers, numbers and strings

Inherited from​

ExpressionBuilder.visitAtomExpression


visitBinaryComparisonExpression()​

visitBinaryComparisonExpression(ctx): PartialComparisonExpression<any>

Defined in: packages/ql/src/query.ts:1785

Visit a binary comparison, returning a PartialComparisonExpression

Parameters​

ctx​

any

the binary comparison context

Returns​

PartialComparisonExpression<any>

the partial comparison expression

Overrides​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.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​

Query

Inherited from​

ExpressionBuilder.visitChildren


visitContainsExpression()​

visitContainsExpression(ctx): PartialComparisonExpression<"CONTAINS">

Defined in: packages/ql/src/query.ts:1810

Visit a CONTAINS expression, returning a PartialComparisonExpression

Parameters​

ctx​

any

the CONTAINS expression context

Returns​

PartialComparisonExpression<"CONTAINS">

the partial comparison expression

Overrides​

ExpressionBuilder.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​

Query

the built Query

Inherited from​

ExpressionBuilder.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​

Query

Inherited from​

ExpressionBuilder.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>

Inherited from​

ExpressionBuilder.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​

Query

the built Query

Inherited from​

ExpressionBuilder.visitFilterQuery


visitInExpression()​

visitInExpression(ctx): PartialComparisonExpression<"IN">

Defined in: packages/ql/src/query.ts:1798

Visit an IN expression, returning a PartialComparisonExpression

Parameters​

ctx​

any

the IN expression context

Returns​

PartialComparisonExpression<"IN">

the partial comparison expression

Overrides​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.visitIntegerLiteral


visitIsNotNullExpression()​

visitIsNotNullExpression(ctx): PartialComparisonExpression<"IS NOT NULL">

Defined in: packages/ql/src/query.ts:1831

Visit an IS NOT NULL expression, returning a PartialComparisonExpression

Parameters​

ctx​

any

the IS NOT NULL expression context

Returns​

PartialComparisonExpression<"IS NOT NULL">

the partial comparison expression

Overrides​

ExpressionBuilder.visitIsNotNullExpression


visitIsNullExpression()​

visitIsNullExpression(ctx): PartialComparisonExpression<"IS NULL">

Defined in: packages/ql/src/query.ts:1822

Visit an IS NULL expression, returning a PartialComparisonExpression

Parameters​

ctx​

any

the IS NULL expression context

Returns​

PartialComparisonExpression<"IS NULL">

the partial comparison expression

Overrides​

ExpressionBuilder.visitIsNullExpression


visitLikeExpression()​

visitLikeExpression(ctx): PartialComparisonExpression<"LIKE">

Defined in: packages/ql/src/query.ts:1773

Visit a LIKE expression, returning a PartialComparisonExpression

Parameters​

ctx​

any

the LIKE expression context

Returns​

PartialComparisonExpression<"LIKE">

the partial comparison expression

Overrides​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.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​

NowValue

the NowValue

Inherited from​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.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​

OrderBy

the parsed OrderBy

Inherited from​

ExpressionBuilder.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​

Expression

the flattened OrExpression

Inherited from​

ExpressionBuilder.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()

Inherited from​

ExpressionBuilder.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​

Query

the query

Inherited from​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.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​

Query

the built Query

Inherited from​

ExpressionBuilder.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

Inherited from​

ExpressionBuilder.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​

Expression

the inner expression

Inherited from​

ExpressionBuilder.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​

Query

Inherited from​

ExpressionBuilder.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​

Query

the built Query

Inherited from​

ExpressionBuilder.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​

Query

the built Query

Inherited from​

ExpressionBuilder.visitWebdaql