This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 5fd831fce9 Revert #17295 (Support from-first SQL syntax) (#17520)
5fd831fce9 is described below

commit 5fd831fce9bf8fddeb85a903c6be9ec49c9afda0
Author: Adrian Garcia Badaracco <1755071+adria...@users.noreply.github.com>
AuthorDate: Fri Sep 12 14:55:37 2025 -0500

    Revert #17295 (Support from-first SQL syntax) (#17520)
    
    * Add failing test
    
    * Fix regression in SELECT FROM syntax with WHERE clause
    
    When using 'SELECT FROM table WHERE condition', the query should create
    an empty projection (no columns) while still filtering rows. This was
    broken by PR #17295 which added FROM-first syntax support.
    
    The issue was that both 'FROM table' and 'SELECT FROM table' resulted
    in empty projection lists, making them indistinguishable. The fix checks
    for the presence of a WHERE clause to differentiate:
    - 'FROM table' (no WHERE) -> add wildcard projection (all columns)
    - 'SELECT FROM table WHERE ...' -> keep empty projection
    
    Also updates the test expectation to correctly show the empty Projection
    node in the query plan.
    
    Fixes #17513
    
    * Revert
    
    * Fix regression: SELECT FROM syntax should return empty projection
    
    Removes automatic wildcard projection for empty projections, fixing
    the regression where `SELECT FROM table` incorrectly returned all
    columns instead of empty projection.
    
    Note: This temporarily breaks FROM-first syntax. A proper fix would
    require distinguishing between `FROM table` and `SELECT FROM table`
    at the parser level.
    
    Fixes #17513
    
    🤖 Generated with [Claude Code](https://claude.ai/code)
    
    Co-Authored-By: Claude <nore...@anthropic.com>
    
    * add a better regression test
    
    * remove comment
    
    * fmt
    
    * Update datafusion/sqllogictest/test_files/projection.slt
    
    Co-authored-by: Oleks V <comph...@users.noreply.github.com>
    
    * Update datafusion/core/tests/sql/select.rs
    
    Co-authored-by: Oleks V <comph...@users.noreply.github.com>
    
    * revert docs
    
    * fmt
    
    ---------
    
    Co-authored-by: Claude <nore...@anthropic.com>
    Co-authored-by: Oleks V <comph...@users.noreply.github.com>
---
 datafusion/core/tests/sql/select.rs               | 25 +++++++++++
 datafusion/sql/src/select.rs                      |  8 ----
 datafusion/sqllogictest/test_files/from-first.slt | 55 -----------------------
 datafusion/sqllogictest/test_files/projection.slt | 28 ++++++++++++
 docs/source/user-guide/sql/select.md              | 14 ------
 5 files changed, 53 insertions(+), 77 deletions(-)

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:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@datafusion.apache.org
For additional commands, e-mail: commits-h...@datafusion.apache.org

Reply via email to