Commit Graph

20 Commits (bf4fce3c77b3f996cb151cb9aed0fd511b011ace)

Author SHA1 Message Date
Stuart Carnie d5719f9be2
refactor: Moved simplification of time range expressions to parser 2023-06-02 09:50:01 +10:00
Stuart Carnie 2dddda7c33
refactor: InfluxQL parser improvements (#7403)
* chore: Simplify insta snapshots

* chore: Extract struct-like enums to structs

This is in line with DataFusion, which also represents many of its
expression types as struct. The change permits explicit visit
methods for these new types.

These changes will be used by rewriting and visitors to treat the
types, such as Call as an atomic unit that can be replaced.
2023-04-02 21:41:49 +00:00
dependabot[bot] 4b888c7255
chore(deps): Bump insta from 1.28.0 to 1.29.0 (#7322)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.28.0 to 1.29.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.28.0...1.29.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-24 18:25:01 +00:00
Carol (Nichols || Goulding) faae5eb438 chore: Rerun cargo hakari manage-deps 2023-02-27 11:56:15 +01:00
dependabot[bot] a06f64b198
chore(deps): Bump insta from 1.26.0 to 1.28.0 (#7016)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.26.0 to 1.28.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.26.0...1.28.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-16 18:14:25 +00:00
Stuart Carnie 57f55e14c8
feat: IOx InfluxQL planner learns how to process time range expressions (#6772)
* feat: IOx learns InfluxQL time-range expression → DF logical Expr

IOx now understand the how to evaluate an InfluxQL time-range filter
expression and transform that to a DataFusion logical expression.

* chore: move time range expression to independent functions

There is no need for these to be part of the `InfluxQLToLogicalPlan`
struct and makes them easier to test.

* chore: support scalar now on either side of binary expression

* chore: improve error messages

* chore: address clippy concerns

* chore: add tests for time ranges

* chore: add a test where time appears on the right-hand side

Ensure time is correctly identified on the right-hand side of a
conditional expression.

* chore: add tests that specify a timezone

* chore: Run cargo hakari tasks

* chore: fix linting issues

* chore: Remove unnecessary line

* chore: Feedback: Add API to parse a conditional expression

Based on feedback from @alamb, we don't want to hide the error from
parsing a `ConditionalExpression`. To do this, we use the
public API, `parse_statements` as a model and provide a new API,
`parse_conditional_expression`, which returns a `Result` with the error
being a `ParseError`. Additionally, `ConditionalExpression` implements
the `FromStr` API using the `parse_conditional_expression` API.

* chore: PR feedback reverting this change

I believe my intention was to update all instances in the match, but
never completed the change. Will leave for another day.

* chore: PR feedback add additional comments

* chore: rustfmt

---------

Co-authored-by: CircleCI[bot] <circleci@influxdata.com>
2023-02-01 00:27:17 +00:00
Stuart Carnie 15a9b4f1e5
refactor: Drop Expr::UnaryOp to simplify tree traversal (#6600)
* refactor: Drop Expr::UnaryOp to simplify tree traversal

The UnaryOp doesn't provide and additional value and complicates
walking the AST, as literal values wrapped in a UnaryOp(Minus, ...)
require extra handling when reducing time range expressions, etc.

This change also is true to the InfluxQL Go implementation,
which represents whole number literals as signed integers unless
they exceed i64::MAX.

* chore: Refactor all usages of format!("{}", ?) to ?.to_string()

Per https://github.com/influxdata/influxdb_iox/pull/6600#discussion_r1072028895
2023-01-18 02:27:38 +00:00
Stuart Carnie 3f6bb3e330
feat: Parse IANA timezones in an InfluxQL TZ clause (#6585)
* feat: Parse IANA timezone strings to chrono_tz::Tz

* feat: Visitors can customise the return error type

This avoids having to remap errors from `&'static str` to the caller's
error type, and will be used in a future PR for time range expressions.

* chore: Run cargo hakari tasks

Co-authored-by: CircleCI[bot] <circleci@influxdata.com>
2023-01-15 22:00:41 +00:00
dependabot[bot] dfdc964f64
chore(deps): Bump insta from 1.24.1 to 1.26.0 (#6534)
* chore(deps): Bump insta from 1.24.1 to 1.26.0

Bumps [insta](https://github.com/mitsuhiko/insta) from 1.24.1 to 1.26.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.24.1...1.26.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: Run cargo hakari tasks

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: CircleCI[bot] <circleci@influxdata.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-01-09 08:02:08 +00:00
dependabot[bot] 84485b57b0
chore(deps): Bump insta from 1.24.0 to 1.24.1 (#6500)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.24.0 to 1.24.1.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.24.0...1.24.1)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-05 08:49:05 +00:00
dependabot[bot] 8bb56f6ef5
chore(deps): Bump insta from 1.23.0 to 1.24.0 (#6491)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.23.0 to 1.24.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.23.0...1.24.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-04 07:11:08 +00:00
dependabot[bot] 9305e4c566
chore(deps): Bump insta from 1.22.0 to 1.23.0 (#6370)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.22.0 to 1.23.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.22.0...1.23.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-12 06:48:35 +00:00
dependabot[bot] c3a2ac99aa
chore(deps): Bump insta from 1.21.2 to 1.22.0 (#6332)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.21.2 to 1.22.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.21.2...1.22.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-05 10:18:59 +00:00
dependabot[bot] 721dfb9960
chore(deps): Bump insta from 1.21.1 to 1.21.2 (#6235)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.21.1 to 1.21.2.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.21.1...1.21.2)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-28 09:42:03 +00:00
dependabot[bot] fa07a107a1
chore(deps): Bump insta from 1.21.0 to 1.21.1
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.21.0 to 1.21.1.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/commits/1.21.1)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-15 12:01:26 +00:00
Carol (Nichols || Goulding) 2e83e04eab
feat: Use workspace package metadata to reduce differences and repetition 2022-10-24 13:04:09 -04:00
Stuart Carnie 58e4c2697f
fix: Address InfluxQL parsing issues (#5857)
* feat: Reimplement keywords as BTreeSet for more efficient lookup

Added a `Token` type to perform case-insensitive comparisons to avoid
allocations when performing lookups in the set.

Also introduced new `keyword` combinator to replace use of
`tag_no_case`. This is necessary to prevent eagerly recognising tags
without the appropriate separator. For example, `tag_no_case("OR")`
will recognise `ORDER` in a conditional expression.

The new combinator a `keyword` follows the pattern:

```
keyword ::= (a..z | A..Z)* keyword_separator
keyword_separator ::= ' '  | '('  | ')' | ';' | ',' | '=' |
                      '\n' | '\t'
```

* fix: Allow quoted time; using more efficient case-insensitive comparison

* fix: Digits to right of decimal point are optional

* fix: More idiomatic use of zip

* fix: Use `keyword` combinator and adjust whitespace handling

* fix: <> is a valid alias for the != operator

* fix: Special handling of DISTINCT identifier for function call name

* chore: Add tests

* chore: Feedback to remove unnecessary comments

* chore: Switch from BTreeSet to HashSet – thanks @domodwyer!
2022-10-16 23:33:09 +00:00
Stuart Carnie 81722dc19b
feat: AST traversal using Visitor pattern (#5796)
* feat: Partition implementation of Visitable for InfluxQL AST

* feat: Added consistent structures for each clause to simplify visitor

Continued to expand `accept` and `pre` / `post` visit implementations.

* feat: Added insta and tests using snapshots (thanks @crepererum)

The insta crate simplifies the process of validating the combination of
visitor and accept implementations are called and in the correct order.

* chore: Run cargo hakari tasks

* feat: Added remaining snapshot tests

Some tests are failing as some minor type changes must be added along
with the addition of related visitor functions.

* feat: Add types to represent each clause in numerous statements

These clauses permit distinct visit functions on the `Visitor` type.

* chore: Reformat `SELECT`

* chore: Explicitly specify access to export selected types only

This required completing all the missing documentation for the exported
types.

* chore: Update Cargo.lock

* chore: macro to implement common traits and hide 0th tuple element

Co-authored-by: CircleCI[bot] <circleci@influxdata.com>
2022-10-13 22:37:49 +00:00
Stuart Carnie 9feb27b3b0
feat: Add `SELECT` statement parsing (#5692)
* feat: Identifier → VarRef, which represents a tag or field reference

InfluxQL calls these variables, so the Rust parser will follow
precedent.

* chore: Add docs

* chore: Separate arithmetic and conditional expression parsing

This is necessary to ensure conditional expressions are only supported
in a `WHERE` clause and arithmetic expressions in `SELECT` field
projection list

* feat: Add a `verify` API to transform combinator functions to errors

This is useful to preform additional validation on a valid result.

* feat: Add customisation for operand parsing to arithmetic expressions

This permits narrowing of valid function calls in `WHERE` clauses
and to customise valid operands in a `SELECT` projection, such as a
wildcard (`*`)

* chore: move logic to appropriate modules.

* feat: Add wildcard discriminator to Expr enum required for `SELECT`

* chore: Remove dead_code attribute

* feat: Add `DISTINCT` operator

* chore: Add `distinct` macro; simplify existing macros

* chore: add assert_matches; parse Field and Field list; refactor literal

* feat: Add a new type to parse a separated_list1 into a specialised type

* chore: Refactor types using `separated_list1`

* chore: Ensure items in a list can be preceded by a space

* chore: Refactor IN clause to use OneOrMore

* feat: Parse `GROUP BY` clause

* chore: appease clippy

* chore: refactor number parsing to share code; add signed Number type

* feat: completed `SELECT` statement parser.

* chore: Consistent error messages when expecting tokens

* chore: Add recommended derive implementations

* feat: Add `SELECT` statement to `statement` combinator

* chore: Refactor OneOrMore::separated_list1 to a single error message

* chore: More tests and cleanup 🧹

* chore: More tests

* chore: Appease broken doc links checker

* chore: remove remaining `dead_code` attributes 🥳

* chore: Address PR feedback

* https://github.com/influxdata/influxdb_iox/pull/5692#discussion_r982559420
* https://github.com/influxdata/influxdb_iox/pull/5692#discussion_r982527476

* chore: Address PR feedback

* https://github.com/influxdata/influxdb_iox/pull/5692#discussion_r982626857
* https://github.com/influxdata/influxdb_iox/pull/5692#discussion_r982569760

* chore: Address PR feedback for Display implementations

Also removed duplicate test case
2022-09-29 23:10:18 +00:00
Stuart Carnie b4e5895d7a
feat: Add influxdb_influxql_parser crate (#5415)
* feat: Add crate; parse quoted identifiers

* chore: Run cargo hakari tasks

* chore: satisfy linter

* chore: Use `test_helpers::Result`

* feat: Add all InfluxQL keywords

* chore: Update influxdb_influxql_parser/src/lib.rs

Co-authored-by: Marco Neumann <marco@crepererum.net>

* chore: PR feedback

* chore: PR Feedback, remove Result<()>

* chore: Update Cargo.lock

Co-authored-by: CircleCI[bot] <circleci@influxdata.com>
Co-authored-by: Marco Neumann <marco@crepererum.net>
2022-08-18 23:09:45 +00:00