Commit graph

606 commits

Author SHA1 Message Date
Nickolay Ponomarev
d9e044aabb Extend one_statement_parses_to to also test parsing canonical SQL
It was an omission of the original implementation.
2020-10-12 06:52:39 +03:00
Nickolay Ponomarev
4128dfe1db Introduce tests/test_utils/mod.rs and use it consistently
To share helper macros between various tests/* we added a new module
(tests/macros/mod.rs). This made the prologue to be used in tests quite
long and a little weird:
```
#[macro_use]
#[path = "macros/mod.rs"]
mod macros;
use sqlparser::test_utils::*;
```

This simplifies it to:
```
#[macro_use]
mod test_utils;
use test_utils::*;
```
- and switches all existing tests to the new prologue simultaneously...

...while fixing a few other inconsistencies and adding a few comments
about the way `test_utils` work.
2020-10-12 06:52:00 +03:00
Nickolay Ponomarev
99fb633221 Move existing SF tests to sqlparser_snowflake.rs
Co-authored-by: Eyal Leshem <eyal@satoricyber.com>
2020-10-05 08:42:26 +03:00
Nickolay Ponomarev
54be3912a9 Update CHANGELOG 2020-10-05 04:32:46 +03:00
Nickolay Ponomarev
7dc5d4c35e Follow-up to #275: Bump simple_logger version in Cargo.toml
SimpleLogger is private in v1.6. Bumping its version in Cargo.toml makes
`git pull && carg test` use the new version in an existing checkout
(with an existing Cargo.lock file referencing the old version)
2020-10-05 04:32:46 +03:00
Alex Dukhno
1ac208307c
Support IF NOT EXISTS for CREATE SCHEMA (#276)
This is a Postgres-specific clause: https://www.postgresql.org/docs/12/sql-createschema.html

Also add a test for `DROP SCHEMA IF EXISTS schema_name`, which is already supported in the parser.
2020-10-02 17:35:20 +03:00
Alex Dukhno
926b03a31d
Add parsing for PostgreSQL math operators (#267) 2020-09-30 05:29:31 +03:00
Daniël Heres
2f71324c33
Fix deprecated way of initializing SimpleLogger (#275)
* Use builder pattern instead as suggested
2020-09-07 09:34:27 +02:00
Nickolay Ponomarev
cf7263c294 Fix typo in the README
Closes https://github.com/ballista-compute/sqlparser-rs/issues/269
2020-09-07 04:31:07 +03:00
Nickolay Ponomarev
01a2a6bd0c
Update CHANGELOG (#261) 2020-09-07 04:11:26 +03:00
eyalleshem
1c6077c0db
[snowflake] Support single line comments starting with '#' or '//' (#264)
Co-authored-by: Eyal Leshem <eyal@satoricyber.com>
2020-09-07 03:57:37 +03:00
dependabot[bot]
e9aa87fa2c
Update bigdecimal requirement from 0.1 to 0.2 (#268)
Updates the requirements on [bigdecimal](https://github.com/akubera/bigdecimal-rs) to permit the latest version.
- [Release notes](https://github.com/akubera/bigdecimal-rs/releases)
- [Commits](https://github.com/akubera/bigdecimal-rs/compare/v0.1.0...v0.2.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-09-02 13:47:55 +02:00
Daniël Heres
a5b752484e
Fix clippy linting error, use enumerate (#266) 2020-08-27 21:32:06 +02:00
Andy Grove
038ef985a7
Add Ballista to the README as a user of this crate (#262) 2020-08-27 19:42:34 +02:00
Max Countryman
118a345790
Merge pull request #238 from maxcountryman/feature/gh-action-releases
automate crate publishing
2020-08-12 07:04:38 -07:00
eyalleshem
f500a42e99
Add snowflake dialect (#259) 2020-08-12 04:55:22 +03:00
Nickolay Ponomarev
2c6c295dd0
Refactor <column definition> parsing (#251) 2020-08-10 17:19:33 +03:00
Nickolay Ponomarev
66505ebf9e Don't fail parsing a column definition with unexpected tokens
Since PR https://github.com/ballista-compute/sqlparser-rs/pull/93
`parse_column_def` parses a set of column options in a loop, e.g. given:

```
                  _______ column_def _______
CREATE TABLE foo (bar INT NOT NULL DEFAULT 1, )
                          -------- ---------
                          option 1  option 2
````

it parses column options until it encounters one of the delimiter tokens

First when we only supported `CREATE TABLE`, the set of delimiters that
stopped the parsing used to be `Token::Comma | Token::RParen`.

Then we added support for `ALTER TABLE ADD COLUMN <column_def>`. Turns
out the parser started to bail if the statement ended with a semicolon,
while attempting to parse the semicolon as a column option, as we forgot
to add it to the set of delimiter tokens.

This was recently fixed in https://github.com/ballista-compute/sqlparser-rs/pull/246
by including Token::SemiColon to the list, but it felt wrong to have
to update this list, and to have a common list of delimiters for two
different contexts (CREATE TABLE with parens vs ALTER TABLE ADD COLUMN
without parens).

Also our current approach cannot handle multiple statements NOT
separated by a semicolon, as is common in MS SQL DDL. We don't
explicitly support it in `parse_statements`, but that's a use-case
like to keep in mind nevertheless.
2020-08-10 17:12:33 +03:00
Nickolay Ponomarev
23f5c7e7ce Move parse_column_def below parse_columns
...because in the section related to CREATE TABLE parsing, the callers
are defined above the callees.
2020-08-10 17:09:34 +03:00
eyalleshem
1b46e82eec
Enable dialect specific behaviours in the parser (#254)
* Change `Parser { ... }` to store the dialect used:
    `Parser<'a> { ... dialect: &'a dyn Dialect }`

    Thanks to @c7hm4r for the initial version of this submitted as
    part of https://github.com/ballista-compute/sqlparser-rs/pull/170

* Introduce `dialect_of!(parser is SQLiteDialect |  GenericDialect)` helper
    to branch on the dialect's type

* Use the new functionality to make `AUTO_INCREMENT` and `AUTOINCREMENT`
  parsing dialect-dependent.


Co-authored-by: Christoph Müller <pmzqxfmn@runbox.com>
Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
2020-08-10 16:51:59 +03:00
Daniël Heres
3871bbc5ee
Enable dependabot for this repository (#256)
* Enable dependabot for this repository

* Remove duplication, add sqlparser_bench
2020-08-05 09:03:29 +02:00
Daniël Heres
5f3a40e772
Dependency updates (#255) 2020-08-05 09:12:13 +03:00
eyalleshem
61431b087d
Support TABLE functions in FROM (#253)
Support `TABLE(...)` syntax in `FROM`, for example:

    select * from TABLE(SOME_FUNCTION(some_arg))

The ANSI spec allows routine invocations (and some other kinds of expressions we don't currently support) inside TABLE:
https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#PTF-derived-table
https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#table-function-derived-table
2020-08-05 08:59:43 +03:00
Heres, Daniel
a246d5da9a Undo accidental commit 2020-08-04 22:45:26 +02:00
Daniël Heres
caeb046803
Enable dependabot for this repository 2020-08-04 22:44:13 +02:00
eyalleshem
1cc3bf4099
Support named arguments in function invocations (#250)
This commit supports functions with argument names.

the format is :
"Select some_function( a => exp, b => exp2 .. ) FROM table1
OR
"select * from table(function(a => exp)) f;"

see:
https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#named-argument-assignment-token
or the motivating example from snowflake:
https://docs.snowflake.com/en/sql-reference/functions/flatten.html
2020-08-02 08:04:55 +03:00
Max Countryman
9351efb437 update release instructions 2020-08-01 07:30:41 -07:00
Max Countryman
580e4b1d64
Merge pull request #252 from ballista-compute/fixup/use-nightly-fmt
ensure we use nightly with fmt
2020-07-31 09:48:58 -07:00
Max Countryman
6b37c1642f fix typo 2020-07-31 09:34:51 -07:00
Max Countryman
1a70c6e1fe document initial release process 2020-07-31 09:18:34 -07:00
Max Countryman
cac3a8ec1e provide missing license header 2020-07-31 09:01:32 -07:00
Max Countryman
76a911b34e
ensure we use nightly with fmt 2020-07-31 08:56:59 -07:00
mz
9c1a5a781d
Don't fail parsing ALTER TABLE ADD COLUMN ending with a semicolon (#246)
This is a follow-up to https://github.com/ballista-compute/sqlparser-rs/pull/203
where ALTER TABLE ADD COLUMN support was initially implemented.

Fixes #233.
2020-07-31 18:10:53 +03:00
mz
f8feff4ef2
Add SQLite dialect (#248) 2020-07-31 15:09:54 +03:00
mz
4452f9bad1
Support specifying ASC/DESC in index columns (#249)
...by reusing `OrderByExpr` for `columns` in `Statement::CreateIndex`.

This supports SQLite's indexed-column syntax https://www.sqlite.org/syntax/indexed-column.html

MSSQL's (`ON <object> ( column [ ASC | DESC ] [ ,...n ] )`)
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql?view=sql-server-ver15

And most of PostgreSQL syntax (except for opclass):
`( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )`
https://www.postgresql.org/docs/12/sql-createindex.html
2020-07-30 15:37:58 +03:00
mz
9e7e30282e
Support identifiers quoted with backticks in the MySQL dialect (#247)
Per https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
MySQL historically supports `identifiers quoted in backticks`
in addition to the ANSI "quoting style" (assuming ANSI_QUOTES mode).
2020-07-30 04:22:29 +03:00
Nickolay Ponomarev
1337820c06
Merge pull request #245 from nickolay/cleanups
Minor code cleanups
2020-07-29 02:13:16 +03:00
Nickolay Ponomarev
a6e30b3fad Fix typo in JSONFILE serialization
Closes https://github.com/ballista-compute/sqlparser-rs/issues/237
2020-07-29 02:08:17 +03:00
Nickolay Ponomarev
9a2d86dcb5 Change CREATE INDEX serialization to not end with a semicolon 2020-07-29 02:08:17 +03:00
Nickolay Ponomarev
9371652446 Fix "unused stmt" warning in tests, with default features 2020-07-29 02:08:17 +03:00
Nickolay Ponomarev
3e880b599a Use consistent style for Display impls 2020-07-29 02:08:17 +03:00
Nickolay Ponomarev
d0db8a224b Run cargo fmt 2020-07-28 23:36:13 +03:00
mz
09ca14fe8e
Support dialect-specific auto-increment column options for MySQL and SQLite (#234)
In MySQL it's AUTO_INCREMENT
(see https://dev.mysql.com/doc/refman/8.0/en/create-table.html)
and in SQLite it's AUTOINCREMENT.

We use `ColumnOption::DialectSpecific(Vec<Token>)` to avoid adding a new variant for each vendor-specific column option.
2020-07-28 23:34:21 +03:00
Steven
8020b2e5f0
Add Postgres-specific PREPARE, EXECUTE and DEALLOCATE (#243)
Adds top-statements PREPARE, EXECUTE and DEALLOCATE for Postgres-specific feature prepared statement.
2020-07-28 12:01:52 +03:00
Daniël Heres
d2e4340a32
Support create or replace view/table (#239)
* Support create or replace table

* Support create or replace view

* Simplify create or replace table parser

* Add tests for create or replace external table and materialized view

* Formatting

* Address review comments

* Create error if we didn't see a (external) table or (materialized) view afer create or replace
2020-07-27 21:59:08 +02:00
Max Countryman
bc9bfaeb84 automate crate publishing
This introduces a new section of the GitHub Actions workflow which will
publish the crate upon a new tag being pushed. Note that this requires a
new project secret, `CRATES_TOKEN`.
2020-07-25 08:05:34 -07:00
Dandandan
f053383c71 Release 0.6.1 2020-07-20 18:20:08 +02:00
Daniël Heres
3a42b69b89
Release 0.6.0 (#232) 2020-07-20 18:14:46 +02:00
Daniël Heres
583f22b929
Remove PostgreSQL version of assert (#229)
Remove PostgreSQL procedural assert statement. This also simplifies code somewhat.
2020-07-17 13:20:49 +02:00
Daniël Heres
c24b0e01db
Implement ASSERT statement (#226)
As supported by PostgreSQL and BigQuery (with some differences between them)
2020-07-16 17:28:03 +02:00