Commit graph

386 commits

Author SHA1 Message Date
Nikhil Benesch
ccbd048dda
Test that redundant nesting is supported
SELECT * FROM (((SELECT 1))) is just as valid as
SELECT * FROM (SELECT 1). Add a test to ensure that we can parse the
first form.

Addresses a comment from #100.
2019-06-07 23:54:56 -04:00
Nikhil Benesch
5f9f17de8a
Merge pull request #100 from benesch/nested-joins
Support nested joins
2019-06-07 22:37:53 -04:00
Nikhil Benesch
fc5e662b91
Merge pull request #107 from benesch/prec
Fix precedence of unary NOT
2019-06-06 17:26:00 -04:00
Nikhil Benesch
525f4d7501
Fix precedence of unary NOT
get_next_precedence deals with left-binding power, not right binding
power. Therefore, when it encounters a standalone NOT operator (i.e., a
"NOT" token that is not followed by "BETWEEN", "LIKE", or "IN"), it
should return 0, because unary NOT is not an infix operator, it's a
prefix operator, and therefore it has no left-binding power.
2019-06-06 17:20:07 -04:00
Nikhil Benesch
8fbf82deb0
Support nested joins
Fix #83.
2019-06-04 10:25:07 -04:00
Nikhil Benesch
1f87083906
Merge pull request #99 from benesch/dates
Basic date/time support
2019-06-04 00:30:21 -04:00
Nikhil Benesch
ed3ed26bb1
Support parsing dates, times, and timestamps as strings 2019-06-04 00:12:09 -04:00
Nikhil Benesch
11fc833433
Merge pull request #96 from benesch/extract
Support EXTRACT function-like operator
2019-06-04 00:07:23 -04:00
Nikhil Benesch
4c2722280d
Merge pull request #98 from benesch/col-names
Support column names in more places
2019-06-04 00:00:07 -04:00
Nikhil Benesch
9abcac350e
Support aliasing columns
A table alias can specify new names for the columns within the aliased
table, in addition to a new name for the table itself.
2019-06-03 23:51:23 -04:00
Nikhil Benesch
73ed685879
Support views with explicit column names
A `CREATE VIEW` statement may provide names for its columns that
override the names of the columns derived from the view's query.
2019-06-03 23:50:23 -04:00
Nikhil Benesch
fdbf64c64d
Merge pull request #94 from benesch/empty-create-table
Support CREATE TABLE with no columns
2019-06-03 23:44:18 -04:00
Nikhil Benesch
d484756182
Support EXTRACT function-like operator
The EXTRACT function, for extracting components of a date from a
timestamp, has special syntax: `EXTRACT(<field> FROM <timestamp>)`.
2019-06-03 23:37:39 -04:00
Nikhil Benesch
2f4cd8f6c8
Merge pull request #102 from benesch/ci-speedup
Speed up CI
2019-06-03 23:34:39 -04:00
Nikhil Benesch
a594375966
Merge pull request #97 from benesch/update
Support UPDATE statements
2019-06-03 23:32:23 -04:00
Nikhil Benesch
610d6f8304
Improve CI caching
We weren't making very effective use of the cache before, leading to
10m+ builds, as `cargo install --force` always busts the cache.
2019-06-03 17:46:20 -04:00
Nikhil Benesch
e753bd4f90
Install kcov via APT
This prevents cargo coveralls from downloading it and compiling it on
the fly.
2019-06-03 17:36:35 -04:00
Nikhil Benesch
b7125c979a
Upgrade CI to Xenial
This isn't required by anything, but newer distributions tend to boot
faster in Travis.
2019-06-03 17:33:44 -04:00
Nikhil Benesch
6fceba8aa1
Merge pull request #74 from benesch/with-options
Support arbitrary WITH options for CREATE [TABLE|VIEW]
2019-06-03 13:57:38 -04:00
Nikhil Benesch
69f0082db6
Support arbitrary WITH options for CREATE [TABLE|VIEW]
Both Postgres and MSSQL accept this syntax, though the particular
options they accept differ.
2019-06-03 13:32:13 -04:00
Nikhil Benesch
1931c76eb8
Merge pull request #101 from benesch/merge-skew
Fix merge skew by implementing Hash for SQLValues
2019-06-03 12:28:49 -04:00
Nikhil Benesch
fa3cf732d5
Fix merge skew by implementing Hash for SQLValues 2019-06-03 12:08:06 -04:00
Nikhil Benesch
b12fb34f3d
Merge pull request #95 from benesch/hex-literals
Support hexadecimal string literals
2019-06-03 11:49:25 -04:00
Nikhil Benesch
b8ba188191
Merge pull request #91 from benesch/from-values
Improve VALUES-related syntax parsing
2019-06-03 11:44:52 -04:00
Nikhil Benesch
eba3983268
Support hexadecimal string literals 2019-06-03 11:33:51 -04:00
Nikhil Benesch
057518b377
Merge pull request #88 from benesch/hash
Implement Hash on all AST nodes
2019-06-03 11:29:31 -04:00
Nikhil Benesch
7aff70772b
Merge pull request #90 from benesch/exists
Support EXISTS subqueries
2019-06-03 11:29:04 -04:00
Nikhil Benesch
14e07ebdda
Support arbitrary INSERT sources
INSERT takes arbitrary queries as sources, not just VALUES clauses. For
example, `INSERT INTO foo SELECT * FROM bar` is perfectly valid.
2019-06-03 11:27:21 -04:00
Nikhil Benesch
9420070a0d
Support VALUES clauses in FROM
VALUES clauses are not just valid in INSERT statements. They're also
valid (basically) anywhere table expressions are accepted, like in FROM
clauses.
2019-06-03 11:26:45 -04:00
Nikhil Benesch
975106b207
Support EXISTS subqueries
Fix #5.
2019-06-03 11:14:24 -04:00
Nikhil Benesch
c49352f394
Implement Hash on all AST nodes
It is convenient for downstream libraries to be able to stash bits of
ASTs into hash maps, e.g., for performing simple common subexpression
elimination.

The only downside to this change is that it requires that the f64 in the
Value enum be wrapped in an OrderedFloat, which provides the necessary
equality semantics to allow Hash to be drived. The reason f64 doesn't
implement Hash by default is because NaN is typically not equal to
itself, so it's not clear what it should hash to. That's less of a
concern in a SQL context, because every SQL database I've looked at
treats NaN as equal to itself, in violation of the IEEE standard, in
order to permit indexing and sorting of float columns.
2019-06-03 11:11:24 -04:00
Nikhil Benesch
a3aaa49a7e
Merge pull request #89 from benesch/sqlfunction-struct
Extract a SQLFunction struct
2019-06-03 11:09:27 -04:00
Nikhil Benesch
1ddef7aa71
Merge pull request #92 from benesch/decimal-dec
Parse DECIMAL and DEC aliases for NUMERIC type
2019-06-03 11:08:18 -04:00
Nikhil Benesch
85ba953ea1
Merge pull request #87 from nickolay/pr/join-refactor
Refactor parse_joins
2019-06-03 00:55:23 -04:00
Nikhil Benesch
1cef68e510
Support UPDATE statements
Fix #10.
2019-06-03 00:21:23 -04:00
Nikhil Benesch
b3a2a6be48
Support CREATE TABLE with no columns
This is weird, but supported by PostgreSQL.
2019-06-02 23:50:16 -04:00
Nikhil Benesch
054a59df12
Extract a SQLFunction struct
This variant is getting rather large, and it's useful downstream to be
able to pass around SQLFunction nodes without reinventing the wheel.
2019-06-02 23:00:28 -04:00
Nikhil Benesch
38fc920d7c
Parse DECIMAL and DEC aliases for NUMERIC type 2019-06-02 22:40:18 -04:00
Nickolay Ponomarev
d0f2de06ed Refactor parse_joins, pt.2: implicit/cross/natural joins
- reduce duplication in the handling of implicit/cross joins and make
  the flow of data slightly clearer by returning the `join` instead of
  pushing it and exiting early.

  (I wanted the block that currently returns `join` to return one of
  JoinOperator::* tags, so that `parse_table_factor` and the construction
  of the `Join` struct could happen after we've parsed the JOIN keywords,
  but that seems impossible.)

- move the check for the NATURAL keyword into the block that deals with 
  INNER/OUTER joins that support constraints (and thus can be preceded
  by "NATURAL")

- add a check for NATURAL not followed by a known join type with a test

- add more tests for NATURAL joins (we didn't have any), and fix
  whitespace bug in `to_string()` that was uncovered (we emitted an
  extra space: `foo NATURAL JOIN bar `)
2019-06-03 02:44:03 +03:00
Nickolay Ponomarev
665b9df729 Refactor parse_joins, pt.1: INNER/OUTER joins
This block parses one of:
- `[ INNER ] JOIN <table_factor> <join_constraint>`
- `{ LEFT | RIGHT | FULL } [ OUTER ] JOIN <table_factor> <join_constraint>`

..but it was hard to see because of the duplication.
2019-06-03 02:44:03 +03:00
Nickolay Ponomarev
8206523416 Minor consume_token()-related simplifications
- use `if !self.consume_token(&Token::Comma) { break; }` to consume the
  comma and exit the loop if no comma found.
- coalesce two `{ false }` blocks in `consume_token` by using a match guard
2019-06-03 02:44:03 +03:00
Nickolay Ponomarev
2308c1c6f7
Merge pull request #86 from nickolay/pr/token-refactor
Internal improvements to Parser::next_token/prev_token

This reduces the number of helper functions used by next_token()/prev_token() while slightly improving performance and reducing the chances of coding errors when using prev_token() after hitting end-of-file.
2019-06-03 02:42:59 +03:00
Nickolay Ponomarev
e02625719e Allow calling prev_token() after EOF
Before this `next_token()` would only increment the index when returning
`Some(token)`. This means that the caller wishing to rewind must be
careful not to call `prev_token()` on EOF (`None`), while not forgetting
to call it for `Some`. Not doing this resulted in bugs in the
undertested code that does error handling.

After making this mistake several times, I'm changing `next_token()` /
`prev_token()` so that calling `next_token(); prev_token(); next_token()`
returns the same token in the first and the last invocation.
2019-06-02 22:57:44 +03:00
Nickolay Ponomarev
1227fddd48 Reduce cloning of tokens
- Avoid cloning whitespace tokens in `peek_nth_token()` by using a
  &Token from `tokens.get()` instead of a cloned `Token` from `token_at()`

- Similarly avoid cloning in `next_token_no_skip`, and clone the
  non-whitespace tokens in `next_token` instead.

- Remove `token_at`, which was only used in `peek_token` and
  `peek_nth_token`

- Fold `prev_token_no_skip()` into `prev_token()` and make `prev_token`
  return nothing, as the return value isn't used anyway.
2019-06-02 22:57:44 +03:00
Nickolay Ponomarev
ebb82b8c8f
Merge pull request #65 from nickolay/pr/ddl-improvements
* Rewrite parsing of `ALTER TABLE ADD CONSTRAINT`
* Support constraints in CREATE TABLE
* Change `Value::Long()` to be unsigned, use u64 consistently
* Allow trailing comma in CREATE TABLE
2019-06-02 20:53:21 +03:00
Nikhil Benesch
5847a16fff
Merge pull request #85 from benesch/clippy
Enable Clippy and rustfmt in CI
2019-06-02 10:51:28 -04:00
Nikhil Benesch
1cc9d2d6f5
Merge pull request #82 from benesch/not-prec
Fix the precedence of NOT LIKE
2019-06-02 10:49:49 -04:00
Nickolay Ponomarev
58420cab61
Merge pull request #66 from nickolay/pr/ms-identifiers-aliases
Support for MSSQL identifier and alias parsing rules
2019-06-02 14:19:51 +03:00
Nickolay Ponomarev
d9edc2588b Change Value::Long() to u64, use u64 instead of usize
The tokenizer emits a separate Token for +/- signs, so the value of
Value::Long() (as well as of parse_literal_int()) may never be negative.

Also we have been using both u64 and usize to represent a parsed
unsigned number. Change to using u64 for consistency.
2019-06-02 13:58:14 +03:00
Nickolay Ponomarev
0407ed2b57 Allow trailing comma in CREATE TABLE
At least MSSQL supports it, not sure about others.
2019-06-02 13:54:16 +03:00