Skip to content

Commit

Permalink
Datum based like kernels (apache#4595)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Aug 24, 2023
1 parent 90449ff commit 20ea507
Show file tree
Hide file tree
Showing 6 changed files with 501 additions and 717 deletions.
12 changes: 5 additions & 7 deletions arrow-flight/src/sql/metadata/db_schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use arrow_array::{builder::StringBuilder, ArrayRef, RecordBatch, Scalar, StringA
use arrow_ord::cmp::eq;
use arrow_schema::{DataType, Field, Schema, SchemaRef};
use arrow_select::{filter::filter_record_batch, take::take};
use arrow_string::like::like_utf8_scalar;
use arrow_string::like::{like, like_utf8_scalar};
use once_cell::sync::Lazy;

use super::lexsort_to_indices;
Expand Down Expand Up @@ -122,15 +122,13 @@ impl GetDbSchemasBuilder {

if let Some(db_schema_filter_pattern) = db_schema_filter_pattern {
// use like kernel to get wildcard matching
filters.push(like_utf8_scalar(
&db_schema_name,
&db_schema_filter_pattern,
)?)
let scalar = StringArray::new_scalar(db_schema_filter_pattern);
filters.push(like(&db_schema_name, &scalar)?)
}

if let Some(catalog_filter_name) = catalog_filter {
let scalar = StringArray::from_iter_values([catalog_filter_name]);
filters.push(eq(&catalog_name, &Scalar::new(&scalar))?);
let scalar = StringArray::new_scalar(catalog_filter_name);
filters.push(eq(&catalog_name, &scalar)?);
}

// `AND` any filters together
Expand Down
20 changes: 8 additions & 12 deletions arrow-flight/src/sql/metadata/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use arrow_array::{ArrayRef, RecordBatch, Scalar, StringArray};
use arrow_ord::cmp::eq;
use arrow_schema::{DataType, Field, Schema, SchemaRef};
use arrow_select::{filter::filter_record_batch, take::take};
use arrow_string::like::like_utf8_scalar;
use arrow_string::like::{like, like_utf8_scalar};
use once_cell::sync::Lazy;

use super::lexsort_to_indices;
Expand Down Expand Up @@ -184,16 +184,13 @@ impl GetTablesBuilder {
let mut filters = vec![];

if let Some(catalog_filter_name) = catalog_filter {
let scalar = StringArray::from_iter_values([catalog_filter_name]);
filters.push(eq(&catalog_name, &Scalar::new(&scalar))?);
let scalar = StringArray::new_scalar(catalog_filter_name);
filters.push(eq(&catalog_name, &scalar)?);
}

let tt_filter = table_types_filter
.into_iter()
.map(|tt| {
let scalar = StringArray::from_iter_values([tt]);
eq(&table_type, &Scalar::new(&scalar))
})
.map(|tt| eq(&table_type, &StringArray::new_scalar(tt)))
.collect::<std::result::Result<Vec<_>, _>>()?
.into_iter()
// We know the arrays are of same length as they are produced fromn the same root array
Expand All @@ -204,15 +201,14 @@ impl GetTablesBuilder {

if let Some(db_schema_filter_pattern) = db_schema_filter_pattern {
// use like kernel to get wildcard matching
filters.push(like_utf8_scalar(
&db_schema_name,
&db_schema_filter_pattern,
)?)
let scalar = StringArray::new_scalar(db_schema_filter_pattern);
filters.push(like(&db_schema_name, &scalar)?)
}

if let Some(table_name_filter_pattern) = table_name_filter_pattern {
// use like kernel to get wildcard matching
filters.push(like_utf8_scalar(&table_name, &table_name_filter_pattern)?)
let scalar = StringArray::new_scalar(table_name_filter_pattern);
filters.push(like(&table_name, &scalar)?)
}

let batch = if let Some(table_schema) = table_schema {
Expand Down
1 change: 1 addition & 0 deletions arrow-string/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
pub mod concat_elements;
pub mod length;
pub mod like;
mod predicate;
pub mod regexp;
pub mod substring;
Loading

0 comments on commit 20ea507

Please sign in to comment.