MCPcopy Create free account
hub / github.com/apache/datafusion / new

Method new

datafusion/physical-expr/src/expressions/lambda.rs:77–133  ·  view source on GitHub ↗
(params: Vec<String>, body: Arc<dyn PhysicalExpr>)

Source from the content-addressed store, hash-verified

75 }
76
77 fn new(params: Vec<String>, body: Arc<dyn PhysicalExpr>) -> Self {
78 let mut used_column_indices = HashSet::new();
79
80 body.apply(|node| {
81 if let Some(col) = node.downcast_ref::<Column>() {
82 used_column_indices.insert(col.index());
83 } else if let Some(var) = node.downcast_ref::<LambdaVariable>() {
84 used_column_indices.insert(var.index());
85 }
86
87 Ok(TreeNodeRecursion::Continue)
88 })
89 .expect("closure should be infallible");
90
91 let mut projection = used_column_indices.into_iter().collect::<Vec<_>>();
92
93 projection.sort();
94
95 let column_index_map = projection
96 .iter()
97 .enumerate()
98 .map(|(projected, original)| (*original, projected))
99 .collect::<HashMap<_, _>>();
100
101 let projected_body = Arc::clone(&body)
102 .transform_down(|e| {
103 if let Some(column) = e.downcast_ref::<Column>() {
104 let original = column.index();
105 let projected = *column_index_map.get(&original).unwrap();
106 if projected != original {
107 return Ok(Transformed::yes(Arc::new(Column::new(
108 column.name(),
109 projected,
110 ))));
111 }
112 } else if let Some(lambda_variable) = e.downcast_ref::<LambdaVariable>() {
113 let original = lambda_variable.index();
114 let projected = *column_index_map.get(&original).unwrap();
115 if projected != original {
116 return Ok(Transformed::yes(Arc::new(LambdaVariable::new(
117 projected,
118 Arc::clone(lambda_variable.field()),
119 ))));
120 }
121 }
122 Ok(Transformed::no(e))
123 })
124 .expect("closure should be infallible")
125 .data;
126
127 Self {
128 params,
129 body,
130 projected_body,
131 projection,
132 }
133 }
134

Callers

nothing calls this directly

Calls 12

newFunction · 0.85
transform_downMethod · 0.80
applyMethod · 0.45
insertMethod · 0.45
indexMethod · 0.45
into_iterMethod · 0.45
sortMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
getMethod · 0.45
nameMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected