Commit graph

321 commits

Author SHA1 Message Date
Nikhil Benesch
b2c93bd969
Enforce clippy and rustfmt in CI 2019-05-31 18:06:51 -04:00
Nickolay Ponomarev
d80f9f3a7a
Merge pull request #80 from benesch/between-expr
Support nested expressions in BETWEEN
2019-05-30 02:37:06 +03:00
Nickolay Ponomarev
646479e56c
Merge pull request #77 from benesch/count-distinct
Support COUNT(DISTINCT x) and similar
2019-05-30 02:35:49 +03:00
Nickolay Ponomarev
86a2fbd8e4
Merge pull request #76 from benesch/select-all
Support SELECT ALL
2019-05-30 02:35:18 +03:00
Nickolay Ponomarev
7a6a66bdc5
Merge pull request #75 from benesch/drop
Support DROP [TABLE|VIEW]
2019-05-30 02:33:33 +03:00
Nickolay Ponomarev
80f594e8d3
Merge pull request #73 from benesch/option-vec
Replace Option<Vec<T>> with Vec<T>
2019-05-30 02:32:35 +03:00
Nickolay Ponomarev
bc1ec47e4b
Merge pull request #72 from benesch/error
Implement std::error::Error for ParserError
2019-05-30 02:32:02 +03:00
Jamie Brandon
72ced4bffe
Support COUNT(DISTINCT x) and similar 2019-05-28 16:59:05 -04:00
Nikhil Benesch
ba21ce9d37
Support nested expressions in BETWEEN
`BETWEEN <thing> AND <thing>` allows <thing> to be any expr that doesn't
contain boolean operators. (Allowing boolean operators would wreak
havoc, because of the repurposing of AND as both a boolean operation
and part of the syntax of BETWEEN.)
2019-05-28 16:42:11 -04:00
Nikhil Benesch
187376e657
Support DROP [TABLE|VIEW]
Co-authored-by: Jamie Brandon <jamie@scattered-thoughts.net>
2019-05-26 19:57:33 -04:00
Nikhil Benesch
373a9265a2
Implement std::error::Error for ParserError 2019-05-26 18:59:43 -04:00
Jamie Brandon
55fc8c5a57
Support SELECT ALL
Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
2019-05-26 18:57:04 -04:00
Nikhil Benesch
5652b4676c
Replace Option<Vec<T>> with Vec<T>
Vectors can already represent the absence of any arguments (i.e., by
being empty), so there is no need to wrap them in an Option.
2019-05-22 11:42:28 -04:00
Nickolay Ponomarev
4f944dd4aa
Merge pull request #71 from benesch/infix
Don't panic when NOT is not followed by an expected keyword
2019-05-22 01:18:23 +03:00
Jamie Brandon
143846d333
Don't panic on weird infix garbage
Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
2019-05-21 11:59:45 -04:00
Nickolay Ponomarev
908082d26f
Merge pull request #63 from nickolay/pr/refactor-keywords
Use smarter macros to avoid duplication in keywords.rs
2019-05-12 01:06:12 +03:00
Nickolay Ponomarev
3d1b73ad1a
Merge pull request #64 from nickolay/pr/collate-cte-ne
Implement COLLATE, optional column list in CTEs, and more
2019-05-12 01:05:27 +03:00
Nickolay Ponomarev
5f3150e39a Add IsOptional enum to use instead of optional: bool
The meaning of `self.parse_parenthesized_column_list(false)?` was not
very obvious.
2019-05-08 03:23:44 +03:00
Nickolay Ponomarev
eeae3af6a3 Change the default serialization of "not equals" operator to <>
`!=` is not standard, though widely supported - https://stackoverflow.com/a/723426/1026
2019-05-06 22:20:29 +03:00
Nickolay Ponomarev
f93e69d1d4 Add parse_parenthesized_column_list to reduce code duplication 2019-05-06 22:20:29 +03:00
Nickolay Ponomarev
cccf7f0d8e Parse an optional column list after a CTE 2019-05-06 22:20:29 +03:00
Nickolay Ponomarev
f859c9b80e Support COLLATE in expressions
Roughly the <character factor> production - https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#character-factor

If an expression is followed by the keyword `COLLATE`, it must be
followed by the collation name, which is optionally schema-qualified
identifier.

The `COLLATE` keyword is not a regular binary operator in that it can't
be "nested": `foo COLLATE bar COLLATE baz` is not valid. If you prefer
to think of it as an operator, you might say it has the highest
precedence (judging from the spec), i.e. it binds to the smallest valid
expression to the left of it (so in `foo < bar COLLATE c`, the COLLATE
is applied first).
2019-05-06 22:20:29 +03:00
Nickolay Ponomarev
e7949d493c Reduce indentation in parse_prefix() 2019-05-06 22:20:29 +03:00
Nickolay Ponomarev
f82dc74e38 Mention that we use rustfmt for code formatting
...and add a `rustfmt.toml` as advised in https://www.reddit.com/r/rust/comments/9jl6a9/pro_tip_if_you_use_cargo_fmtrustfmt_use_a/
2019-05-06 22:20:29 +03:00
Andy Grove
037c6dab93
Merge pull request #61 from nickolay/pr/revamp-tests
Reorganize tests, remove datetime code, and add basic MSSQL dialect
2019-05-06 07:17:19 -06:00
Nickolay Ponomarev
ed20b8dde8 Use smarter macros to avoid duplication in keywords.rs 2019-05-04 16:58:58 +03:00
Nickolay Ponomarev
67cc880fd1 Add comments to the test files 2019-05-04 02:43:00 +03:00
Nickolay Ponomarev
304710d59a Add MSSQL dialect and fix up the postgres' identifier rules
The `@@version` test is MS' dialect of SQL, it seems, so test it with
its own dialect.

Update the rules for identifiers in Postresql dialect per documentation,
while we're at it. The current identifier rules in Postgresql dialect
were introduced in this commit - as a copy of generic rules, it seems:
810cd8e6cf (diff-2808df0fba0aed85f9d35c167bd6a5f1L138)
2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
5047f2c02e Remove the ansi-specific test file and update PG tests
- The ANSI dialect is now tested in `sqlparser_common.rs`
- Some PG testcases are also parsed by the generic dialect successfully,
  so test that.
2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
1347ca0825 Move the rest of tests not specific to PG from the sqlparser_postgres.rs 2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
478dbe940d Factor test helpers into a common module
Also run "generic" tests with all dialects (`parse_select_version`
doesn't work with ANSI dialect, so I moved it to the postgres file
temporarily)
2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
de177f107c Remove dead datetime-related code
1) Removed unused date/time parsing methods from `Parser`

I don't see how the token-based parsing code would ever be used: the
date/time literals are usually quoted, like `DATE 'yyyy-mm-dd'` or
simply `'YYYYMMDD'`, so the date will be a single token.

2) Removed unused date/time related variants from `Value` and the
dependency on `chrono`.

We don't support parsing date/time literals at the moment and when we
do I think we should store the exact String to let the consumer parse
it as they see fit.

3) Removed `parse_timestamps_example` and
`parse_timestamps_with_millis_example` tests. They parsed as
`number(2016) minus number(02) minus number(15) <END OF EXPRESSION>`
(leaving the time part unparsed) as it makes no sense to try parsing
a yyyy-mm-dd value as an SQL expression.
2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
9297ffbe18 Move tests using standard SQL from the postgresql-specific file 2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
d1b088bd43 Switch remaining tests to the standard format 2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
0233604f9b Remove extraneous tests
`parse_example_value` parses as compound identifier, which makes no
sense ("SARAH"."LEWISE@sakilacustomer"."org")

`parse_function_now` is unnecessary since we already test the parsing
of functions in `parse_scalar_function_in_projection`
2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
fe635350f0 Improve INSERT tests
De-duplicate and check for specific error in `parse_insert_invalid`.
2019-05-04 01:00:13 +03:00
Nickolay Ponomarev
d58bbb8f9f Update doc comments
(The `SQLBetween` change is to fix a `cargo doc` warning.)
2019-05-02 21:30:32 +03:00
Andy Grove
4b27db0bf9
Merge pull request #59 from nickolay/next
Cleanups, and support `CASE operand`, TVFs and MSSQL-specific WITH hints
2019-04-27 15:13:47 -06:00
Nickolay Ponomarev
364f62f333 Parse table-valued functions and MSSQL-specific WITH hints
1) Table-valued functions (`FROM possibly_qualified.fn(arg1, ...)`) is
not part of ANSI SQL, but is supported in Postgres and MSSQL at least:
- "38.5.7. SQL Functions as Table Sources" <https://www.postgresql.org/docs/current/xfunc-sql.html#XFUNC-SQL-TABLE-FUNCTIONS>
- `user_defined_function` in "FROM (Transact-SQL)" <https://docs.microsoft.com/en-us/sql/t-sql/queries/from-transact-sql?view=sql-server-2017>

I've considered renaming TableFactor::Table to something else (Object?),
now that it can be a TVF, but couldn't come up with a satisfactory name.

2) "WITH hints" is MSSQL-specific syntax
<https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-2017>

Note that MSSQL supports the following ways of specifying hints, which
are parsed with varying degrees of accuracy:
- `FROM tab (NOLOCK)` -- deprecated syntax, parsed as a function with a `NOLOCK` argument
- `FROM tab C (NOLOCK)` -- deprecated syntax, rejected ATM
- `FROM TAB C WITH (NOLOCK)` -- OK
2019-04-27 21:14:18 +03:00
Nickolay Ponomarev
e5e3d71354 Support CASE operand WHEN expected_value THEN ..
Another part of #15
2019-04-27 21:14:18 +03:00
Nickolay Ponomarev
2aa4c267e7 Simplify CASE parsing 2019-04-27 21:14:18 +03:00
Nickolay Ponomarev
e5c0c426b7 Simplify parse_infix()
- ASTNode::SQLBinaryExpr is now constructed in one location
- There's no duplicate calls to parse_in/parse_between
- The list of tokens that correspond to operators is not duplicated
  in parse_infix / to_sql_operator
- ...which made it easy to distinguish between errors that could be
  caused by invalid input and internal errors. I switched the latter
  to `panic!()`
2019-04-27 21:14:18 +03:00
Nickolay Ponomarev
d65274bc31 Improve ALTER error messages for unsupported syntax 2019-04-27 21:14:18 +03:00
Nickolay Ponomarev
787cd9a717 Add Parser::expected() for more succinct error handling 2019-04-27 21:14:18 +03:00
Nickolay Ponomarev
c679c7a5b4 Remove Value::Uuid
We don't have the code to parse UUID literals, so it's dead code, that
brings in the dependency on `uuid`.

I kept SQLType::Uuid, as it's not dead code, though it ought to be
dialect-specific.
2019-04-27 21:14:18 +03:00
Nickolay Ponomarev
6bb2acc9f8
Merge pull request #50 from nickolay/window-functions
Support OVER clause for window/analytic functions, add support for qualified function names
2019-04-27 21:12:08 +03:00
Andy Grove
64b1ea7a25
Merge pull request #54 from nickolay/windows-newlines
Support \r and \r\n line breaks in tokenizer
2019-04-27 08:54:20 -06:00
Andy Grove
07d66a93ef
Merge pull request #53 from thomas-jeepe/master
Fix qualified wildcard stringifying
2019-04-27 08:53:08 -06:00
Andy Grove
4cdd003cd4
Merge pull request #51 from nickolay/rust-2018
Rust 2018 and clippy fixes
2019-04-27 08:51:43 -06:00
Nickolay Ponomarev
bf3110f6ce Use consume_and_return when possible 2019-04-27 02:51:10 +03:00