@@ -27,9 +27,7 @@ use arrow::array::{ArrayRef, BooleanArray, new_empty_array};
2727use arrow:: compute:: filter_record_batch;
2828use arrow:: datatypes:: { DataType , Field , FieldRef , Schema } ;
2929use arrow:: record_batch:: RecordBatch ;
30- use datafusion_common:: tree_node:: {
31- Transformed , TransformedResult , TreeNode , TreeNodeRecursion ,
32- } ;
30+ use datafusion_common:: tree_node:: { TreeNode , TreeNodeRecursion } ;
3331use datafusion_common:: {
3432 Result , ScalarValue , assert_eq_or_internal_err, exec_err, not_impl_err,
3533} ;
@@ -357,55 +355,6 @@ pub trait PhysicalExpr: Any + Send + Sync + Display + Debug + DynEq + DynHash {
357355 /// See the [`fmt_sql`] function for an example of printing `PhysicalExpr`s as SQL.
358356 fn fmt_sql ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result ;
359357
360- /// Take a snapshot of this `PhysicalExpr`, if it is dynamic.
361- ///
362- /// "Dynamic" in this case means containing references to structures that may change
363- /// during plan execution, such as hash tables.
364- ///
365- /// This method is used to capture the current state of `PhysicalExpr`s that may contain
366- /// dynamic references to other operators in order to serialize it over the wire
367- /// or treat it via downcast matching.
368- ///
369- /// You should not call this method directly as it does not handle recursion.
370- /// Instead use [`snapshot_physical_expr`] to handle recursion and capture the
371- /// full state of the `PhysicalExpr`.
372- ///
373- /// This is expected to return "simple" expressions that do not have mutable state
374- /// and are composed of DataFusion's built-in `PhysicalExpr` implementations.
375- /// Callers however should *not* assume anything about the returned expressions
376- /// since callers and implementers may not agree on what "simple" or "built-in"
377- /// means.
378- /// In other words, if you need to serialize a `PhysicalExpr` across the wire
379- /// you should call this method and then try to serialize the result,
380- /// but you should handle unknown or unexpected `PhysicalExpr` implementations gracefully
381- /// just as if you had not called this method at all.
382- ///
383- /// In particular, consider:
384- /// * A `PhysicalExpr` that references the current state of a `datafusion::physical_plan::TopK`
385- /// that is involved in a query with `SELECT * FROM t1 ORDER BY a LIMIT 10`.
386- /// This function may return something like `a >= 12`.
387- /// * A `PhysicalExpr` that references the current state of a `datafusion::physical_plan::joins::HashJoinExec`
388- /// from a query such as `SELECT * FROM t1 JOIN t2 ON t1.a = t2.b`.
389- /// This function may return something like `t2.b IN (1, 5, 7)`.
390- ///
391- /// A system or function that can only deal with a hardcoded set of `PhysicalExpr` implementations
392- /// or needs to serialize this state to bytes may not be able to handle these dynamic references.
393- /// In such cases, we should return a simplified version of the `PhysicalExpr` that does not
394- /// contain these dynamic references.
395- ///
396- /// Systems that implement remote execution of plans, e.g. serialize a portion of the query plan
397- /// and send it across the wire to a remote executor may want to call this method after
398- /// every batch on the source side and broadcast / update the current snapshot to the remote executor.
399- ///
400- /// Note for implementers: this method should *not* handle recursion.
401- /// Recursion is handled in [`snapshot_physical_expr`].
402- fn snapshot ( & self ) -> Result < Option < Arc < dyn PhysicalExpr > > > {
403- // By default, we return None to indicate that this PhysicalExpr does not
404- // have any dynamic references or state.
405- // This is a safe default behavior.
406- Ok ( None )
407- }
408-
409358 /// Returns the generation of this `PhysicalExpr` for snapshotting purposes.
410359 /// The generation is an arbitrary u64 that can be used to track changes
411360 /// in the state of the `PhysicalExpr` over time without having to do an exhaustive comparison.
@@ -618,50 +567,6 @@ pub fn fmt_sql(expr: &dyn PhysicalExpr) -> impl Display + '_ {
618567 Wrapper { expr }
619568}
620569
621- /// Take a snapshot of the given `PhysicalExpr` if it is dynamic.
622- ///
623- /// Take a snapshot of this `PhysicalExpr` if it is dynamic.
624- /// This is used to capture the current state of `PhysicalExpr`s that may contain
625- /// dynamic references to other operators in order to serialize it over the wire
626- /// or treat it via downcast matching.
627- ///
628- /// See the documentation of [`PhysicalExpr::snapshot`] for more details.
629- ///
630- /// # Returns
631- ///
632- /// Returns a snapshot of the `PhysicalExpr` if it is dynamic, otherwise
633- /// returns itself.
634- pub fn snapshot_physical_expr (
635- expr : Arc < dyn PhysicalExpr > ,
636- ) -> Result < Arc < dyn PhysicalExpr > > {
637- snapshot_physical_expr_opt ( expr) . data ( )
638- }
639-
640- /// Take a snapshot of the given `PhysicalExpr` if it is dynamic.
641- ///
642- /// Take a snapshot of this `PhysicalExpr` if it is dynamic.
643- /// This is used to capture the current state of `PhysicalExpr`s that may contain
644- /// dynamic references to other operators in order to serialize it over the wire
645- /// or treat it via downcast matching.
646- ///
647- /// See the documentation of [`PhysicalExpr::snapshot`] for more details.
648- ///
649- /// # Returns
650- ///
651- /// Returns a `[`Transformed`] indicating whether a snapshot was taken,
652- /// along with the resulting `PhysicalExpr`.
653- pub fn snapshot_physical_expr_opt (
654- expr : Arc < dyn PhysicalExpr > ,
655- ) -> Result < Transformed < Arc < dyn PhysicalExpr > > > {
656- expr. transform_up ( |e| {
657- if let Some ( snapshot) = e. snapshot ( ) ? {
658- Ok ( Transformed :: yes ( snapshot) )
659- } else {
660- Ok ( Transformed :: no ( Arc :: clone ( & e) ) )
661- }
662- } )
663- }
664-
665570/// Check the generation of this `PhysicalExpr`.
666571/// Dynamic `PhysicalExpr`s may have a generation that is incremented
667572/// every time the state of the `PhysicalExpr` changes.
0 commit comments