MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / plan_bool_or

Method plan_bool_or

src/sql/src/plan/transform_ast.rs:345–374  ·  view source on GitHub ↗
(
        &mut self,
        expr: Expr<Aug>,
        filter: Option<Box<Expr<Aug>>>,
        distinct: bool,
        over: Option<WindowSpec<Aug>>,
    )

Source from the content-addressed store, hash-verified

343 }
344
345 fn plan_bool_or(
346 &mut self,
347 expr: Expr<Aug>,
348 filter: Option<Box<Expr<Aug>>>,
349 distinct: bool,
350 over: Option<WindowSpec<Aug>>,
351 ) -> Expr<Aug> {
352 // The code below converts `bool_or(x)`z into:
353 //
354 // sum((x OR false)::int4) > 0
355 //
356 // It is tempting to use `count` instead, but count does not return NULL
357 // when all input values are NULL, as required.
358 //
359 // The `(x OR false)` expression implicitly casts `x` to `bool` without
360 // changing its logical value. It is tempting to use `x::bool` instead,
361 // but that performs an explicit cast, and to match PostgreSQL we must
362 // perform only an implicit cast.
363 let sum = self.plan_agg(
364 self.scx
365 .dangerous_resolve_name(vec![PG_CATALOG_SCHEMA, "sum"]),
366 expr.or(Expr::Value(Value::Boolean(false)))
367 .cast(self.int32_data_type()),
368 vec![],
369 filter,
370 distinct,
371 over,
372 );
373 sum.gt(Expr::Value(Value::Number(0.to_string())))
374 }
375
376 fn rewrite_function(&mut self, func: &Function<Aug>) -> Option<(Ident, Expr<Aug>)> {
377 if let Function {

Callers 1

rewrite_functionMethod · 0.80

Calls 9

plan_aggMethod · 0.80
castMethod · 0.80
int32_data_typeMethod · 0.80
gtMethod · 0.80
ValueInterface · 0.50
BooleanClass · 0.50
orMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected