This document provides an overview of the Asterix Query language.
Expression ::= ( OperatorExpr | IfThenElse | FLWOGR | QuantifiedExpression )
PrimaryExpr ::= Literal | VariableRef | ParenthesizedExpression | FunctionCallExpr | DatasetAccessExpression | ListConstructor | RecordConstructor
Literal ::= StringLiteral | <INTEGER_LITERAL> | <FLOAT_LITERAL> | <DOUBLE_LITERAL> | <NULL> | <TRUE> | <FALSE> StringLiteral ::= <STRING_LITERAL>
VariableRef ::= <VARIABLE>
ParenthesizedExpression ::= <LEFTPAREN> Expression <RIGHTPAREN>
FunctionCallExpr ::= FunctionOrTypeName <LEFTPAREN> ( Expression ( "," Expression )* )? <RIGHTPAREN>
DatasetAccessExpression ::= <DATASET> ( ( Identifier ( "." Identifier )? ) | ( <LEFTPAREN> Expression ( "," Expression )* <RIGHTPAREN> ) ) Identifier ::= <IDENTIFIER> | StringLiteral
ListConstructor ::= ( OrderedListConstructor | UnorderedListConstructor ) OrderedListConstructor ::= "[" ( Expression ( "," Expression )* )? "]" UnorderedListConstructor ::= "{{" ( Expression ( "," Expression )* )? "}}" RecordConstructor ::= "{" ( FieldBinding ( "," FieldBinding )* )? "}" FieldBinding ::= Expression ":" Expression
ValueExpr ::= PrimaryExpr ( Field | Index )* Field ::= "." Identifier Index ::= "[" ( Expression | "?" ) "]"
OperatorExpr ::= AndExpr ( "or" AndExpr )* AndExpr ::= RelExpr ( "and" RelExpr )*
RelExpr ::= AddExpr ( ( "<" | ">" | "<=" | ">=" | "=" | "!=" | "~=" ) AddExpr )?
AddExpr ::= MultExpr ( ( "+" | "-" ) MultExpr )* MultExpr ::= UnaryExpr ( ( "*" | "/" | "%" | <CARET> | "idiv" ) UnaryExpr )* UnaryExpr ::= ( ( "+" | "-" ) )? ValueExpr
FLWOGR ::= ( ForClause | LetClause ) ( Clause )* "return" Expression Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause ForClause ::= "for" Variable ( "at" Variable )? "in" ( Expression ) LetClause ::= "let" Variable ":=" Expression WhereClause ::= "where" Expression OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )* GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* "with" VariableRef ( "," VariableRef )* LimitClause ::= "limit" Expression ( "offset" Expression )? DistinctClause ::= "distinct" "by" Expression ( "," Expression )* Variable ::= <VARIABLE>
IfThenElse ::= "if" <LEFTPAREN> Expression <RIGHTPAREN> "then" Expression "else" Expression
QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression ( "," Variable "in" Expression )* "satisfies" Expression
Statement ::= ( SingleStatement ( ";" )? )* <EOF> SingleStatement ::= DataverseDeclaration | FunctionDeclaration | CreateStatement | DropStatement | LoadStatement | SetStatement | InsertStatement | DeleteStatement | FeedStatement | Query
DataverseDeclaration ::= "use" "dataverse" Identifier SetStatement ::= "set" Identifier StringLiteral FunctionDeclaration ::= "declare" "function" Identifier ParameterList "{" Expression "}" ParameterList ::= <LEFTPAREN> ( <VARIABLE> ( "," <VARIABLE> )* )? <RIGHTPAREN>
CreateStatement ::= "create" ( TypeSpecification | DatasetSpecification | IndexSpecification | DataverseSpecification | FunctionSpecification ) DropStatement ::= "drop" ( <DATASET> QualifiedName IfExists | "index" DoubleQualifiedName IfExists | "type" FunctionOrTypeName IfExists | "dataverse" Identifier IfExists | "function" FunctionSignature IfExists ) IfExists ::= ( "if" "exists" )? QualifiedName ::= Identifier ( "." Identifier )? DoubleQualifiedName ::= Identifier "." Identifier ( "." Identifier )?
TypeSpecification ::= "type" FunctionOrTypeName IfNotExists "as" TypeExpr FunctionOrTypeName ::= QualifiedName IfNotExists ::= ( "if not exists" )? TypeExpr ::= RecordTypeDef | TypeReference | OrderedListTypeDef | UnorderedListTypeDef RecordTypeDef ::= ( "closed" | "open" )? "{" ( RecordField ( "," RecordField )* )? "}" RecordField ::= Identifier ":" ( TypeExpr ) ( "?" )? TypeReference ::= Identifier OrderedListTypeDef ::= "[" ( TypeExpr ) "]" UnorderedListTypeDef ::= "{{" ( TypeExpr ) "}}"
DatasetSpecification ::= "external" <DATASET> QualifiedName <LEFTPAREN> Identifier <RIGHTPAREN> IfNotExists "using" AdapterName Configuration ( "hints" Properties )? | "feed" <DATASET> QualifiedName <LEFTPAREN> Identifier <RIGHTPAREN> IfNotExists "using" AdapterName Configuration ( ApplyFunction )? PrimaryKey ( "on" Identifier )? ( "hints" Properties )? | "internal"? <DATASET> QualifiedName <LEFTPAREN> Identifier <RIGHTPAREN> IfNotExists PrimaryKey ( "on" Identifier )? ( "hints" Properties )? AdapterName ::= Identifier Configuration ::= <LEFTPAREN> ( KeyValuePair ( "," KeyValuePair )* )? <RIGHTPAREN> KeyValuePair ::= <LEFTPAREN> StringLiteral "=" StringLiteral <RIGHTPAREN> Properties ::= ( <LEFTPAREN> Property ( "," Property )* <RIGHTPAREN> )? Property ::= Identifier "=" ( StringLiteral | <INTEGER_LITERAL> ) ApplyFunction ::= "apply" "function" FunctionSignature FunctionSignature ::= FunctionOrTypeName "@" <INTEGER_LITERAL> PrimaryKey ::= "primary" "key" Identifier ( "," Identifier )*
IndexSpecification ::= "index" Identifier IfNotExists "on" QualifiedName <LEFTPAREN> ( Identifier ) ( "," Identifier )* <RIGHTPAREN> ( "type" IndexType )? IndexType ::= "btree" | "rtree" | "keyword" | "fuzzy keyword" | "ngram" <LEFTPAREN> <INTEGER_LITERAL> <RIGHTPAREN> | "fuzzy ngram" <LEFTPAREN> <INTEGER_LITERAL> <RIGHTPAREN>
DataverseSpecification ::= "dataverse" Identifier IfNotExists ( "with format" StringLiteral )?
FunctionSpecification ::= "function" FunctionOrTypeName IfNotExists ParameterList "{" Expression "}"
LoadStatement ::= "load" <DATASET> QualifiedName "using" AdapterName Configuration ( "pre-sorted" )?
InsertStatement ::= "insert" "into" <DATASET> QualifiedName Query DeleteStatement ::= "delete" Variable "from" <DATASET> QualifiedName ( "where" Expression )?
FeedStatement ::= "begin" "feed" QualifiedName | "suspend" "feed" QualifiedName | "resume" "feed" QualifiedName | "end" "feed" QualifiedName | "alter" "feed" QualifiedName "set" Configuration
Query ::= Expression