Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CQL arithmetic expressions #103

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,23 @@ It includes [*OGC API - Features*](http://docs.opengeospatial.org/is/17-069r3/17
- [x] property names
- [x] character literals
- [x] numeric literals
- [x] geometry literals
- `POINT`,`LINESTRING`,`POLYGON`,`MULTIPOINT`,`MULTILINESTRING`,`MULTIPOLYGON`,`GEOMETRYCOLLECTION`,`ENVELOPE`
- [ ] temporal literals
- [x] arithemetic expressions
- `+`,`-`,`*`,`/`, `%`, parentheses
- [x] binary comparisons
- `<`,`<=`,`>`,`>=`,`=`,`<>`
- [x] `property [NOT] BETWEEN a AND B`
- [x] `property [NOT] IN ( value-list )`
- [x] `property [NOT] (LIKE | ILIKE) pattern`
- `pattern` can include `%` wildcards
- [x] `property [NOT] IS NULL`
- [x] boolean combinations (`AND`,`OR`,`NOT`)
- [x] boolean combinations (`AND`,`OR`,`NOT`, parentheses)
- [x] geometry literals
- `POINT`,`LINESTRING`,`POLYGON`,`MULTIPOINT`,`MULTILINESTRING`,`MULTIPOLYGON`,`GEOMETRYCOLLECTION`,`ENVELOPE`
- [x] spatial predicates
- `INTERSECTS`,`DISJOINT`,`CONTAINS`,`WITHIN`,`EQUALS`,`CROSSES`,`OVERLAPS`,`TOUCHES`
- [x] distance predicate
- `DWITHIN`
- [ ] temporal literals
- [ ] temporal predicates
- [ ] functions

Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Add configuration to set base path (#88)
* Add standard query parameters `crs` and `bbox-crs` (#98)
* Allow configuring published function schemas (#99)
* Add support for CQL filtering with `filter` and `filter-crs` query parameters (#101, #102)
* Add support for CQL filtering with `filter` and `filter-crs` query parameters (#101, #102, #103)

### Performance Improvements

Expand Down
11 changes: 11 additions & 0 deletions hugo/content/usage/cql.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ true
'it''s easy'
```

## Arithmetic expressions

Numeric values can be combined using the
arithmetic operators `+`,`-`,`*`,`/` and `%` (modulo), with parentheses if needed
for operator precedence.
```
x + 3
2 * (y - 3)
p % 10
```

## Comparisons

Values can be compared using conditional operators:
Expand Down
20 changes: 14 additions & 6 deletions internal/cql/CQL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,34 @@ predicate : binaryComparisonPredicate
# an operator to test if a scalar expression is NULL or not.
#============================================================================*/

binaryComparisonPredicate : scalarExpression ComparisonOperator scalarExpression;
binaryComparisonPredicate : arithmeticExpression ComparisonOperator arithmeticExpression;

likePredicate : propertyName (NOT)? ( LIKE | ILIKE ) characterLiteral;

betweenPredicate : propertyName (NOT)? BETWEEN
scalarExpression AND scalarExpression ;
// (scalarExpression | temporalExpression) AND (scalarExpression | temporalExpression);
arithmeticExpression AND arithmeticExpression ;
// (scalarValue | temporalExpression) AND (scalarValue | temporalExpression);

isNullPredicate : propertyName IS (NOT)? NULL;

/*============================================================================
# Arithmetic expressions
#============================================================================*/

arithmeticExpression : scalarValue
| LEFTPAREN arithmeticExpression RIGHTPAREN
| arithmeticExpression ArithmeticOperator arithmeticExpression
;

/*
# A scalar expression is the property name, a chracter literal, a numeric
# A scalar value is a property name, a chracter literal, a numeric
# literal or a function/method invocation that returns a scalar value.
*/
scalarExpression : propertyName
scalarValue : propertyName
| characterLiteral
| numericLiteral
| booleanLiteral
// | function
// | arithmeticExpression
;

propertyName: Identifier;
Expand Down
145 changes: 73 additions & 72 deletions internal/cql/CQL.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -15,78 +15,79 @@ BETWEEN=14
IS=15
NULL=16
IN=17
SpatialOperator=18
DistanceOperator=19
POINT=20
LINESTRING=21
POLYGON=22
MULTIPOINT=23
MULTILINESTRING=24
MULTIPOLYGON=25
GEOMETRYCOLLECTION=26
ENVELOPE=27
NumericLiteral=28
Identifier=29
IdentifierStart=30
IdentifierPart=31
ALPHA=32
DIGIT=33
OCTOTHORP=34
DOLLAR=35
UNDERSCORE=36
DOUBLEQUOTE=37
PERCENT=38
AMPERSAND=39
QUOTE=40
LEFTPAREN=41
RIGHTPAREN=42
LEFTSQUAREBRACKET=43
RIGHTSQUAREBRACKET=44
ASTERISK=45
PLUS=46
COMMA=47
MINUS=48
PERIOD=49
SOLIDUS=50
COLON=51
SEMICOLON=52
QUESTIONMARK=53
VERTICALBAR=54
BIT=55
HEXIT=56
UnsignedNumericLiteral=57
SignedNumericLiteral=58
ExactNumericLiteral=59
ApproximateNumericLiteral=60
Mantissa=61
Exponent=62
SignedInteger=63
UnsignedInteger=64
Sign=65
WS=66
CharacterStringLiteral=67
QuotedQuote=68
ArithmeticOperator=18
SpatialOperator=19
DistanceOperator=20
POINT=21
LINESTRING=22
POLYGON=23
MULTIPOINT=24
MULTILINESTRING=25
MULTIPOLYGON=26
GEOMETRYCOLLECTION=27
ENVELOPE=28
NumericLiteral=29
Identifier=30
IdentifierStart=31
IdentifierPart=32
ALPHA=33
DIGIT=34
OCTOTHORP=35
DOLLAR=36
UNDERSCORE=37
DOUBLEQUOTE=38
PERCENT=39
AMPERSAND=40
QUOTE=41
LEFTPAREN=42
RIGHTPAREN=43
LEFTSQUAREBRACKET=44
RIGHTSQUAREBRACKET=45
ASTERISK=46
PLUS=47
COMMA=48
MINUS=49
PERIOD=50
SOLIDUS=51
COLON=52
SEMICOLON=53
QUESTIONMARK=54
VERTICALBAR=55
BIT=56
HEXIT=57
UnsignedNumericLiteral=58
SignedNumericLiteral=59
ExactNumericLiteral=60
ApproximateNumericLiteral=61
Mantissa=62
Exponent=63
SignedInteger=64
UnsignedInteger=65
Sign=66
WS=67
CharacterStringLiteral=68
QuotedQuote=69
'<'=2
'='=3
'>'=4
'#'=34
'$'=35
'_'=36
'"'=37
'%'=38
'&'=39
'('=41
')'=42
'['=43
']'=44
'*'=45
'+'=46
','=47
'-'=48
'.'=49
'/'=50
':'=51
';'=52
'?'=53
'|'=54
'\'\''=68
'#'=35
'$'=36
'_'=37
'"'=38
'%'=39
'&'=40
'('=42
')'=43
'['=44
']'=45
'*'=46
'+'=47
','=48
'-'=49
'.'=50
'/'=51
':'=52
';'=53
'?'=54
'|'=55
'\'\''=69
6 changes: 6 additions & 0 deletions internal/cql/CqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ IS : I S;
NULL: N U L L;
IN: I N;

/*============================================================================
# Definition of ARITHMETIC operators
#============================================================================*/

ArithmeticOperator : PLUS | MINUS | ASTERISK | SOLIDUS | PERCENT;

/*============================================================================
# Definition of SPATIAL operators
#============================================================================*/
Expand Down
Loading