@@ -28,8 +28,6 @@ use arrow::{
2828} ;
2929use datafusion_common:: { Result , internal_err} ;
3030
31- #[ cfg( feature = "proto" ) ]
32- use datafusion_proto_models:: protobuf;
3331use datafusion_expr:: ColumnarValue ;
3432
3533#[ derive( Debug , Clone , Eq ) ]
@@ -92,7 +90,9 @@ impl PhysicalExpr for UnKnownColumn {
9290 fn try_to_proto (
9391 & self ,
9492 _ctx : & datafusion_physical_expr_common:: physical_expr:: proto_encode:: PhysicalExprEncodeCtx < ' _ > ,
95- ) -> Result < Option < protobuf:: PhysicalExprNode > > {
93+ ) -> Result < Option < datafusion_proto_models:: protobuf:: PhysicalExprNode > > {
94+ use datafusion_proto_models:: protobuf;
95+
9696 Ok ( Some ( protobuf:: PhysicalExprNode {
9797 expr_id : None ,
9898 expr_type : Some ( protobuf:: physical_expr_node:: ExprType :: UnknownColumn (
@@ -108,17 +108,82 @@ impl PhysicalExpr for UnKnownColumn {
108108impl UnKnownColumn {
109109 /// Reconstruct an [`UnKnownColumn`] from its protobuf representation.
110110 pub fn try_from_proto (
111- node : & protobuf:: PhysicalExprNode ,
111+ node : & datafusion_proto_models :: protobuf:: PhysicalExprNode ,
112112 _ctx : & datafusion_physical_expr_common:: physical_expr:: proto_decode:: PhysicalExprDecodeCtx < ' _ > ,
113113 ) -> Result < Arc < dyn PhysicalExpr > > {
114+ use datafusion_proto_models:: protobuf;
115+
114116 let protobuf:: UnknownColumn { name } = match & node. expr_type {
115117 Some ( protobuf:: physical_expr_node:: ExprType :: UnknownColumn ( c) ) => c,
116- _ => return internal_err ! ( "PhysicalExprNode is not an UnKnownColumn" ) ,
118+ other => {
119+ return internal_err ! (
120+ "PhysicalExprNode is not an UnKnownColumn (expr_id={:?}, expr_type={other:?})" ,
121+ node. expr_id
122+ ) ;
123+ }
117124 } ;
118125 Ok ( Arc :: new ( UnKnownColumn :: new ( name) ) )
119126 }
120127}
121128
129+ #[ cfg( test) ]
130+ mod tests {
131+ use super :: * ;
132+
133+ #[ cfg( feature = "proto" ) ]
134+ use std:: sync:: Arc ;
135+
136+ #[ cfg( feature = "proto" ) ]
137+ use arrow:: datatypes:: Schema ;
138+
139+ #[ cfg( feature = "proto" ) ]
140+ use datafusion_common:: { Result , internal_err} ;
141+
142+ #[ cfg( feature = "proto" ) ]
143+ use datafusion_physical_expr_common:: physical_expr:: proto_decode:: PhysicalExprDecodeCtx ;
144+
145+ #[ cfg( feature = "proto" ) ]
146+ struct DummyDecode ;
147+
148+ #[ cfg( feature = "proto" ) ]
149+ impl datafusion_physical_expr_common:: physical_expr:: proto_decode:: PhysicalExprDecode
150+ for DummyDecode
151+ {
152+ fn decode (
153+ & self ,
154+ _node : & datafusion_proto_models:: protobuf:: PhysicalExprNode ,
155+ _schema : & Schema ,
156+ ) -> Result < Arc < dyn PhysicalExpr > > {
157+ internal_err ! ( "decode should not be called" )
158+ }
159+ }
160+
161+ #[ cfg( feature = "proto" ) ]
162+ #[ test]
163+ fn try_from_proto_reports_found_variant ( ) {
164+ use datafusion_proto_models:: protobuf;
165+
166+ let node = protobuf:: PhysicalExprNode {
167+ expr_id : Some ( 7 ) ,
168+ expr_type : Some ( protobuf:: physical_expr_node:: ExprType :: Column (
169+ protobuf:: PhysicalColumn {
170+ name : "col_a" . to_string ( ) ,
171+ index : 0 ,
172+ } ,
173+ ) ) ,
174+ } ;
175+ let schema = Schema :: empty ( ) ;
176+ let decoder = DummyDecode ;
177+ let ctx = PhysicalExprDecodeCtx :: new ( & schema, & decoder) ;
178+
179+ let err = UnKnownColumn :: try_from_proto ( & node, & ctx) . unwrap_err ( ) ;
180+ let err = err. to_string ( ) ;
181+
182+ assert ! ( err. contains( "expr_id=Some(7)" ) ) ;
183+ assert ! ( err. contains( "PhysicalColumn" ) ) ;
184+ }
185+ }
186+
122187impl Hash for UnKnownColumn {
123188 fn hash < H : Hasher > ( & self , state : & mut H ) {
124189 self . name . hash ( state) ;
0 commit comments