AST
The JSON form of a parsed query — how the tree is shaped, the __type discriminator, ParseQuery and AstToBql for converting in both directions, the MinimalBql form, and validation.
BQL text parses into a tree of the grammar's rules (BQL grammar); the server can hand you that tree as JSON, accept it back in place of text, and turn it into text again. Clients that build or edit queries programmatically — the query editor, the parameter panel, the chat — work on this form.
Shape#
Every node is a JSON object with a __type naming its grammar class, and one member per attribute of that class; list attributes are arrays, enumerations are their literal names, and absent optional parts are omitted. The class and attribute names are those of the grammar rules: a query is a Bql with features, where, groupBy, orderBy, limit, offset and using; a GET item is a SingleFeature with feature (a FeatureWithOptionalUnit or an aggregate) and az (the alias); a condition is a TypeCondition, a TerminalExpression with feature and comparator, an AndExpression with left and right, and so on.
{
"__type": "Bql",
"features": [
{"__type": "SingleFeature", "feature": {"__type": "FeatureWithOptionalUnit", "feature": {"__type": "QidFeature"}}},
{"__type": "SingleFeature", "feature": {"__type": "FeatureWithOptionalUnit", "feature": {"__type": "AttributeFeature", "name": "Name"}}}
],
"where": {
"__type": "AndExpression",
"left": {"__type": "TypeCondition", "equalsType": "IFCWALL"},
"right": {"__type": "TerminalExpression",
"feature": {"__type": "PropertyFeature", "propertySetName": "Pset_WallCommon", "propertyNames": ["IsExternal"]},
"comparator": {"__type": "EqualsComparator", "literal": {"__type": "BooleanLiteral", "value": "TRUE"}}}
}
}The example is the tree of GET qid, attribute.Name WHERE type = IFCWALL AND property.Pset_WallCommon.IsExternal = true; obtain the exact tree for any query from ParseQuery rather than composing it by hand, because attribute names follow the grammar and change when the grammar does.
Text to AST: ParseQuery#
The ParseQuery task takes query (text) and returns the tree. With a parameters object it returns the tree with the parameters already bound (using#binding), so a client that needs a bound tree does not substitute values itself. In the SDKs: client.bim.parseQuery(query) (Java, ObjectNode).
AST to text: AstToBql#
AstToBql takes ast and returns the query text, formatted by the language's writer. Editing a query is therefore parse → change the tree → write.
Querying with an AST#
The query tasks accept query either as text or as a tree whose __type is Bql. A tree with __type MinimalBql — a condition with optional GROUP BY, ORDER BY, LIMIT and OFFSET but no GET — is accepted too; it is the form the visualisation language's if conditions have.
Validation#
ValidateQuery parses and augments a query without running it. A query that does not parse is rejected with SYNTAX_ERROR, the line and column in its message; one that parses is answered with its validation problems as messages, each with a line and column, a severity, a code and a message (Validate a query). The messages are those of the editor: unknown IFC class names and attribute names with a did-you-mean, unit mismatches, aggregate and relation misuse, BETWEEN bounds in the wrong order, deprecated spellings. The validator reads text, so a query given as a tree gets no such messages. Passing an empty model list to Query checks the syntax as well, without the messages.
The other languages#
BVL, BUL, BCL, BRL, BSL and BCOL reuse the BQL classes for every condition and feature, so their trees embed BQL subtrees; BvlToAst, ResolveBvl and ResolveBsl accept either text or such a tree.
Used in#
- Validate a query — validation before running.
- Use query parameters — binding through
ParseQuery.