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

jeffreyvo 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 85f879d41a Support from-first SQL syntax (#17295)
85f879d41a is described below

commit 85f879d41a2565703caeb7811f7a3fe47ad3353e
Author: Simon Vandel Sillesen <simon.van...@gmail.com>
AuthorDate: Sun Aug 24 02:56:10 2025 +0200

    Support from-first SQL syntax (#17295)
    
    * Support from-first syntax
    
    I noticed in https://github.com/apache/datafusion/pull/17278 that `from`
    without an explicit projection did not work.
    This should fix it
    
    * add more tests
    
    * document in user guide
---
 datafusion/sql/src/select.rs                      |  9 ++++
 datafusion/sqllogictest/test_files/from-first.slt | 55 +++++++++++++++++++++++
 docs/source/user-guide/sql/select.md              | 14 ++++++
 3 files changed, 78 insertions(+)

diff --git a/datafusion/sql/src/select.rs b/datafusion/sql/src/select.rs
index c7ccda7232..1a90e5e09b 100644
--- a/datafusion/sql/src/select.rs
+++ b/datafusion/sql/src/select.rs
@@ -664,6 +664,15 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
     ) -> Result<Vec<SelectExpr>> {
         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
new file mode 100644
index 0000000000..c4a305e85e
--- /dev/null
+++ b/datafusion/sqllogictest/test_files/from-first.slt
@@ -0,0 +1,55 @@
+# 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/docs/source/user-guide/sql/select.md 
b/docs/source/user-guide/sql/select.md
index 39163cf492..eb8bca7a75 100644
--- a/docs/source/user-guide/sql/select.md
+++ b/docs/source/user-guide/sql/select.md
@@ -75,6 +75,20 @@ 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