/Users/andrewlamb/Software/datafusion/datafusion/physical-expr/src/expressions/no_op.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | //! NoOp placeholder for physical operations |
19 | | |
20 | | use std::any::Any; |
21 | | use std::hash::{Hash, Hasher}; |
22 | | use std::sync::Arc; |
23 | | |
24 | | use arrow::{ |
25 | | datatypes::{DataType, Schema}, |
26 | | record_batch::RecordBatch, |
27 | | }; |
28 | | |
29 | | use crate::physical_expr::down_cast_any_ref; |
30 | | use crate::PhysicalExpr; |
31 | | use datafusion_common::{internal_err, Result}; |
32 | | use datafusion_expr::ColumnarValue; |
33 | | |
34 | | /// A place holder expression, can not be evaluated. |
35 | | /// |
36 | | /// Used in some cases where an `Arc<dyn PhysicalExpr>` is needed, such as `children()` |
37 | | #[derive(Debug, PartialEq, Eq, Default, Hash)] |
38 | | pub struct NoOp {} |
39 | | |
40 | | impl NoOp { |
41 | | /// Create a NoOp expression |
42 | 0 | pub fn new() -> Self { |
43 | 0 | Self {} |
44 | 0 | } |
45 | | } |
46 | | |
47 | | impl std::fmt::Display for NoOp { |
48 | 0 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
49 | 0 | write!(f, "NoOp") |
50 | 0 | } |
51 | | } |
52 | | |
53 | | impl PhysicalExpr for NoOp { |
54 | | /// Return a reference to Any that can be used for downcasting |
55 | 0 | fn as_any(&self) -> &dyn Any { |
56 | 0 | self |
57 | 0 | } |
58 | | |
59 | 0 | fn data_type(&self, _input_schema: &Schema) -> Result<DataType> { |
60 | 0 | Ok(DataType::Null) |
61 | 0 | } |
62 | | |
63 | 0 | fn nullable(&self, _input_schema: &Schema) -> Result<bool> { |
64 | 0 | Ok(true) |
65 | 0 | } |
66 | | |
67 | 0 | fn evaluate(&self, _batch: &RecordBatch) -> Result<ColumnarValue> { |
68 | 0 | internal_err!("NoOp::evaluate() should not be called") |
69 | 0 | } |
70 | | |
71 | 0 | fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>> { |
72 | 0 | vec![] |
73 | 0 | } |
74 | | |
75 | 0 | fn with_new_children( |
76 | 0 | self: Arc<Self>, |
77 | 0 | _children: Vec<Arc<dyn PhysicalExpr>>, |
78 | 0 | ) -> Result<Arc<dyn PhysicalExpr>> { |
79 | 0 | Ok(self) |
80 | 0 | } |
81 | | |
82 | 0 | fn dyn_hash(&self, state: &mut dyn Hasher) { |
83 | 0 | let mut s = state; |
84 | 0 | self.hash(&mut s); |
85 | 0 | } |
86 | | } |
87 | | |
88 | | impl PartialEq<dyn Any> for NoOp { |
89 | 0 | fn eq(&self, other: &dyn Any) -> bool { |
90 | 0 | down_cast_any_ref(other) |
91 | 0 | .downcast_ref::<Self>() |
92 | 0 | .map(|x| self == x) |
93 | 0 | .unwrap_or(false) |
94 | 0 | } |
95 | | } |