You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "simonvandel (via GitHub)" <gi...@apache.org> on 2025/08/22 20:19:24 UTC

[PR] Support from-first syntax [datafusion]

simonvandel opened a new pull request, #17295:
URL: https://github.com/apache/datafusion/pull/17295

   
   
   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   - Closes #.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   I noticed in https://github.com/apache/datafusion/pull/17278 that `from` without an explicit projection did not work.
   This should fix it.
   
   The from-first syntax is also available in duckdb. See https://duckdb.org/docs/stable/sql/query_syntax/from.html#examples
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   Yes, added SLT test
   
   ## Are there any user-facing changes?
   
   FROM-first syntax without projection is now supported.
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "simonvandel (via GitHub)" <gi...@apache.org>.
simonvandel commented on code in PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#discussion_r2295857111


##########
datafusion/sqllogictest/test_files/from-first.slt:
##########
@@ -0,0 +1,41 @@
+# 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 *

Review Comment:
   I added some tests in [fe284b6](https://github.com/apache/datafusion/pull/17295/commits/fe284b6f655deccf040cc4a65387032f83de6f6e). Does this cover your question?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#issuecomment-3281551846

   > SHould we also make from t (without anything else) an error like it is in duckdb?
   
   DuckDB *does* support `FROM t;`, it does *not* support `SELECT FROM t;`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#issuecomment-3281536219

   > So maybe the answer is that we should make `select from t1;` equivalent to "select no columns from t1" while keeping `from t1;` equivalent to `select * from t1;`?
   
   I think we should be consistent with other databases
   
   This proposal seems reasonable to me 
   
   SHould we also make `from t` (without anything else) an error like it is in duckdb?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#discussion_r2295868517


##########
datafusion/sqllogictest/test_files/from-first.slt:
##########
@@ -0,0 +1,41 @@
+# 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 *

Review Comment:
   Yep! 👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#issuecomment-3281120327

   @alamb we discussed a bit in https://github.com/apache/datafusion/pull/17520#issuecomment-3280334178, I'm not sure that this PR introduced a bug. If I understand correctly `select from t1` should be equivalent to `select * from t1` -> then there is no bug. Now if `select from t1` is meant to be `select every row but no columns` then there is a bug but it has nothing to do with the where clause or projection pushdown.
   
   FWIW:
   
   ```
   DataFusion CLI v50.0.0
   > create table t1 (a int, b int);
   0 row(s) fetched. 
   Elapsed 0.004 seconds.
   
   > insert into t1 values (1, 2);
   +-------+
   | count |
   +-------+
   | 1     |
   +-------+
   1 row(s) fetched. 
   Elapsed 0.010 seconds.
   
   > select * from t1;
   +---+---+
   | a | b |
   +---+---+
   | 1 | 2 |
   +---+---+
   1 row(s) fetched. 
   Elapsed 0.003 seconds.
   
   > select from t1;
   +---+---+
   | a | b |
   +---+---+
   | 1 | 2 |
   +---+---+
   1 row(s) fetched. 
   Elapsed 0.004 seconds.
   
   > from t1;
   +---+---+
   | a | b |
   +---+---+
   | 1 | 2 |
   +---+---+
   1 row(s) fetched. 
   Elapsed 0.001 seconds.
   ```
   
   Postgres:
   ```
   postgres=# create table t1 (a int, b int);
   CREATE TABLE
   postgres=# insert into t1 values (1), (2);
   INSERT 0 2
   postgres=# select * from t1;
    a | b 
   ---+---
    1 |  
    2 |  
   (2 rows)
   
   postgres=# select from t1;
   --
   (2 rows)
   
   postgres=# from t1;
   ERROR:  syntax error at or near "from"
   LINE 1: from t1;
   ```
   
   DuckDB:
   ```sql
   DuckDB v1.3.2 (Ossivalis) 0b83e5d2f6
   Enter ".help" for usage hints.
   Connected to a transient in-memory database.
   Use ".open FILENAME" to reopen on a persistent database.
   D create table t1 AS (select 1 as a, 2 as b);
   D insert into t1 values (1, 2);
   D select from t1;
   Parser Error:
   SELECT clause without selection list
   D from t1;
   ┌───────┬───────┐
   │   a   │   b   │
   │ int32 │ int32 │
   ├───────┼───────┤
   │     1 │     2 │
   │     1 │     2 │
   └───────┴───────┘
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey merged PR #17295:
URL: https://github.com/apache/datafusion/pull/17295


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#discussion_r2295640501


##########
datafusion/sqllogictest/test_files/from-first.slt:
##########
@@ -0,0 +1,41 @@
+# 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 *

Review Comment:
   Is it valid to put specific columns in this `SELECT` that comes after the `FROM`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "simonvandel (via GitHub)" <gi...@apache.org>.
simonvandel commented on PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#issuecomment-3216792813

   > Maybe need to update the SQL reference docs with this new behaviour?
   > 
   >     * https://datafusion.apache.org/user-guide/sql/select.html
   
   I added some documentation in [9f1b436](https://github.com/apache/datafusion/pull/17295/commits/9f1b436a543dc1c34ed016e54678218ac9e73228)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#issuecomment-3281069200

   @xudong963  found this PR seems to have introduced a regression
   - https://github.com/apache/datafusion/issues/17513
   
   @adriangb  has a proposed PR up to fix:
   - https://github.com/apache/datafusion/pull/17520


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Support from-first SQL syntax [datafusion]

Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on PR #17295:
URL: https://github.com/apache/datafusion/pull/17295#issuecomment-3281124360

   So maybe the answer is that we should make `select from t1;` equivalent to "select no columns from t1"


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org