@@ -43,6 +43,21 @@ use itertools::izip;
4343/// Shared [`PhysicalExpr`].
4444pub type PhysicalExprRef = Arc < dyn PhysicalExpr > ;
4545
46+ /// Describes execution context for the particular expression.
47+ pub struct ExprExecutionContext {
48+ /// External parameters.
49+ pub external_params : Arc < [ ScalarValue ] > ,
50+ }
51+
52+ impl ExprExecutionContext {
53+ /// Make a new [`ExprExecutionContext`].
54+ pub fn new ( external_param : impl Into < Arc < [ ScalarValue ] > > ) -> Self {
55+ Self {
56+ external_params : external_param. into ( ) ,
57+ }
58+ }
59+ }
60+
4661/// [`PhysicalExpr`]s represent expressions such as `A + 1` or `CAST(c1 AS int)`.
4762///
4863/// `PhysicalExpr` knows its type, nullability and can be evaluated directly on
@@ -430,6 +445,15 @@ pub trait PhysicalExpr: Any + Send + Sync + Display + Debug + DynEq + DynHash {
430445 fn is_volatile_node ( & self ) -> bool {
431446 false
432447 }
448+
449+ /// Make this expression executable. The most expressions are executable and do not
450+ /// require an additional work so this method could return `self`. However, there are
451+ /// expressions that should be transformed prior to execution, e.g. placeholder that
452+ /// should be resolved into scalar.
453+ fn execute (
454+ self : Arc < Self > ,
455+ context : & ExprExecutionContext ,
456+ ) -> Result < Arc < dyn PhysicalExpr > > ;
433457}
434458
435459#[ deprecated(
@@ -662,7 +686,7 @@ pub fn is_volatile(expr: &Arc<dyn PhysicalExpr>) -> bool {
662686
663687#[ cfg( test) ]
664688mod test {
665- use crate :: physical_expr:: PhysicalExpr ;
689+ use crate :: physical_expr:: { ExprExecutionContext , PhysicalExpr } ;
666690 use arrow:: array:: { Array , BooleanArray , Int64Array , RecordBatch } ;
667691 use arrow:: datatypes:: { DataType , Schema } ;
668692 use datafusion_expr_common:: columnar_value:: ColumnarValue ;
@@ -707,6 +731,13 @@ mod test {
707731 fn fmt_sql ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
708732 f. write_str ( "TestExpr" )
709733 }
734+
735+ fn execute (
736+ self : Arc < Self > ,
737+ _context : & ExprExecutionContext ,
738+ ) -> datafusion_common:: Result < Arc < dyn PhysicalExpr > > {
739+ Ok ( self )
740+ }
710741 }
711742
712743 impl Display for TestExpr {
0 commit comments