Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ should_panic_without_expect = "deny"
todo = "deny"

[workspace]
members = ["sqlparser_bench"]
members = ["sqlparser_bench", "sqlparser_v2"]

[features]
default = ["std", "recursive-protection"]
Expand All @@ -60,6 +60,8 @@ recursive-protection = ["std", "recursive"]
json_example = ["serde_json", "serde"]
derive-dialect = ["sqlparser_derive"]
visitor = ["sqlparser_derive"]
# Parse with the v2 parser, returning this crate's AST.
v2 = ["std", "dep:sqlparser_v2"]

[dependencies]
bigdecimal = { version = "0.4.1", features = ["serde"], optional = true }
Expand All @@ -72,6 +74,7 @@ serde = { version = "1.0", default-features = false, features = ["derive", "allo
# https://github.com/rust-lang/cargo/issues/1596
serde_json = { version = "1.0", optional = true }
sqlparser_derive = { version = "0.7.0", path = "derive", optional = true }
sqlparser_v2 = { version = "2.0.0", path = "sqlparser_v2", optional = true }

[dev-dependencies]
simple_logger = "5.0"
Expand Down
6 changes: 5 additions & 1 deletion sqlparser_bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ authors = ["Dandandan <danielheres@gmail.com>"]
edition = "2018"

[dependencies]
sqlparser = { path = "../" }
sqlparser = { path = "../", features = ["v2"] }

[dev-dependencies]
criterion = "0.8"

[[bench]]
name = "sqlparser_bench"
harness = false

[[bench]]
name = "v2_bridge"
harness = false
78 changes: 78 additions & 0 deletions sqlparser_bench/benches/v2_bridge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//! Compares this crate's parser with the v2 parser converted to this crate's AST.

use criterion::{criterion_group, criterion_main, Criterion};
use sqlparser::dialect::PostgreSqlDialect;
use sqlparser::parser::Parser;
use std::hint::black_box;

fn large_statement() -> String {
let list =
|f: &dyn Fn(usize) -> String, sep: &str| (0..1000).map(f).collect::<Vec<_>>().join(sep);
format!(
"SELECT {} FROM {} WHERE {} ORDER BY {}",
list(&|n| format!("FN_{n}(COL_{n})"), ", "),
list(&|n| format!("TABLE_{n}"), " CROSS JOIN "),
list(&|n| format!("COL_{n} = {n}"), " OR "),
list(&|n| format!("COL_{n} DESC"), ", "),
)
}

fn v2_bridge(c: &mut Criterion) {
let dialect = PostgreSqlDialect {};
let queries = [
("select", "SELECT * FROM my_table WHERE 1 = 1".to_string()),
(
"with_select",
"WITH derived AS (SELECT MAX(a) AS max_a, COUNT(b) AS b_num, user_id \
FROM MY_TABLE GROUP BY user_id) \
SELECT * FROM my_table LEFT JOIN derived USING (user_id)"
.to_string(),
),
(
"tpch_q5",
"SELECT n_name, sum(l_extendedprice * (1 - l_discount)) AS revenue \
FROM customer, orders, lineitem, supplier, nation, region \
WHERE c_custkey = o_custkey AND l_orderkey = o_orderkey AND l_suppkey = s_suppkey \
AND c_nationkey = s_nationkey AND s_nationkey = n_nationkey \
AND n_regionkey = r_regionkey AND r_name = 'ASIA' \
AND o_orderdate >= DATE '1994-01-01' AND o_orderdate < DATE '1995-01-01' \
GROUP BY n_name ORDER BY revenue DESC"
.to_string(),
),
("large_statement", large_statement()),
];
let mut group = c.benchmark_group("v2_bridge");
for (name, sql) in &queries {
assert_eq!(
sqlparser::v2::parse_sql(&dialect, sql).unwrap(),
Parser::parse_sql(&dialect, sql).unwrap()
);
group.bench_function(format!("{name}/v1"), |b| {
b.iter(|| Parser::parse_sql(&dialect, black_box(sql)).unwrap())
});
group.bench_function(format!("{name}/v2"), |b| {
b.iter(|| sqlparser::v2::parse_sql(&dialect, black_box(sql)).unwrap())
});
}
group.finish();
}

criterion_group!(benches, v2_bridge);
criterion_main!(benches);
37 changes: 37 additions & 0 deletions sqlparser_v2/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: CI

on:
push:
branches: [main]
pull_request:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --check
- run: cargo clippy --all-targets -- -D warnings
- run: cargo test
- run: cargo test --release
2 changes: 2 additions & 0 deletions sqlparser_v2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
37 changes: 37 additions & 0 deletions sqlparser_v2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
name = "sqlparser_v2"
description = "Extensible SQL Lexer and Parser with composable dialects"
version = "2.0.0"
authors = ["Apache DataFusion <dev@datafusion.apache.org>"]
documentation = "https://docs.rs/sqlparser_v2/"
keywords = ["ansi", "sql", "lexer", "parser"]
repository = "https://github.com/apache/datafusion-sqlparser-rs"
license = "Apache-2.0"
include = [
"src/**/*.rs",
"Cargo.toml",
"LICENSE",
"NOTICE",
]
edition = "2024"

[lib]
name = "sqlparser_v2"
path = "src/lib.rs"
Loading
Loading