Skip to content
Open
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
4 changes: 4 additions & 0 deletions datafusion-cli/tests/cli_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ fn init() {
"change_format_version",
["--file", "tests/sql/types_format.sql", "-q"],
)]
#[case::fetch_not_supported(
"fetch_not_supported",
["--command", "SELECT 1 FETCH NEXT 1 ROW ONLY", "-q"],
)]
#[test]
fn cli_quick_test<'a>(
#[case] snapshot_name: &'a str,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: datafusion-cli/tests/cli_integration.rs
assertion_line: 176
info:
program: datafusion-cli
args:
- "--command"
- SELECT 1 FETCH NEXT 1 ROW ONLY
- "-q"
---
success: false
exit_code: 1
----- stdout -----
Error: This feature is not implemented: FETCH clause is not supported yet

----- stderr -----
28 changes: 21 additions & 7 deletions datafusion/sql/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,31 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
let mut query_plan_context = outer_planner_context.clone();
let planner_context = &mut query_plan_context;

if let Some(with) = query.with {
let Query {
with,
body,
order_by,
limit_clause,
pipe_operators,
fetch,
..
} = query;

if fetch.is_some() {
return not_impl_err!("FETCH clause is not supported yet");
}

if let Some(with) = with {
self.plan_with_clause(with, planner_context)?;
}

let set_expr = *query.body;
let set_expr = *body;
let plan = match set_expr {
SetExpr::Select(mut select) => {
let select_into = select.into.take();
let plan =
self.select_to_plan(*select, query.order_by, planner_context)?;
let plan = self.limit(plan, query.limit_clause, planner_context)?;
self.select_to_plan(*select, order_by.clone(), planner_context)?;
let plan = self.limit(plan, limit_clause.clone(), planner_context)?;
// Process the `SELECT INTO` after `LIMIT`.
self.select_into(plan, select_into)
}
Expand All @@ -69,7 +83,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
let _guard = StackGuard::new(256 * 1024);
self.set_expr_to_plan(other, planner_context)
}?;
let oby_exprs = to_order_by_exprs(query.order_by)?;
let oby_exprs = to_order_by_exprs(order_by)?;
let order_by_rex = self.order_by_to_sort_expr(
oby_exprs,
plan.schema(),
Expand All @@ -78,11 +92,11 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
None,
)?;
let plan = self.order_by(plan, order_by_rex)?;
self.limit(plan, query.limit_clause, planner_context)
self.limit(plan, limit_clause, planner_context)
}
}?;

self.pipe_operators(plan, query.pipe_operators, planner_context)
self.pipe_operators(plan, pipe_operators, planner_context)
}

/// Apply pipe operators to a plan
Expand Down
7 changes: 7 additions & 0 deletions datafusion/sql/tests/sql_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3901,6 +3901,13 @@ Limit: skip=3, fetch=5
);
}

#[test]
fn fetch_clause_is_not_supported() {
let sql = "SELECT 1 FETCH NEXT 1 ROW ONLY";
let err = logical_plan(sql).unwrap_err();
assert_contains!(err.to_string(), "FETCH clause is not supported yet");
}

#[test]
fn test_offset_before_limit() {
let sql = "select id from person where person.id > 100 OFFSET 3 LIMIT 5;";
Expand Down
2 changes: 2 additions & 0 deletions docs/source/user-guide/sql/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ SELECT age, person FROM table ORDER BY age, person DESC;

Limits the number of rows to be a maximum of `count` rows. `count` should be a non-negative integer.

DataFusion does not currently support the SQL `FETCH` clause. Use `LIMIT` to constrain the number of returned rows instead.

Example:

```sql
Expand Down