Commit Graph

76 Commits (fad34c375ef2cc9abda28713b2cf8d0675dc0d2d)

Author SHA1 Message Date
Stuart Carnie 3de03d02c5
chore: clippy 😬 2023-06-06 16:40:34 +10:00
Stuart Carnie b9d064135a
chore: clippy 🧠 2023-06-06 16:04:16 +10:00
Stuart Carnie 73b29c1fed
chore: add API for returning an intersection with another time range 2023-06-06 15:29:27 +10:00
Stuart Carnie 8c71f30145
chore: Don't wrap `TimeRange` in an `Option`
It is unnecessary, because both the lower and upper are already
optional values.
2023-06-06 15:07:47 +10:00
Stuart Carnie 17156c4a4b
feat: Add operator APIs to build binary conditional expressions 2023-06-06 09:59:58 +10:00
Stuart Carnie d8c2f2c679
refactor: Simplify `TimeRange` to match InfluxQL OG behaviour explicitly 2023-06-05 15:14:13 +10:00
Stuart Carnie 271d807988
chore: oops 2023-06-02 13:44:13 +10:00
Stuart Carnie 45e3351665
feat: InfluxQL can split time range predicates from a `WhereClause` 2023-06-02 13:39:34 +10:00
Stuart Carnie bf4fce3c77
feat: Implement `LiteralExpr` for `bool` 2023-06-02 13:38:37 +10:00
Stuart Carnie d5719f9be2
refactor: Moved simplification of time range expressions to parser 2023-06-02 09:50:01 +10:00
Dom Dwyer 928a4d163e
build: remove unused dependencies from crates
This commit fixes loads of crates (47!) had unused dependencies, or
mis-configured dependencies (test deps as normal deps).

I added the "unused_crate_dependencies" to all crates to help prevent
this mess from growing again!

    https://doc.rust-lang.org/beta/nightly-rustc/rustc_lint_defs/builtin/static.UNUSED_CRATE_DEPENDENCIES.html

