From bd9e37d9cd0694ed88d0955013a7cf600b0544c6 Mon Sep 17 00:00:00 2001 From: Jia-Xuan Liu Date: Fri, 26 Jul 2024 23:03:02 +0800 Subject: [PATCH] allow qualified wildcard expressions to exist in the logical plan --- datafusion/expr/src/expr.rs | 4 +--- datafusion/expr/src/expr_schema.rs | 21 +++++---------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index 68d5504eea48..7f82337e1b45 100644 --- a/datafusion/expr/src/expr.rs +++ b/datafusion/expr/src/expr.rs @@ -2305,9 +2305,7 @@ fn write_name(w: &mut W, e: &Expr) -> Result<()> { } Expr::Wildcard { qualifier } => match qualifier { Some(qualifier) => { - return internal_err!( - "Create name does not support qualified wildcard, got {qualifier}" - ) + write!(w, "{}.*", qualifier)?; } None => write!(w, "*")?, }, diff --git a/datafusion/expr/src/expr_schema.rs b/datafusion/expr/src/expr_schema.rs index 5e0571f712ee..d3648a722d4c 100644 --- a/datafusion/expr/src/expr_schema.rs +++ b/datafusion/expr/src/expr_schema.rs @@ -28,8 +28,8 @@ use crate::{utils, LogicalPlan, Projection, Subquery, WindowFunctionDefinition}; use arrow::compute::can_cast_types; use arrow::datatypes::{DataType, Field}; use datafusion_common::{ - internal_err, not_impl_err, plan_datafusion_err, plan_err, Column, ExprSchema, - Result, TableReference, + not_impl_err, plan_datafusion_err, plan_err, Column, ExprSchema, Result, + TableReference, }; use std::collections::HashMap; use std::sync::Arc; @@ -254,13 +254,7 @@ impl ExprSchemable for Expr { ) }) } - Expr::Wildcard { qualifier } => { - // Wildcard do not really have a type and do not appear in projections - match qualifier { - Some(_) => internal_err!("QualifiedWildcard expressions are not valid in a logical query plan"), - None => Ok(DataType::Null) - } - } + Expr::Wildcard { .. } => Ok(DataType::Null), Expr::GroupingSet(_) => { // grouping sets do not really have a type and do not appear in projections Ok(DataType::Null) @@ -374,12 +368,7 @@ impl ExprSchemable for Expr { | Expr::SimilarTo(Like { expr, pattern, .. }) => { Ok(expr.nullable(input_schema)? || pattern.nullable(input_schema)?) } - Expr::Wildcard { qualifier } => match qualifier { - Some(_) => internal_err!( - "QualifiedWildcard expressions are not valid in a logical query plan" - ), - None => Ok(false), - }, + Expr::Wildcard { .. } => Ok(false), Expr::GroupingSet(_) => { // grouping sets do not really have the concept of nullable and do not appear // in projections @@ -560,7 +549,7 @@ mod tests { use super::*; use crate::{col, lit}; - use datafusion_common::{DFSchema, ScalarValue}; + use datafusion_common::{internal_err, DFSchema, ScalarValue}; macro_rules! test_is_expr_nullable { ($EXPR_TYPE:ident) => {{