Skip to content

Commit 236181f

Browse files
mvzinkMohamedAbdeen-rs
authored andcommitted
readyset-sql-parsing: Wrap expression subparser
This allows tests which directly use the expression subparser to parse with both sqlparser-rs and nom-sql to verify parity. Change-Id: I91402127c9e2aa80f0037180ab2514f543214fd2 Reviewed-on: https://gerrit.readyset.name/c/readyset/+/9102 Tested-by: Buildkite CI Reviewed-by: Michael Zink <[email protected]> Reviewed-by: Mohamed Yasser Abdelhamed Abdeen <[email protected]>
1 parent 2d6215c commit 236181f

File tree

17 files changed

+185
-63
lines changed

17 files changed

+185
-63
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ slotmap = "1.0.7"
223223
smallvec = { version = "1.13.2", default-features = false }
224224
socket2 = "0.5"
225225
sqlformat = "0.3.1"
226-
sqlparser = { git = "https://github.com/apache/datafusion-sqlparser-rs", rev = "53aba68e2dc758e591292115b1dd5faf71374346" }
226+
sqlparser = { git = "https://github.com/apache/datafusion-sqlparser-rs", rev = "ac0367ce1d6f71d80108d9e19be4b6574b832080" }
227227
strawpoll = "0.2.3"
228228
streaming-iterator = "0.1"
229229
stringprep = "0.1.4"

dataflow-expression/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ postgres = { workspace = true, features = [
3838
"with-serde_json-1",
3939
"with-bit-vec-0_6",
4040
] }
41+
readyset-sql-parsing = { path = "../readyset-sql-parsing" }
4142
regex = { workspace = true }
4243
serial_test = { workspace = true }
4344
test-utils = { path = "../test-utils" }

