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

Function find_operator_impl

prqlc/prqlc/src/sql/operators.rs:123–170  ·  view source on GitHub ↗
(
    operator_name: &str,
    dialect: Dialect,
)

Source from the content-addressed store, hash-verified

121}
122
123fn find_operator_impl(
124 operator_name: &str,
125 dialect: Dialect,
126) -> Option<(&pl::Func, Option<i32>, bool, Option<String>)> {
127 let operator_name = operator_name.strip_prefix("std.").unwrap();
128 let operator_ident = pl::Ident::from_path(
129 operator_name
130 .split('.')
131 .map(String::from)
132 .collect::<Vec<_>>(),
133 );
134
135 let dialect_module = std().get(&pl::Ident::from_name(dialect.to_string()));
136
137 let mut func_def = None;
138
139 if let Some(dialect_module) = dialect_module {
140 let module = dialect_module.kind.as_module().unwrap();
141 func_def = module.get(&operator_ident);
142 }
143
144 if func_def.is_none() {
145 func_def = std().get(&operator_ident);
146 }
147
148 let decl = func_def?;
149
150 let func_def = decl.kind.as_expr().unwrap();
151 let func_def = func_def.kind.as_func().unwrap();
152
153 let annotation = decl.annotations.iter().exactly_one().ok();
154 let mut annotation = annotation
155 .and_then(|x| into_tuple_items(*x.expr.clone()).ok())
156 .unwrap_or_default();
157
158 let binding_strength = pluck_annotation(&mut annotation, "binding_strength")
159 .and_then(|literal| literal.into_integer().ok())
160 .map(|int| int as i32);
161
162 let window_frame = pluck_annotation(&mut annotation, "window_frame")
163 .and_then(|literal| literal.into_boolean().ok())
164 .unwrap_or_default();
165
166 let coalesce =
167 pluck_annotation(&mut annotation, "coalesce").and_then(|val| val.into_string().ok());
168
169 Some((func_def.as_ref(), binding_strength, window_frame, coalesce))
170}
171
172fn pluck_annotation(
173 annotation: &mut Vec<(String, pl::ExprKind)>,

Callers 1

translate_operatorFunction · 0.85

Calls 6

stdFunction · 0.85
into_tuple_itemsFunction · 0.85
pluck_annotationFunction · 0.85
mapMethod · 0.80
iterMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected