Commit graph

456 commits

Author SHA1 Message Date
Nickolay Ponomarev
7c153e1ab0 Add changelog 2019-07-06 03:47:24 +03:00
Nikhil Benesch
8cd64e7b94
Merge pull request #128 from andygrove/readme
README: update for recent improvements
2019-07-03 10:30:35 -04:00
Nikhil Benesch
4172b68319
README: update for recent improvements
Remove outdated bits that claim shoddy SQL support and code
structure--we're much better on those fronts now! Also add a few
paragraphs about the current state of SQL compliance, why it's hard to
say anything detailed about SQL compliance, and what our long-term goals
are.
2019-07-03 01:39:14 -04:00
Andy Grove
7a4eb505b3 (cargo-release) start next development iteration 0.4.0 2019-07-01 18:19:02 -06:00
Andy Grove
4f805d6c96 (cargo-release) version 0.4.0 2019-07-01 18:17:47 -06:00
Nikhil Benesch
ed76cd68f8
Merge pull request #124 from vemoo/impl-display
implement fmt::Display instead of ToString
2019-07-01 16:24:53 -04:00
Nickolay Ponomarev
b6538592da
Merge pull request #126 from nickolay/pr/renames-comments
Update comments after the renaming done in PR #105
2019-07-01 04:56:18 +03:00
Nickolay Ponomarev
7d4b488336 Update comments after the renaming done in PR #105 2019-07-01 04:45:08 +03:00
Bernardo
b2b159fed1 implement fmt::Display instead of ToString 2019-06-30 17:32:51 +02:00
Nikhil Benesch
cdba43682f
Merge pull request #123 from benesch/eq
Implement Eq alongside Hash
2019-06-25 17:45:12 -04:00
Jamie Brandon
add898c2bd
Implement Eq alongside Hash
It turns out implementing Hash alone is not very useful, as
std::collection::HashMap keys are required to implement both Hash and
Eq.

Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
2019-06-25 14:14:28 -04:00
Nikhil Benesch
f7199ec99f
Merge pull request #122 from benesch/sqlprefix-missed
Remove "SQL" prefix from "SQLDateTimeField" struct
2019-06-25 14:13:26 -04:00
Nikhil Benesch
106c9f8efb
Remove "SQL" prefix from "SQLDateTimeField" struct
I realized a moment too late that I'd missed a type name in
when removing the "SQL" prefix from types in ac555d7e8. As far as I can
tell, this was the only oversight.
2019-06-25 13:24:31 -04:00
Nikhil Benesch
bafb20746f
Merge pull request #105 from benesch/renames
Remove "SQL" from types (and other renames)
2019-06-25 13:16:13 -04:00
Nikhil Benesch
ac555d7e86
Remove "SQL" prefix from types
The rationale here is the same as the last commit: since this crate
exclusively parses SQL, there's no need to restate that in every type
name. (The prefix seems to be an artifact of this crate's history as a
submodule of Datafusion, where it was useful to explicitly call out
which types were related to SQL parsing.)

This commit has the additional benefit of making all type names
consistent; over type we'd added some types which were not prefixed with
"SQL".
2019-06-25 13:11:11 -04:00
Nikhil Benesch
cf655ad1a6
Remove "sql" prefix from module names
Since this crate only deals with SQL parsing, the modules are understood
to refer to SQL and don't need to restate that explicitly.
2019-06-24 12:56:26 -04:00
Nikhil Benesch
5b23ad1d4c
Merge pull request #119 from andygrove/astnode-expr
Rename ASTNode to Expr
2019-06-19 21:45:49 -04:00
Nickolay Ponomarev
3c401d5e4f
Merge pull request #120 from nickolay/pr/outer-apply
[mssql/oracle] Support CROSS/OUTER APPLY
2019-06-19 13:26:35 +03:00
Nikhil Benesch
646d1e13ca
Rename ASTNode to Expr
The ASTNode enum was confusingly named. In the past, the name made
sense, as the enum contained nearly all of the nodes in the AST, but
over time, pieces have been split into different structs, like
SQLStatement and SQLQuery. The ASTNode enum now contains only contains
expression nodes, so Expr is a better name.

Also rename the UnnamedExpression and ExpressionWithAlias variants
of SQLSelectItem to UnnamedExpr and ExprWithAlias, respectively, to
match the new shorthand for the word "expression".
2019-06-19 00:00:59 -04:00
Nickolay Ponomarev
4294581ded [mssql] Parse CROSS/OUTER APPLY
T-SQL (and Oracle) support non-standard syntax, which is similar in
functionality to LATERAL joins in ANSI and PostgreSQL
<https://blog.jooq.org/tag/lateral-derived-table/>: it allows to use
the columns from the tables defined to the left of `APPLY` in the
"derived tables" (subqueries) to the right of `APPLY`. Unlike ANSI
LATERAL (but like Postgres' implementation), APPLY is also used with
table-valued function calls.

Despite them being similar, we represent "APPLY" joins with
`JoinOperator`s of its own (`CrossApply` and `OuterApply`). Doing
otherwise seemed like it would cause unnecessary confusion, as those
interested in dialect-specific parsing would probably not expect APPLY
being parsed as LATERAL, and those wanting to forbid non-standard SQL
would not be helped by this either.

This also renames existing JoinOperator::Cross -> CrossJoin to avoid
confusion with CrossApply.
2019-06-19 02:45:47 +03:00
Nickolay Ponomarev
0f6bf15258 Fix bad merge in #118 2019-06-19 02:45:47 +03:00
Nikhil Benesch
e6b26330df
Merge pull request #118 from andygrove/outer-join
Don't silently accept naked OUTER JOINS
2019-06-18 13:15:25 -04:00
Nikhil Benesch
2c99635709
Don't silently accept naked OUTER JOINS
`SELECT * FROM a OUTER JOIN b` was previously being parsed as an inner
join where table `a` was aliased to `OUTER`. This is extremely
surprising, as the user likely intended to say FULL OUTER JOIN. Since
the SQL specification lists OUTER as a keyword, we are well within our
rights to return an error here.
2019-06-18 12:03:15 -04:00
Nickolay Ponomarev
7857543749
Merge pull request #116 from nickolay/pr/more-followups
Support HAVING/LIMIT/OFFSET/FETCH without FROM and other follow-ups
2019-06-18 02:58:31 +03:00
Nickolay Ponomarev
a37ba089ec Add a comment about RESERVED_FOR_TABLE_ALIAS to parse_table_and_joins 2019-06-17 10:55:20 +03:00
Nickolay Ponomarev
eb3450dd51 Support HAVING without GROUP BY
...which is weird but allowed:
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#table-expression
https://dba.stackexchange.com/a/57453/15599

Also add a test for GROUP BY .. HAVING
2019-06-17 01:06:32 +03:00
Nickolay Ponomarev
d60bdc0b92 Allow LIMIT/OFFSET/FETCH without FROM
Postgres allows it, as does ANSI SQL per the <query expression> definition:
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#_7_13_query_expression
2019-06-17 00:54:37 +03:00
Nickolay Ponomarev
c1509b36ec Use FETCH_FIRST_TWO_ROWS_ONLY in tests to reduce duplication 2019-06-17 00:49:25 +03:00
Nickolay Ponomarev
f87e8d5158 Don't duplicate all the parse_simple_select assertions in the LIMIT test 2019-06-17 00:39:00 +03:00
Nickolay Ponomarev
3c073a4c34 Use TableAlias in Cte 2019-06-16 21:18:57 +03:00
Nickolay Ponomarev
4f239745bc Update comments now that get_precedence is no more 2019-06-16 21:01:29 +03:00
Nickolay Ponomarev
dc26c4abd5
Merge pull request #115 from nickolay/pr/followups
Doc improvements and follow-ups to the recent PRs
2019-06-15 01:57:52 +03:00
Nikhil Benesch
98a06d6d23
Merge pull request #111 from benesch/join-tweaks
Refine join parsing
2019-06-14 16:45:06 -04:00
Nickolay Ponomarev
535505bb96
Update the error message in parse_query_body 2019-06-14 16:28:53 -04:00
Nikhil Benesch
4ee461bae4
Require that nested joins always have one join
The SQL specification prohibits constructions like

    SELECT * FROM a NATURAL JOIN (b)

where b sits alone inside parentheses. Parentheses in a FROM entry
always introduce either a derived table or a join.
2019-06-14 16:28:52 -04:00
Nikhil Benesch
8bee74277a
Handle derived tables with set operations
This commit adds support for derived tables (i.e., subqueries) that
incorporate set operations, like:

    SELECT * FROM (((SELECT 1) UNION (SELECT 2)) t1 AS NATURAL JOIN t2)

This introduces a bit of complexity around determining whether a left
paren starts a subquery, starts a nested join, or belongs to an
already-started subquery. The details are explained in a comment within
the patch.
2019-06-14 16:28:52 -04:00
Nickolay Ponomarev
5c7ff79e78 Add a test for parsing the NULL literal
(Coveralls notices we didn't have one.)
2019-06-13 11:17:36 +03:00
Nickolay Ponomarev
45c9aa1cc2 Use self.expected() more 2019-06-13 11:15:10 +03:00
Nickolay Ponomarev
f18fbe5cda Remove unused parse_literal_double
`parse_value` handles parsing a non-integer value in expression context,
and we use parse_literal_uint() when expecting a number in other 
contexts (such as `FETCH FIRST ... ROWS`)
2019-06-13 11:11:23 +03:00
Nickolay Ponomarev
7041850b33 Reduce nesting in parse_table_and_joins
This is a follow-up to #109 which moved the handling of Token::Comma
from parse_table_and_joins to the `FROM` parser.
2019-06-13 04:30:14 +03:00
Nickolay Ponomarev
32cf36e64f Add a testcase, which passes thanks to PR #109 2019-06-12 21:04:31 +03:00
Nickolay Ponomarev
6b0a396785 Remove table_key.rs accidentally re-added in PR #79 2019-06-12 21:04:31 +03:00
Nickolay Ponomarev
cfb77912f7 Mention SQLSelectItem::Wildcard in ASTNode::SQLWildcard docs
as a follow-up to https://github.com/andygrove/sqlparser-rs/issues/52
2019-06-12 21:04:31 +03:00
Nickolay Ponomarev
846f2ff1d9 Fix intra_doc_link_resolution_failure in cargo doc
..and other formatting errors.
2019-06-12 21:04:27 +03:00
Nickolay Ponomarev
26fac099b1 Update Value docs 2019-06-12 21:04:23 +03:00
Andy Grove
1998910bfa
Merge pull request #113 from andygrove/revert-78-visitor
Revert "Add an AST visitor"
2019-06-10 21:56:42 -06:00
Andy Grove
b07c7a90f1
Revert "Add an AST visitor" 2019-06-10 21:51:10 -06:00
Andy Grove
7ed6e03880
Merge pull request #78 from benesch/visitor
Add an AST visitor
2019-06-10 21:19:45 -06:00
Nikhil Benesch
f2fda57e36
Merge pull request #112 from benesch/expr-consistency
Improve consistency of binary/unary op nodes
2019-06-10 23:08:33 -04:00
Nikhil Benesch
ae25dce246
Split operators by arity
It is useful downstream to have two separate enums, one for unary
operators and one for binary operators, so that the compiler can check
exhaustiveness. Otherwise downstream consumers need to manually encode
which operators are unary and which operators are binary when matching
on an Operator enum.
2019-06-10 23:03:11 -04:00