Skip to content
Merged
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
25 changes: 25 additions & 0 deletions datafusion/core/tests/sql/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,28 @@ async fn test_version_function() {

assert_eq!(version.value(0), expected_version);
}

/// Regression test for https://github.com/apache/datafusion/issues/17513
/// See https://github.com/apache/datafusion/pull/17520
#[tokio::test]
async fn test_select_no_projection() -> Result<()> {
let tmp_dir = TempDir::new()?;
// `create_ctx_with_partition` creates 10 rows per partition and we chose 1 partition
let ctx = create_ctx_with_partition(&tmp_dir, 1).await?;

let results = ctx.sql("SELECT FROM test").await?.collect().await?;
// We should get all of the rows, just without any columns
let total_rows: usize = results.iter().map(|b| b.num_rows()).sum();
assert_eq!(total_rows, 10);
// Check that none of the batches have any columns
for batch in &results {
assert_eq!(batch.num_columns(), 0);
}
// Sanity check the output, should be just empty columns
assert_snapshot!(batches_to_sort_string(&results), @r"
++
++
++
");
Ok(())
}
8 changes: 0 additions & 8 deletions datafusion/sql/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,14 +665,6 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
let mut prepared_select_exprs = vec![];
let mut error_builder = DataFusionErrorBuilder::new();

// Handle the case where no projection is specified but we have a valid FROM clause
// In this case, implicitly add a wildcard projection (SELECT *)
let projection = if projection.is_empty() && !empty_from {
vec![SelectItem::Wildcard(WildcardAdditionalOptions::default())]
} else {
projection
};

for expr in projection {
match self.sql_select_to_rex(expr, plan, empty_from, planner_context) {
Ok(expr) => prepared_select_exprs.push(expr),
Expand Down
55 changes: 0 additions & 55 deletions datafusion/sqllogictest/test_files/from-first.slt

This file was deleted.

28 changes: 28 additions & 0 deletions datafusion/sqllogictest/test_files/projection.slt
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,31 @@ physical_plan

statement ok
drop table t;

# Regression test for
# https://github.com/apache/datafusion/issues/17513

query I
COPY (select 1 as a, 2 as b)
TO 'test_files/scratch/projection/17513.parquet'
STORED AS PARQUET;
----
1

statement ok
create external table t1 stored as parquet location 'test_files/scratch/projection/17513.parquet';

query TT
explain format indent
select from t1 where t1.a > 1;
----
logical_plan
01)Projection:
02)--Filter: t1.a > Int64(1)
03)----TableScan: t1 projection=[a], partial_filters=[t1.a > Int64(1)]
physical_plan
01)ProjectionExec: expr=[]
02)--CoalesceBatchesExec: target_batch_size=8192
03)----FilterExec: a@0 > 1
04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
05)--------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/projection/17513.parquet]]}, projection=[a], file_type=parquet, predicate=a@0 > 1, pruning_predicate=a_null_count@1 != row_count@2 AND a_max@0 > 1, required_guarantees=[]
14 changes: 0 additions & 14 deletions docs/source/user-guide/sql/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,6 @@ Example:
SELECT t.a FROM table AS t
```

The `FROM` clause can also come before the `SELECT` clause.
Example:

```sql
FROM table AS t
SELECT t.a
```

If the `SELECT` clause is omitted, the `FROM` clause will return all columns from the table.

```sql
FROM table
```

## WHERE clause

Example:
Expand Down