Skip to content

Apache DataFusion SQL Query Engine

Revert #17295 (Support from-first SQL syntax) (#17520)

Adrian Garcia Badaracco5fd831fce9bf
diff --git a/datafusion/core/tests/sql/select.rs b/datafusion/core/tests/sql/select.rs
index 0e1210ebb8..1978c189c4 100644
--- a/datafusion/core/tests/sql/select.rs
+++ b/datafusion/core/tests/sql/select.rs
@@ -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(())
+}
diff --git a/datafusion/sql/src/select.rs b/datafusion/sql/src/select.rs
index 3a5dcfdb39..26dbf45fbc 100644
--- a/datafusion/sql/src/select.rs
+++ b/datafusion/sql/src/select.rs
@@ -676,14 +676,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),
diff --git a/datafusion/sqllogictest/test_files/from-first.slt b/datafusion/sqllogictest/test_files/from-first.slt
deleted file mode 100644
index c4a305e85e..0000000000
--- a/datafusion/sqllogictest/test_files/from-first.slt
+++ /dev/null
@@ -1,55 +0,0 @@
-# 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.
-
-query I
-FROM range(2)
-----
-0
-1
-
-query I
-FROM range(2)
-SELECT *
-----
-0
-1
-
-query I
-FROM (SELECT * FROM range(2))
-----
-0
-1
-
-query I
-FROM (FROM range(2))
-----
-0
-1
-
-query I
-FROM range(2)
-SELECT 1
-----
-1
-1
-
-query I
-FROM range(2) as r
-SELECT r.value
-----
-0
-1
diff --git a/datafusion/sqllogictest/test_files/projection.slt b/datafusion/sqllogictest/test_files/projection.slt
index 0f0cbac1fa..97ebe2340d 100644
--- a/datafusion/sqllogictest/test_files/projection.slt
+++ b/datafusion/sqllogictest/test_files/projection.slt
@@ -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=[]
diff --git a/docs/source/user-guide/sql/select.md b/docs/source/user-guide/sql/select.md
index eb8bca7a75..39163cf492 100644
--- a/docs/source/user-guide/sql/select.md
+++ b/docs/source/user-guide/sql/select.md
@@ -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: