Jefffrey commented on code in PR #19221:
URL: https://github.com/apache/datafusion/pull/19221#discussion_r2644756797
##########
datafusion/sql/src/expr/value.rs:
##########
@@ -191,75 +191,79 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
negative: bool,
interval: Interval,
) -> Result<Expr> {
- if interval.leading_precision.is_some() {
- return not_impl_err!(
- "Unsupported Interval Expression with leading_precision {:?}",
- interval.leading_precision
- );
- }
-
- if interval.last_field.is_some() {
- return not_impl_err!(
- "Unsupported Interval Expression with last_field {:?}",
- interval.last_field
- );
- }
+ sql_interval_to_expr_impl(negative, interval)
Review Comment:
Bit curious on this refactoring decision; why have it delegate to an inner
function that isn't reused anywhere, except for recursion?
##########
datafusion/sql/src/unparser/ast.rs:
##########
@@ -140,7 +140,15 @@ impl Default for QueryBuilder {
pub struct SelectBuilder {
distinct: Option<ast::Distinct>,
top: Option<ast::Top>,
- projection: Vec<ast::SelectItem>,
+ /// Projection items for the SELECT clause.
+ ///
+ /// This field uses `Option` to distinguish between three distinct states:
+ /// - `None`: No projection has been set (not yet initialized)
+ /// - `Some(vec![])`: Empty projection explicitly set (generates `SELECT
FROM ...` or `SELECT 1 FROM ...`)
+ /// - `Some(vec![...])`: Non-empty projection with specific
columns/expressions
+ ///
+ /// Use `projection()` to set this field and `already_projected()` to
check if it has been set.
+ projection: Option<Vec<ast::SelectItem>>,
Review Comment:
So does `SELECT * FROM` map to `None` here? Could we include this in the
docstring to make it more clear?
##########
datafusion/sql/src/unparser/dialect.rs:
##########
@@ -218,6 +218,45 @@ pub trait Dialect: Send + Sync {
fn timestamp_with_tz_to_string(&self, dt: DateTime<Tz>, _unit: TimeUnit)
-> String {
dt.to_string()
}
+
+ /// Whether the dialect supports an empty select list such as `SELECT FROM
table`.
+ ///
+ /// An empty select list returns rows without any column data, which is
useful for:
+ /// - Counting rows: `SELECT FROM users WHERE active = true` (combined
with `COUNT(*)`)
+ /// - Testing row existence without retrieving column data
+ /// - Performance optimization when only row counts or existence checks
are needed
+ ///
+ /// # Supported Databases
+ ///
+ /// - **PostgreSQL**: Fully supported. Returns rows with zero columns.
+ ///
+ /// # Unsupported Databases
+ ///
+ /// Most other SQL databases require at least one column in the SELECT
list:
+ /// - MySQL
+ /// - SQLite
+ /// - SQL Server
+ /// - Oracle
+ /// - DuckDB
+ ///
+ /// For these databases, the unparser falls back to `SELECT 1 FROM table`.
+ ///
+ /// # Default
+ ///
+ /// Returns `false` for maximum compatibility across SQL dialects.
Review Comment:
I don't know if we should include this detail about specific databases here;
ideally their own dialects would implement this to show their support. We can
just leave it at what the default behaviour is.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]