-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: kleene_or, kleene_and, and restore SQL semantics (#1284)
I noticed that our row filters disagreed with DuckDB's semantics which is SQL semantics, in particular `where true or null` _keeps_ the row (we filtered it). cc: @robert3005 we'll probably conflict on #1272
- Loading branch information
Showing
9 changed files
with
264 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,48 @@ | ||
use arrow_arith::boolean; | ||
use arrow_array::cast::AsArray as _; | ||
use arrow_array::{Array as _, BooleanArray}; | ||
use arrow_schema::ArrowError; | ||
use vortex_error::VortexResult; | ||
|
||
use crate::array::BoolArray; | ||
use crate::arrow::FromArrowArray as _; | ||
use crate::compute::{AndFn, OrFn}; | ||
use crate::{Array, IntoCanonical}; | ||
|
||
impl OrFn for BoolArray { | ||
fn or(&self, array: &Array) -> VortexResult<Array> { | ||
impl BoolArray { | ||
/// Lift an Arrow binary boolean kernel function to Vortex arrays. | ||
fn lift_arrow<F>(&self, arrow_fun: F, other: &Array) -> VortexResult<Array> | ||
where | ||
F: FnOnce(&BooleanArray, &BooleanArray) -> Result<BooleanArray, ArrowError>, | ||
{ | ||
let lhs = self.clone().into_canonical()?.into_arrow()?; | ||
let lhs = lhs.as_boolean(); | ||
|
||
let rhs = array.clone().into_canonical()?.into_arrow()?; | ||
let rhs = other.clone().into_canonical()?.into_arrow()?; | ||
let rhs = rhs.as_boolean(); | ||
|
||
let array = boolean::or(lhs, rhs)?; | ||
let array = arrow_fun(lhs, rhs)?; | ||
|
||
Ok(Array::from_arrow(&array, true)) | ||
Ok(Array::from_arrow(&array, array.is_nullable())) | ||
} | ||
} | ||
|
||
impl AndFn for BoolArray { | ||
fn and(&self, array: &Array) -> VortexResult<Array> { | ||
let lhs = self.clone().into_canonical()?.into_arrow()?; | ||
let lhs = lhs.as_boolean(); | ||
impl OrFn for BoolArray { | ||
fn or(&self, array: &Array) -> VortexResult<Array> { | ||
self.lift_arrow(boolean::or, array) | ||
} | ||
|
||
let rhs = array.clone().into_canonical()?.into_arrow()?; | ||
let rhs = rhs.as_boolean(); | ||
fn or_kleene(&self, array: &Array) -> VortexResult<Array> { | ||
self.lift_arrow(boolean::or_kleene, array) | ||
} | ||
} | ||
|
||
let array = boolean::and(lhs, rhs)?; | ||
impl AndFn for BoolArray { | ||
fn and(&self, array: &Array) -> VortexResult<Array> { | ||
self.lift_arrow(boolean::and, array) | ||
} | ||
|
||
Ok(Array::from_arrow(&array, true)) | ||
fn and_kleene(&self, array: &Array) -> VortexResult<Array> { | ||
self.lift_arrow(boolean::and_kleene, array) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.