Skip to content

Commit 2951467

Browse files
author
Dean Karn
authored
Add BETWEEN operator & Fix DateTime gt, get, lt, lte (#6)
1 parent 73947ec commit 2951467

File tree

6 files changed

+232
-35
lines changed

6 files changed

+232
-35
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.3.0] - 2022-07-19
10+
### Added
11+
- Added BETWEEN operator support <value> BETWEEN <value> <value>
12+
13+
### Fixed
14+
- Missing Gt, Gte, Lt, Lte for DateTime data type.
15+
916
## [0.2.0] - 2022-07-18
1017
### Fixed
1118
- Reworked Parsing algorithm fixing a bunch of scoping issues.
@@ -24,7 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2431
### Added
2532
- Initial conversion from https://github.com/rust-playground/ksql.
2633

27-
[Unreleased]: https://github.com/go-playground/ksql/compare/v0.2.0...HEAD
34+
[Unreleased]: https://github.com/go-playground/ksql/compare/v0.3.0...HEAD
35+
[0.2.0]: https://github.com/go-playground/ksql/compare/v0.2.0...v0.3.0
2836
[0.2.0]: https://github.com/go-playground/ksql/compare/v0.1.1...v0.2.0
2937
[0.1.1]: https://github.com/go-playground/ksql/compare/v0.1.0...v0.1.1
3038
[0.1.0]: https://github.com/go-playground/ksql/commit/v0.1.0

README.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,39 +52,40 @@ Expressions support most mathematical and string expressions see below for detai
5252

5353
#### Syntax & Rules
5454

