Commit Graph

31 Commits (8bb56f6ef5196ad95d01e7624f58726ffb785624)

Author SHA1 Message Date
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
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
Stuart Carnie 5ac80bf4a5
feat: Add mutable visitor to InfluxQL parser crate (#6292)
* feat: Add mutable visitor to InfluxQL parser crate

* chore: Add missing snapshots

* chore: Fix docs

* chore: Fix test visitor
2022-12-02 05:37:41 +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
Stuart Carnie 2604eb935b
chore: identifier parser handles preceding whitespace (#6223)
* fix: `identifier` parser consumes preceding whitespace

* chore: Update module docs

* feat: Add function to identify when an identifier requires quotes

* feat: Add ability to deref OneOrMore to its vector representation

This feature was used as part the InfluxQL logical planner in IOx

* chore: Feedback, prefer slice `[T]` rather than `Vec<T>`
2022-11-25 00:09:26 +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
Stuart Carnie 106d3a76de
feat: Parse InfluxQL line and inline comments (#6076)
* feat: Added single and inline comment combinators

* chore: Add tests for ws0 function

* feat: Add ws1 combinator

* feat: Use ws0 and ws1 combinators to properly handle comments
2022-11-08 22:53:19 +00:00
Stuart Carnie 30c353e9c0
feat: Add parser for `CREATE DATABASE` statement (#6062)
* feat: Add parser for `CREATE DATABASE` statement

* feat: Improved errors and added associated tests
2022-11-08 00:43:29 +00:00
Stuart Carnie f54124102e
fix: InfluxQL parser incompatibilities (#6034)
* fix: Parse regular expressions starting with possible escape sequence

This was failing because the previous combinator, `is_not`, would return
an error if it consumed no input when identifying one of the characters
in its set. This case would then prevent the remainder of the
`regex_literal` parser from identifying and ignoring sequences like "\w"

* fix: Parse microsecond duration literals with correct unit suffix

* fix: Parse a var ref as a 3-part, segmented identifier

Closes #6033

* chore: Address lint warnings

* chore: Additional test cases per feedback
2022-11-03 05:43:16 +00:00
Stuart Carnie 9f8c5856fc
chore: Keep types in their respective modules (#5993)
* chore: Keep types in their respective modules

Also adds required documentation now that the individual modules are
public.

* chore: Fix incomplete docs

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-10-28 10:06:49 +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 5bd6b43666
fix: Correct representation of 3-part measurement name (#5794)
Closes #5662
2022-10-07 00:01:22 +00:00
Stuart Carnie b862ae6476
feat: `EXPLAIN` statement (#5763) 2022-10-03 00:38:35 +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
Dom Dwyer cd4087e00d style: add no todo!() or dbg!() lints
Some crates had theme, some not - lets be consistent and have the
compiler spot dbg!() and todo!() macro calls - they should never be in
prod code!
2022-09-29 13:10:07 +02:00
Stuart Carnie 56df74802c
feat: Add `DELETE` and `DROP MEASUREMENT` statements (#5656)
* chore: Refactor `FROM` clause parser to be generic

This will allow us to use it for `DELETE` statements, which has
a more restrictive requirement, only allowing regular expressions
or single part identifiers.

* feat: Add `DELETE` series statement

* chore: Add test case for insignificant whitespace between operators

NOTE: Added a skipped test until #5663 is implemented

* feat: Add `DROP MEASUREMENT` statement

* chore: Add DropMeasurementStatement struct

* chore: `Statement` enum contains only `Box`ed types

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-09-20 00:51:30 +00:00
Stuart Carnie 5c21c66691
feat: Teach InfluxQL parser how to parse SHOW statements (#5643)
* feat: Add `SHOW DATABASES`

* feat: Add `SHOW RETENTION POLICIES`

* chore: Drive by clean up, use consistent names for functions

* feat: Parse `SHOW TAG KEYS` statement

* chore: drive-by: Ensure parsing succeeds when whitespace omitted

* feat: `SHOW TAG VALUES` statement

* feat: `SHOW FIELD KEYS` statement

* chore: Finish docs

* chore: Add additional docs to `FromMeasurementClause`

NOTE: technically, the EBNF does not match the current implementation,
but will be addressed in #5662
2022-09-19 02:02:32 +00:00
Stuart Carnie e5d8f23fcd
chore: Remove variants from Identifier and BindParameter types (#5642)
* chore: Remove variants from Identifier and BindParameter types

This simplifies usage of these types. Display traits have been updated
to properly quote and escape the output, when necessary.

* chore: Fix docs
2022-09-15 06:52:31 +00:00
Stuart Carnie e6f2a105e5
feat: Improved InfluxQL error messages (#5632)
* chore: Drive by to improve tests and coverage

* chore: Make Error generic, so we can change it

* chore: change visibility

pub(crate) is superfluous, as we are yet to specify
which APIs are public outside the crate in lib.rs

* chore: Introduce crate IResult type

In preparation of adding custom error type

* feat: Initial implementation of custom error type

* chore: Add module docs

* chore: Rename IResult → ParseResult; syntax and expect errors

* chore: ParserResult and error refactoring

* chore: Drive by simplification

* feat: Add custom errors to string parsing

* feat: Added public API to parse a set of statements

* chore: Errors are dyn Display to convey their intent

Errors from the parser are only displayable messages.

* chore: Separate SHOW for improved error handling

By moving SHOW to a separate parser, we can display clearer error
messages when consuming SHOW followed by an unexpected token.

* chore: Docs and cleanup

* chore: Add tests and a specific `ParseError` type

The fields are intentionally not public yet, as we would like clients
of the package to display the message only.

* chore: PR feedback to improve the `ORDER BY` error message
2022-09-15 00:19:03 +00:00
Stuart Carnie bde26e11ab
feat: Teach IOx to parse `SHOW MEASUREMENTS` statement (#5430)
* feat: Add measurement expression and statement terminator combinators

* feat: Begin parsing SHOW MEASUREMENTS statements

* chore: Placate clippy

* feat: parse LIMIT clause

* feat: parse OFFSET clause

* chore: Clippy

* chore: Fix doc comments

* feat: Parse ORDER BY clause

* feat: Parse WHERE clause

* feat: Add Call expression

* chore: Clippy

* feat: parse WITH MEASUREMENT regex; WHERE clause

* chore: Test to validate regex not-equal operator is not supported

* chore: No need to be public

* chore: Remove invalid comment

* chore: PR Feedback – use `tag_no_case`

Also added `cut` to force Err::Failure state, as `ORDER BY` must be
followed by one of the specified rules.
2022-09-06 01:58:41 +00:00
Stuart Carnie d219f93241
feat: Implementation of expression parsing for InfluxQL (#5469)
* feat: Partial implementation of expression parsing for InfluxQL

* chore: Add nom 7.x compatible precedence package

Simplifies definition of operator precedence

* feat: Add BindParameter parser

* feat: Add BindParameter expression type

* feat: Add conditional operators

* chore: Revert "chore: Add nom 7.x compatible precedence package"

This reverts commit e681dd03

* feat: Corrected unary operator precedence

* chore: Rename combinator functions

* chore: Add missing keywords

* feat: Parse regular expression conditions

Also ensure regex's are only accepted for regular expression
conditional expressions.

* chore: Fix bind parameter link

* chore: Fix broken doc link

* chore: Make conditional expression API public

* chore: More test cases

* chore: consistent whitespace handling

* chore: PR Feedback to include additional operator precedence tests
2022-09-02 00:32:57 +00:00
Stuart Carnie 1fb9423f98
feat: Teach IOx how to parse InfluxQL literals (#5460)
* feat: Parse various InfluxQL literals

* feat: Parse regex, refactor single and double quoted string parsing

* chore: Literals do not include sign; those are unary expressions

* chore: Add docs

* chore: Integer literals are unsigned

Add more tests for max values

* chore: Impl Display for Literal; add macro to write escaped strings

Also added Duration type for InfluxQL durations, so they can be properly
formatted when displayed.

The macro uses match to efficiently map a small number of characters
to their escaped equivalent. It also removes a bit of boilerplate.

* chore: Don't tie lifetime of AST elements to source `str`

* feat: Impl From trait for Literal, Regex and Duration

* chore: Derive Copy for Duration

* chore: PR Feedback, use unwrap_err for better output when API fails

* chore: Drive-by cleanup using unwrap_err
2022-08-31 23:44:58 +00:00
Stuart Carnie b08655a952
feat: Parse InfluxQL identifiers (#5425)
* feat: Parse InfluxQL identifiers

Closes #5424

* chore: Add common derive implementations

* feat: Implement fmt::Display trait for Identifier

* feat: Display implementation, nouns for combinator functions

* chore: Update docs

* chore: Double quoted are identifiers, single quoted are literals

Single quoted strings will be parsed in a separate module.
2022-08-25 23:03:12 +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