MCPcopy Create free account
hub / github.com/PRQL/prql / insert_frame

Method insert_frame

prqlc/prqlc/src/semantic/module.rs:197–298  ·  view source on GitHub ↗
(&mut self, lineage: &Lineage, namespace: &str)

Source from the content-addressed store, hash-verified

195 }
196
197 pub(super) fn insert_frame(&mut self, lineage: &Lineage, namespace: &str) {
198 let namespace = self.names.entry(namespace.to_string()).or_default();
199 let namespace = namespace.kind.as_module_mut().unwrap();
200
201 let lin_ty = *ty_of_lineage(lineage).kind.into_array().unwrap().unwrap();
202
203 for (col_index, column) in lineage.columns.iter().enumerate() {
204 // determine input name
205 let input_name = match column {
206 LineageColumn::All { input_id, .. } => {
207 lineage.find_input(*input_id).map(|i| &i.name)
208 }
209 LineageColumn::Single { name, .. } => name.as_ref().and_then(|n| n.path.first()),
210 };
211
212 // get or create input namespace
213 let ns;
214 if let Some(input_name) = input_name {
215 let entry = match namespace.names.get_mut(input_name) {
216 Some(x) => x,
217 None => {
218 namespace.redirects.push(Ident::from_name(input_name));
219
220 let input = lineage.find_input_by_name(input_name).unwrap();
221 let order = lineage.inputs.iter().position(|i| i.id == input.id);
222 let order = order.unwrap();
223
224 let mut sub_ns = Module::default();
225
226 let self_ty = lin_ty.clone().kind.into_tuple().unwrap();
227 let self_ty = self_ty
228 .into_iter()
229 .flat_map(|x| x.into_single())
230 .find(|(name, _)| name.as_ref() == Some(input_name))
231 .and_then(|(_, ty)| ty)
232 .or(Some(Ty::new(TyKind::Tuple(vec![TyTupleField::Wildcard(
233 None,
234 )]))));
235
236 let self_decl = Decl {
237 declared_at: Some(input.id),
238 kind: DeclKind::InstanceOf(input.table.clone(), self_ty),
239 ..Default::default()
240 };
241 sub_ns.names.insert(NS_SELF.to_string(), self_decl);
242
243 let sub_ns = Decl {
244 declared_at: Some(input.id),
245 order,
246 kind: DeclKind::Module(sub_ns),
247 ..Default::default()
248 };
249
250 namespace.names.entry(input_name.clone()).or_insert(sub_ns)
251 }
252 };
253 ns = entry.kind.as_module_mut().unwrap()
254 } else {

Callers 1

resolve_function_argsMethod · 0.80

Calls 10

ModuleClass · 0.85
iterMethod · 0.80
mapMethod · 0.80
find_inputMethod · 0.80
get_mutMethod · 0.80
pushMethod · 0.80
find_input_by_nameMethod · 0.80
into_iterMethod · 0.80
ty_of_lineageFunction · 0.70
insertMethod · 0.45

Tested by

no test coverage detected