55-
| Token | Example | Syntax Rules |
56-
|-----------------|--------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
57-
| `Equals` | `==` | supports both `==` and `=`. |
58-
| `Add` | `+` | N/A |
59-
| `Subtract` | `-` | N/A |
60-
| `Multiply` | `*` | N/A |
61-
| `Divide` | `/` | N/A |
62-
| `Gt` | `>` | N/A |
63-
| `Gte` | `>=` | N/A |
64-
| `Lt` | `<` | N/A |
65-
| `Lte` | `<=` | N/A |
66-
| `OpenParen` | `(` | N/A |
67-
| `CloseParen` | `)` | N/A |
68-
| `OpenBracket` | `[` | N/A |
69-
| `CloseBracket` | `]` | N/A |
70-
| `Comma` | `,` | N/A |
71-
| `QuotedString` | `"sample text"` | Must start and end with an unescaped `"` character |
72-
| `Number` | `123.45` | Must start and end with a valid `0-9` digit. |
73-
| `BooleanTrue` | `true` | Accepts `true` as a boolean only. |
74-
| `BooleanFalse` | `false` | Accepts `false` as a boolean only. |
75-
| `SelectorPath` | `.selector_path` | Starts with a `.` and ends with whitespace blank space. This crate currently uses [gjson](https://github.com/tidwall/gjson.rs) and so the full gjson syntax for identifiers is supported. |
76-
| `And` | `&&` | N/A |
77-
| `Not` | `!` | Must be before Boolean identifier or expression or be followed by an operation |
78-
| `Or` | <code>&vert;&vert;<code> | N/A |
79-
| `Contains` | `CONTAINS ` | Ends with whitespace blank space. |
80-
| `ContainsAny` | `CONTAINS_ANY ` | Ends with whitespace blank space. |
81-
| `ContainsAll` | `CONTAINS_ALL ` | Ends with whitespace blank space. |
82-
| `In` | `IN ` | Ends with whitespace blank space. |
83-
| `StartsWith` | `STARTSWITH ` | Ends with whitespace blank space. |
84-
| `EndsWith` | `ENDSWITH ` | Ends with whitespace blank space. |
85-
| `NULL` | `NULL` | N/A |
86-
| `Coerce` | `COERCE` | Coerces one data type into another using in combination with 'Identifier'. Syntax is `COERCE <expression> _identifer_`. |
87-
| `Identifier` | `_identifier_` | Starts and end with an `_` used with 'COERCE' to cast data types. Currently the onyl supported `Identifier` is `_datetime_`. |
55+
| Token | Example | Syntax Rules |
56+
|----------------|--------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
57+
| `Equals` | `==` | supports both `==` and `=`. |
58+
| `Add` | `+` | N/A |
59+
| `Subtract` | `-` | N/A |
60+
| `Multiply` | `*` | N/A |
61+
| `Divide` | `/` | N/A |
62+
| `Gt` | `>` | N/A |
63+
| `Gte` | `>=` | N/A |
64+
| `Lt` | `<` | N/A |
65+
| `Lte` | `<=` | N/A |
66+
| `OpenParen` | `(` | N/A |
67+
| `CloseParen` | `)` | N/A |
68+
| `OpenBracket` | `[` | N/A |
69+
| `CloseBracket` | `]` | N/A |
70+
| `Comma` | `,` | N/A |
71+
| `QuotedString` | `"sample text"` | Must start and end with an unescaped `"` character |
72+
| `Number` | `123.45` | Must start and end with a valid `0-9` digit. |
73+
| `BooleanTrue` | `true` | Accepts `true` as a boolean only. |
74+
| `BooleanFalse` | `false` | Accepts `false` as a boolean only. |
75+
| `SelectorPath` | `.selector_path` | Starts with a `.` and ends with whitespace blank space. This crate currently uses [gjson](https://github.com/tidwall/gjson.rs) and so the full gjson syntax for identifiers is supported. |
76+
| `And` | `&&` | N/A |
77+
| `Not` | `!` | Must be before Boolean identifier or expression or be followed by an operation |
78+
| `Or` | <code>&vert;&vert;<code> | N/A |
79+
| `Contains` | `CONTAINS ` | Ends with whitespace blank space. |
80+
| `ContainsAny` | `CONTAINS_ANY ` | Ends with whitespace blank space. |
81+
| `ContainsAll` | `CONTAINS_ALL ` | Ends with whitespace blank space. |
82+
| `In` | `IN ` | Ends with whitespace blank space. |
83+
| `Between` | ` BETWEEN ` | Starts & ends with whitespace blank space. example `1 BETWEEN 0 10` |
84+
| `StartsWith` | `STARTSWITH ` | Ends with whitespace blank space. |
85+
| `EndsWith` | `ENDSWITH ` | Ends with whitespace blank space. |
86+
| `NULL` | `NULL` | N/A |
87+
| `Coerce` | `COERCE` | Coerces one data type into another using in combination with 'Identifier'. Syntax is `COERCE <expression> _identifer_`. |
88+
| `Identifier` | `_identifier_` | Starts and end with an `_` used with 'COERCE' to cast data types. Currently the onyl supported `Identifier` is `_datetime_`. |
8889

8990

9091

lexer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
ContainsAny
4444
ContainsAll
4545
In
46+
Between
4647
StartsWith
4748
EndsWith
4849
OpenBracket
@@ -139,6 +140,8 @@ func tokenizeSingleToken(data []byte) (result LexerResult, err error) {
139140
result, err = tokenizeKeyword(data, "STARTSWITH", StartsWith)
140141
case 'E':
141142
result, err = tokenizeKeyword(data, "ENDSWITH", EndsWith)
143+
case 'B':
144+
result, err = tokenizeKeyword(data, "BETWEEN", Between)
142145
case 'N':
143146
result, err = tokenizeNull(data)
144147
case '_':

lexer_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ func Test(t *testing.T) {
327327
input: "CONTAINS_ALL",
328328
err: ErrInvalidKeyword{s: "CONTAINS_ALL"},
329329
},
330+
{
331+
name: "parse bad between",
332+
input: "BETWEEN",
333+
err: ErrInvalidKeyword{s: "BETWEEEN"},
334+
},
335+
{
336+
name: "parse BETWEEN",
337+
input: "BETWEEN ",
338+
tokens: []Token{{kind: Between, start: 0, len: 7}},
339+
},
330340
}
331341

332342
for _, tc := range tests {

0 commit comments

Comments
 (0)