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

Function process_null

prqlc/prqlc/src/sql/gen_expr.rs:144–168  ·  view source on GitHub ↗

Translates into IS NULL if possible

(name: &str, args: &[rq::Expr], ctx: &mut Context)

Source from the content-addressed store, hash-verified

142
143/// Translates into IS NULL if possible
144fn process_null(name: &str, args: &[rq::Expr], ctx: &mut Context) -> Result<sql_ast::Expr> {
145 let (a, b) = (&args[0], &args[1]);
146 let operand = if matches!(a.kind, rq::ExprKind::Literal(Literal::Null)) {
147 b
148 } else {
149 a
150 };
151
152 // If this were an Enum, we could match on it (see notes in `std.rs`).
153 if name == "std.eq" {
154 let strength = sql_ast::Expr::IsNull(Box::new(sql_ast::Expr::Value(Value::Null.into())))
155 .binding_strength();
156 let expr = translate_operand(operand.clone(), true, strength, Associativity::Both, ctx)?;
157 let expr = Box::new(expr.into_ast());
158 Ok(sql_ast::Expr::IsNull(expr))
159 } else if name == "std.ne" {
160 let strength = sql_ast::Expr::IsNotNull(Box::new(sql_ast::Expr::Value(Value::Null.into())))
161 .binding_strength();
162 let expr = translate_operand(operand.clone(), true, strength, Associativity::Both, ctx)?;
163 let expr = Box::new(expr.into_ast());
164 Ok(sql_ast::Expr::IsNotNull(expr))
165 } else {
166 unreachable!()
167 }
168}
169
170/// Translates into IN (v1, v2, ...) if possible
171fn process_array_in(

Callers 1

translate_exprFunction · 0.85

Calls 3

translate_operandFunction · 0.85
binding_strengthMethod · 0.80
into_astMethod · 0.80

Tested by

no test coverage detected