-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document SQL dialect guidance #13706
base: main
Are you sure you want to change the base?
Changes from 3 commits
6bb2aa8
5af035c
49edb03
b674a42
8fd7f44
e9f5da1
c6a83f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!--- | ||
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. | ||
--> | ||
|
||
# SQL Dialect | ||
|
||
By default, Apache DataFusion follows the [PostgreSQL SQL dialect]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When reading something that includes "by default", a reader may have natural question "how do i change this?" Should we have a tip how to amend the behavior if the default doesn't please the user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea -- I tried to do so in 8fd7f44 |
||
For Array/List functions and semantics, it follows the [DuckDB SQL dialect]. | ||
|
||
[duckdb sql dialect]: https://duckdb.org/docs/sql/functions/array | ||
[postgresql sql dialect]: https://www.postgresql.org/docs/current/sql.html | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this dualism good for users? i think the market formed consensus to regard PostgreSQL-compatible as a good thing. Why do we water this down to say PostgreSQL-compatible, except where not? It's going to be confusing and incoherent for example these expressions should be equivalent
whereas we say that first two are governed by "be like PostgreSQL" goal Why would users appreciate that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how good this is for users -- I think this choice (to deviate from postgres and instead follow DuckDB) was driven by the desires of the original implementers. Maybe @jayzhan211 remembers more of the rationale There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nested functions are not well-supported in Postgres, so we choose DuckDB and other OLAP systems for these kind of function. We don’t enforce strict adherence to any particular system for function implementation. Instead, our goal is to establish a default behavior in the DataFusion core while making it easy to customize functions as needed. Given that Postgres and DuckDB are enough for us to decide what the function should be like so we ends up these 2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of focusing on which system we should be compatible with, our goal should be to make it easy to customize for different systems. For example, Spark and Postgres handle nulls differently, as does Datafusion. However, we currently lack a straightforward way to adjust null handling. Users are forced to copy entire functions and maintain them independently, which isn't ideal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #6855 is the original discussion about switching to other OLAP system for nested function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think the "inconsistency" mentioned here is what we want, learn the lesson from existing systems and choose the "better" one among them. The downside of "inconsistency" can be minimize if we document the rationale of the decision and the difference from other systems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I am trying to do with this PR is to provide practical guidance about what to do when we we hit a question like in #13683 (comment) (what should the I think it we could just say "do whatever DuckDB does in this case" that would be much more efficent and the PR would not get stuck I realize there may not be complete alignment on how DataFusion's SQL should behave and I am in full support of making it as configurable as possible I think there is a tension between
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I also would prefer to avoid doing that.
Yes, that's efficient. We're trading answer efficiency vs consistency and predictability of our of the box semantics, with both sides of the trade being desirable properties. It's likely that maximum consistency you get from "do whatever SQL spec says", but obviously this isn't very efficient (most engineers can't even read the spec).
That would be great, especially if this a reasonable dialect (some are, some are not) and is one dialect, not some form of a synergy between two different dialects that disagree with each other. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can change this section to be titles "Aspirational SQL dialect" or something.
I fully admit that what is supported by DataFusion is not exactly the same as any existing dialect. Maybe it is wishful thinking that we are "close enough" to postgres and that defining the goal (even if we never reach it) is valuable 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agreed! We should have a goal, and we should have a litmus test for determining what gets in and with what semantics |
||
|
||
## Rationale | ||
|
||
SQL Engines have a choice to either use an existing SQL dialect or define their | ||
own. Using an existing dialect may not fit perfectly as it is hard to match | ||
semantics exactly (need bug-for-bug compatibility), and is likely not what all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More reasons for using pogstgres specifically: it is
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
mostly true (but i know of some deviations) i kind of assumed PostgreSQL ship has sailed and we're just retro-documenting. But if the ball (choice) is still in play, my vote goes to Trino as a good reference implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That was my assumption too, but as others like @jayzhan211 (and yourself) have pointed out, I don't think DataFusion is (or can be) 100% consistent with this point |
||
users want. However, it avoids the (very significant) effort of defining | ||
semantics as well as documenting and teaching users about them. | ||
|
||
As Apache DataFusion is highly customizable, systems built on DataFusion can and do | ||
update functions and SQL syntax to model other systems, such as Apache Spark or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and type rules |
||
MySQL. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ SQL Reference | |
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
dialect | ||
data_types | ||
select | ||
subqueries | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be good to say this section pertains the SQL frontend:
see also #13704 (comment)
it's also worth noting that we are not going to align with PostgreSQL's dialect fully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworded and expanded in b674a42