Skip to content

Commit

Permalink
feat(cubesql): Support placeholders in OFFSET, FETCH ...
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Feb 23, 2024
1 parent d9a7194 commit ff970f8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
14 changes: 7 additions & 7 deletions packages/cubejs-backend-native/Cargo.lock

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

14 changes: 7 additions & 7 deletions rust/cubesql/Cargo.lock

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

4 changes: 2 additions & 2 deletions rust/cubesql/cubesql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ homepage = "https://cube.dev"

[dependencies]
arc-swap = "1"
datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "531b925ce8215594a0d7c2151cfc17d6c6b2036c", default-features = false, features = ["regex_expressions", "unicode_expressions"] }
datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "28a07c390e7195dfd657c85118dee8cb73fc6bf7", default-features = false, features = ["regex_expressions", "unicode_expressions"] }
anyhow = "1.0"
thiserror = "1.0.50"
cubeclient = { path = "../cubeclient" }
pg-srv = { path = "../pg-srv" }
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "b7f265a4590049f8274cef8411f63eddb5b4bf87" }
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "347f769500e3305f1920d8b38832f483d8795bd3" }
lazy_static = "1.4.0"
base64 = "0.13.0"
tokio = { version = "^1.35", features = ["full", "rt", "tracing"] }
Expand Down
23 changes: 23 additions & 0 deletions rust/cubesql/cubesql/src/sql/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ trait Visitor<'ast, E: Error> {
if let Some(limit) = query.limit.as_mut() {
self.visit_expr_with_placeholder_type(limit, PlaceholderType::Number)?;
}
if let Some(offset) = query.offset.as_mut() {
self.visit_expr_with_placeholder_type(&mut offset.value, PlaceholderType::Number)?;
}
if let Some(fetch) = query.fetch.as_mut() {
if let Some(quantity) = fetch.quantity.as_mut() {
self.visit_expr_with_placeholder_type(quantity, PlaceholderType::Number)?;
}
}

Ok(())
}
Expand Down Expand Up @@ -1379,6 +1387,16 @@ mod tests {
],
)?;

assert_pg_params_finder(
"SELECT 1 OFFSET $1",
vec![FoundParameter::new(ColumnType::Int64)],
)?;

assert_pg_params_finder(
"SELECT 1 FETCH FIRST $1 ROWS ONLY",
vec![FoundParameter::new(ColumnType::Int64)],
)?;

Ok(())
}

Expand Down Expand Up @@ -1418,6 +1436,11 @@ mod tests {
fn test_placeholder_replacer() -> Result<(), CubeError> {
assert_placeholder_replacer("SELECT ?", "SELECT 'replaced_placeholder'")?;
assert_placeholder_replacer("SELECT 1 LIMIT ?", "SELECT 1 LIMIT 1")?;
assert_placeholder_replacer("SELECT 1 OFFSET ?", "SELECT 1 OFFSET 1")?;
assert_placeholder_replacer(
"SELECT 1 FETCH FIRST ? ROWS ONLY",
"SELECT 1 FETCH FIRST 1 ROWS ONLY",
)?;

Ok(())
}
Expand Down

0 comments on commit ff970f8

Please sign in to comment.