Commit Graph

6 Commits (a49a0aaa213e49cfc4440ac1cc6c04193b949733)

Author SHA1 Message Date
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 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 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 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