@@ -322,29 +322,31 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
322322 for column_ident in & columns {
323323 let column_name = column_ident. value . clone ( ) ;
324324
325- if let Some ( idx ) =
325+ let idx = if let Some ( i ) =
326326 base_schema. index_of_column_by_name ( None , & column_name)
327327 {
328- let field = base_schema. field ( idx) ;
329- let field_type = field. data_type ( ) ;
328+ i
329+ } else {
330+ return plan_err ! ( "Column '{}' not found in input" , column_name) ;
331+ } ;
330332
331- // Verify all unpivot columns have compatible types
332- if let Some ( current_type) = & common_type {
333- if comparison_coercion ( current_type, field_type) . is_none ( ) {
334- return plan_err ! (
333+ let field = base_schema. field ( idx) ;
334+ let field_type = field. data_type ( ) ;
335+
336+ // Verify all unpivot columns have compatible types
337+ if let Some ( current_type) = & common_type {
338+ if comparison_coercion ( current_type, field_type) . is_none ( ) {
339+ return plan_err ! (
335340 "The type of column '{}' conflicts with the type of other columns in the UNPIVOT list." ,
336341 column_name. to_uppercase( )
337342 ) ;
338- }
339- } else {
340- common_type = Some ( field_type. clone ( ) ) ;
341343 }
342-
343- unpivot_column_indices. push ( idx) ;
344- unpivot_column_names. push ( column_name) ;
345344 } else {
346- return plan_err ! ( "Column '{}' not found in input" , column_name ) ;
345+ common_type = Some ( field_type . clone ( ) ) ;
347346 }
347+
348+ unpivot_column_indices. push ( idx) ;
349+ unpivot_column_names. push ( column_name) ;
348350 }
349351
350352 if unpivot_column_names. is_empty ( ) {
@@ -378,11 +380,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
378380 let mut builder = LogicalPlanBuilder :: from ( base_plan. clone ( ) )
379381 . project ( projection_exprs) ?;
380382
381- if null_inclusion
382- . clone ( )
383- . unwrap_or ( NullInclusion :: ExcludeNulls )
384- == NullInclusion :: ExcludeNulls
385- {
383+ if let Some ( NullInclusion :: ExcludeNulls ) | None = null_inclusion {
386384 let col = Column :: new ( None :: < & str > , value_column. clone ( ) ) ;
387385 builder = builder
388386 . filter ( Expr :: IsNotNull ( Box :: new ( Expr :: Column ( col) ) ) ) ?;
0 commit comments