dataflow-expression/src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ impl Expr {
373373
#[cfg(test)]
374374
mod tests {
375375
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
376-
use nom_sql::parse_expr;
377376
use readyset_data::{ArrayD, Collation, DfType, Dialect, IxDyn, PgEnumMetadata};
378377
use readyset_errors::internal;
379378
use readyset_sql::Dialect::*;
379+
use readyset_sql_parsing::parse_expr;
380380
use serde_json::json;
381381
use Expr::*;
382382

dataflow-expression/src/eval/builtins.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,9 +1436,9 @@ mod tests {
14361436
use chrono::NaiveTime;
14371437
use chrono_tz::{Asia, Atlantic};
14381438
use lazy_static::lazy_static;
1439-
use nom_sql::parse_expr;
14401439
use readyset_errors::{internal, internal_err};
14411440
use readyset_sql::Dialect::*;
1441+
use readyset_sql_parsing::parse_expr;
14421442
use readyset_util::arbitrary::{
14431443
arbitrary_timestamp_naive_date_time, arbitrary_timestamp_naive_date_time_for_timezone,
14441444
};
@@ -2099,7 +2099,7 @@ mod tests {
20992099

21002100
#[test]
21012101
fn substring_with_from_and_for() {
2102-
let expr = parse_and_lower("SUBSTRING('abcdef', c0, c1)", MySQL);
2102+
let expr = parse_and_lower("substring('abcdef', c0, c1)", MySQL);
21032103
let call_with =
21042104
|from: i64, len: i64| expr.eval::<DfValue>(&[from.into(), len.into()]).unwrap();
21052105

@@ -2116,21 +2116,21 @@ mod tests {
21162116

21172117
#[test]
21182118
fn substring_multibyte() {
2119-
let expr = parse_and_lower("SUBSTRING('é' from 1 for 1)", PostgreSQL);
2119+
let expr = parse_and_lower("substring('é' from 1 for 1)", PostgreSQL);
21202120
let res = expr.eval::<DfValue>(&[]).unwrap();
21212121
assert_eq!(res, "é".into());
21222122
}
21232123

21242124
#[test]
21252125
fn substring_with_from() {
2126-
let expr = parse_and_lower("SUBSTRING('abcdef' from c0)", PostgreSQL);
2126+
let expr = parse_and_lower("substring('abcdef' from c0)", PostgreSQL);
21272127
let res = expr.eval::<DfValue>(&[2.into()]).unwrap();
21282128
assert_eq!(res, "bcdef".into());
21292129
}
21302130

21312131
#[test]
21322132
fn substring_with_for() {
2133-
let expr = parse_and_lower("SUBSTRING('abcdef' for c0)", PostgreSQL);
2133+
let expr = parse_and_lower("substring('abcdef' for c0)", PostgreSQL);
21342134
let res = expr.eval::<DfValue>(&[3.into()]).unwrap();
21352135
assert_eq!(res, "abc".into());
21362136
}

dataflow-expression/src/lower.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,10 +1495,10 @@ impl Expr {
14951495

14961496
#[cfg(test)]
14971497
pub(crate) mod tests {
1498-
use nom_sql::parse_expr;
14991498
use readyset_data::{Collation, PgEnumMetadata};
15001499
use readyset_sql::ast::{BinaryOperator as AstBinaryOperator, Float, Literal};
15011500
use readyset_sql::Dialect as ParserDialect;
1501+
use readyset_sql_parsing::parse_expr;
15021502

15031503
use super::*;
15041504

@@ -1729,7 +1729,7 @@ pub(crate) mod tests {
17291729

17301730
#[test]
17311731
fn substr_regular() {
1732-
let input = parse_expr(ParserDialect::MySQL, "SUBSTR('abcdefghi', 1, 7)").unwrap();
1732+
let input = parse_expr(ParserDialect::MySQL, "substr('abcdefghi', 1, 7)").unwrap();
17331733
let res = Expr::lower(input, Dialect::DEFAULT_MYSQL, &no_op_lower_context()).unwrap();
17341734
assert_eq!(
17351735
res,
@@ -1755,7 +1755,7 @@ pub(crate) mod tests {
17551755

17561756
#[test]
17571757
fn substring_regular() {
1758-
let input = parse_expr(ParserDialect::MySQL, "SUBSTRING('abcdefghi', 1, 7)").unwrap();
1758+
let input = parse_expr(ParserDialect::MySQL, "substring('abcdefghi', 1, 7)").unwrap();
17591759
let res = Expr::lower(input, Dialect::DEFAULT_MYSQL, &no_op_lower_context()).unwrap();
17601760
assert_eq!(
17611761
res,
@@ -1781,7 +1781,7 @@ pub(crate) mod tests {
17811781

17821782
#[test]
17831783
fn substring_without_string_arg() {
1784-
let input = parse_expr(ParserDialect::MySQL, "SUBSTRING(123 from 2)").unwrap();
1784+
let input = parse_expr(ParserDialect::MySQL, "substring(123 from 2)").unwrap();
17851785
let res = Expr::lower(input, Dialect::DEFAULT_MYSQL, &no_op_lower_context()).unwrap();
17861786
assert_eq!(res.ty(), &DfType::DEFAULT_TEXT);
17871787
}

dataflow-expression/tests/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use dataflow_expression::{Expr, LowerContext};
2-
use nom_sql::parse_expr;
32
use readyset_data::{DfType, DfValue};
43
use readyset_errors::{internal, ReadySetResult};
54
use readyset_sql::ast::{Column, Relation};
5+
use readyset_sql_parsing::parse_expr;
66

77
#[derive(Debug, Clone, Copy)]
88
struct TestLowerContext;

dataflow-expression/tests/mysql_oracle.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ async fn example_exprs_eval_same_as_mysql() {
145145
"json_overlaps('[]', '[]')",
146146
"json_overlaps('true', 'true')",
147147
"json_overlaps('[42]', '[0, 42, 0]')",
148-
"SUBSTRING('abcdef', 3)",
149-
"SUBSTRING('abcdef', 3, 2)",
150-
"SUBSTRING('abcdef', 1, 3)",
151-
"SUBSTRING('abcdef', '1', '3')",
148+
"substring('abcdef', 3)",
149+
"substring('abcdef', 3, 2)",
150+
"substring('abcdef', 1, 3)",
151+
"substring('abcdef', '1', '3')",
152152
"concat(1,2)",
153153
"concat('one',2)",
154154
"concat('one',2)",

readyset-mir/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ readyset-errors = { path = "../readyset-errors" }
2525
readyset-sql = { path = "../readyset-sql" }
2626

2727
[dev-dependencies]
28-
nom-sql = { path = "../nom-sql" }
28+
readyset-sql-parsing = { path = "../readyset-sql-parsing" }
2929
readyset-tracing = { path = "../readyset-tracing" }
3030

3131
[lints]

readyset-mir/src/rewrite/filters_to_join_keys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ pub(crate) fn convert_filters_to_join_keys(query: &mut MirQuery<'_>) -> ReadySet
379379
#[cfg(test)]
380380
mod tests {
381381
use common::IndexType;
382-
use nom_sql::parse_expr;
383382
use readyset_client::ViewPlaceholder;
384383
use readyset_sql::ast::{self, ColumnSpecification, Relation, SqlType};
385384
use readyset_sql::Dialect;
385+
use readyset_sql_parsing::parse_expr;
386386

387387
use super::*;
388388
use crate::graph::MirGraph;

0 commit comments

Comments
 (0)