This has the minor downside of false-positives when specifying
dev-dependencies for test/bench binaries - these are files in /test or
/benches (not normal tests). This commit includes a workaround,
importing them in lib.rs (gated by a feature flag). I think the
trade-off of better dependency management is worth it!
2023-05-23 14:55:43 +02:00
Stuart Carnie e88d8befdb
Merge branch 'main' into sgc/issue/7794_subquery_inconsistency 2023-05-19 18:45:58 +10:00
Andrew Lamb 6344fe8c3f
chore: Add rationale for `clippy::future_not_send` (#7822)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-05-18 16:58:56 +00:00
Stuart Carnie c506ee5946
chore: Add test to validate `as_str` returns unquoted identifier 2023-05-17 14:31:01 +10:00
Stuart Carnie 76aa1ac3d6
feat: Refactor node used to represent a tag in a `GROUP BY`
* Use `VarRef` for `Tag`, to ensure a consistent representation of a
  column reference across `GROUP BY`, `SELECT` projection and `WHERE`
  clause.
* Rename `tags` to `tag_names`
* `tags` now returns `VarRef`
2023-05-17 12:29:02 +10:00
Stuart Carnie 09835e5a98
feat: Implement Hash 2023-05-17 11:20:07 +10:00
Stuart Carnie 5c931fa92c
feat: Add explicit lifetimes 2023-05-17 11:17:57 +10:00
Stuart Carnie a06419726b
feat: Add API to parse an InfluxQL field for testing 2023-05-10 11:21:34 +10:00
Stuart Carnie 455c78966c
chore: Remove unused API 2023-05-05 16:15:22 +10:00
Stuart Carnie e7d6819602
chore: Correct docs 2023-05-05 12:25:58 +10:00
Stuart Carnie ccacd7e78e
chore: Fix doc 2023-05-04 18:25:19 +10:00
Stuart Carnie 24378bd460
chore: `time` is always present and at first position of projection 2023-05-03 07:47:14 +10:00
Stuart Carnie b33b56d76a
Merge branch 'main' into sgc/issue/subquery_6891_02 2023-04-28 06:14:42 +10:00
Dom Dwyer 70420d1c47
chore: fmt 2023-04-27 13:19:05 +02:00
Stuart Carnie c89250ff20
feat: Add `take` and `replace` API to allow ownership transfer
This can reduce allocations, as it allows us to mutate the inner vector
2023-04-27 08:05:09 +10:00
Stuart Carnie 06bc2d6272
feat: Add `pre` and `post` visit events for `Literal` (#7629) 2023-04-24 21:15:44 +00:00
Christopher M. Wolff 2d592a0295
feat: teach parser to allow arithmetic functions (#7620)
* feat: teach parser to allow arithmetic functions

* refactor: remove unnecessary lowercasing of fn names

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-04-24 17:09:22 +00:00
Stuart Carnie 5987bc1ea2
feat: Like `Option`, add `take` API to allow ownership transfer
This will be useful when mutably walking an expression tree and reusing
existing allocations.
2023-04-18 16:46:04 +10:00
Stuart Carnie 772b79b86b
feat: Validate the semantics of the projection clause of a SELECT (#7500)
* feat: Validate the semantics of the projection clause of a SELECT

Closes #7499

* chore: Complete sentences are helpful 😂
2023-04-11 22:43:23 +00: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
Stuart Carnie c82674e88d
fix: Parse empty single-line comments (#7312) 2023-03-23 20:22:49 +00:00
Stuart Carnie 08ef689d21
feat: Teach InfluxQL how to plan an aggregate query (#7230)
* feat: Display failed query

Allows a user to immediately identify the failed query.

* feat: API improvements to InfluxQL parser

* feat: Extend `SchemaProvider` trait to query for UDFs

* fix: We don't want the parser to panic on overflows

* fix: ensure `map_type` maps the timestamp data type

* feat: API to map a InfluxQL duration expression to a DataFusion interval

* chore: Copied APIs from DataFusion SQL planner

These APIs are private but useful for InfluxQL planning.

* feat: Initial aggregate query support

* feat: Add an API to fetch a field by name

* chore: Fixes to handling NULLs in aggregates

* chore: Add ability to test expected failures for InfluxQL

* chore: appease rustfmt and clippy 😬

* chore: produce same error as InfluxQL

* chore: appease clippy

* chore: Improve docs

* chore: Simplify aggregate and raw planning

* feat: Add support for GROUP BY TIME(stride, offset)

* chore: Update docs

* chore: remove redundant `is_empty` check

Co-authored-by: Christopher M. Wolff <chris.wolff@influxdata.com>

* chore: PR feedback to clarify purpose of function

* chore: The series_sort can't be empty, as `time` is always added

This was originally intended as an optimisation when executing an
aggregate query that did not group by time or tags, as it will produce
N rows, where N is the number of measurements queried.

* chore: update comment for clarity

---------

Co-authored-by: Christopher M. Wolff <chris.wolff@influxdata.com>
2023-03-23 01:13:15 +00:00
Stuart Carnie 2b74f07fe5
feat: Support `GROUP BY` with tags in raw `SELECT` queries (#7109)
* chore: Normalise name of Call expression to lowercase

Simplifies matching functions in planner, as they are guaranteed to be
lowercase.

This also ensures compatibility with InfluxQL when generating column
alias names, which are reflected in updated tests.

* chore: Ensure aggregate functions fail gracefully.

* feat: GROUP BY tag support

* feat: Ensure schema-level metadata is propagated

Requires: https://github.com/apache/arrow-rs/issues/3779

* chore: Add some tests to validate GROUP BY output

* chore: Add clarifying comment

* chore: Declare message in flight.proto

The metadata is public API, so best practice is to encode this in a way
that is most compatible for clients in other languages, and will also
document the history of schema changes.

Added tests to validate the metadata is encoded correctly.

* chore: Placate linters

* chore: Use correct column in test cases

* chore: Add `is_projected` to the TagKeyColumn message

`is_projected` is necessary to inform a client whether it should include
the tag key is used exclusively for the group key (false) or also
projected in the `SELECT` column list.

* refactor: Move constants to `schema` crate per PR feedback

* chore: rustfmt 🙄

* chore: Update docs for InfluxQlMetadata

Co-authored-by: Andrew Lamb <alamb@influxdata.com>

---------

Co-authored-by: Andrew Lamb <alamb@influxdata.com>
2023-03-07 22:40:23 +00:00
Carol (Nichols || Goulding) faae5eb438 chore: Rerun cargo hakari manage-deps 2023-02-27 11:56:15 +01:00
Stuart Carnie 929ac9081e
feat: Rewrite logical expression to match InfluxQL behaviour (#7031)
* chore: Move to inline snapshots

* chore: Container for the DataFusion and IOx schema

* chore: Simplify using logical expression helper functions

* feat: Rewrite conditional expressions using InfluxQL rules

* feat: Add tests to validation conditional expression rewriting

* feat: Rewrite column expressions

* chore: Rewrite expression to use false when possible

This allows the planner to optimise away the entire logical plan to an
empty plan in many cases.

* feat: Complete cast postfix operator support

Added `unsigned` postfix operator, as the feature was mostly complete.

Closes #6895

* chore: Remove redundant attribute
2023-02-21 20:01:31 +00: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 969319dfd3
fix: Allow all valid characters following a keyword (#6959)
* fix: Allow all valid characters following a keyword

Closes #6382

* chore: Identified additional test cases
2023-02-13 22:21:11 +00:00
Carol (Nichols || Goulding) 30fea67701
fix: Move variables within format strings. Thanks clippy!
Changes made automatically using `cargo clippy --fix`.
2023-02-03 13:06:17 -05: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
Stuart Carnie 81ffb3edb5
chore: move walk and the mutable variant to the parser crate (#6575)
It is generally a useful API to be core to the InfluxQL parser crate.
2023-01-12 21:06:06 +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
Stuart Carnie aacd91db94
feat: Teach InfluxQL rewriter how to name columns (#6481)
* feat: Add timestamp data type

* feat: Add with_quiet API to suppress output to STDOUT

* fix: Field name resolution to match InfluxQL

* refactor: Allow TestChunks to be directly accessed

This will be useful when testing the InfluxQL planner.

* fix: Add Timestamp case to var_ref module

* feat: Add InfluxQL compatible column naming

* chore: Add doc comment.

* fix: keywords may be followed by a `!` such as `!=`

* fix: field_name improvements

* No longer clones expressions
* Explicitly handle all Expr enumerated items
* more tests

* fix: collision with explicitly aliased column

Fixes case where column is explicitly aliased to an auto-named variant.
Test case added to validate.
2023-01-04 00:55:18 +00:00
Stuart Carnie 4add55d39e
feat: InfluxQL planner learns how to normalise InfluxQL AST (#6236)
* chore: Move logic to context, in line with DataFusion SQL

* chore: Add ordering for InfluxQL data types

Ordering is used to determine automatic casting operations. If two
field columns are present in an expression, one float and one integer,
the integer should be cast to a float, such that the final expression
will be a float.

* chore: Add DerefMut trait to collection types

Will allow these collections to be mutated when traversing the InfluxQL
AST.

* chore: Add influxql module with initial AST normalisation implementation

* chore: Add more unit tests and docs

* chore: Run cargo hakari tasks

* chore: Fix link

* chore: Support regular expression expansion and Call expressions

* chore: Add tests for walk_expr functions

* chore: Add insta snapshot files

* chore: Add docs and make API accessible to the crate

* chore: Move to Arc<dyn SchemaProvider> for use in influxql planner

* chore: Move code back; it is better encapsulated here

* chore: Remove redundant attribute

* chore: Improve regex compatibility with InfluxQL / Go

* chore: Style improvement.

Co-authored-by: CircleCI[bot] <circleci@influxdata.com>
2023-01-02 23:48:21 +00:00
Carol (Nichols || Goulding) 46ff8854ec
fix: Use code backticks around invalid HTML tags in doc strings 2022-12-21 16:36:17 -05:00
Stuart Carnie f56b834438
chore: Implemented ZeroOrMore item container (#6373)
* chore: Implemented ZeroOrMore item container

Closes #6372

* chore: Use canonical names based on feedback
2022-12-12 22:01:30 +00:00