vortex-array 0.68.0

Vortex in memory columnar data format
Documentation
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use crate::expr::Expression;
use crate::scalar_fn::fns::binary::Binary;
use crate::scalar_fn::fns::operators::Operator;

/// Converting an expression to a conjunctive normal form can lead to a large number of expression
/// nodes.
/// For now, we will just extract the conjuncts from the expression, and return a vector of conjuncts.
/// We could look at try cnf with a size cap and otherwise return the original conjuncts.
pub fn conjuncts(expr: &Expression) -> Vec<Expression> {
    let mut conjuncts = vec![];
    conjuncts_impl(expr, &mut conjuncts);
    if conjuncts.is_empty() {
        conjuncts.push(expr.clone());
    }
    conjuncts
}

fn conjuncts_impl(expr: &Expression, conjuncts: &mut Vec<Expression>) {
    if let Some(operator) = expr.as_opt::<Binary>()
        && *operator == Operator::And
    {
        conjuncts_impl(expr.child(0), conjuncts);
        conjuncts_impl(expr.child(1), conjuncts);
    } else {
        conjuncts.push(expr.clone())
    }
}