Skip to content

Commit

Permalink
Add option to use bloom filters on string arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngalstyan4 committed Nov 25, 2024
1 parent 944ed0c commit b207077
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lantern_extras/src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,36 @@ fn array_to_bloom_bigint(arr: Vec<i64>) -> Bloom {
return array_to_bloom(arr);
}

#[pg_extern(requires = [Bloom])]
fn elem_in_bloom(elem: i32, bloom: Bloom) -> bool {
let bloom: BloomFilter = bloom.into();
bloom.contains(&elem)
#[pg_extern(immutable, parallel_safe, name = "array_to_bloom")]
fn array_to_bloom_text(arr: Vec<String>) -> Bloom {
return array_to_bloom(arr);
}

extension_sql!(
r#"
CREATE CAST (smallint[] AS bloom) WITH FUNCTION array_to_bloom(smallint[]);
CREATE CAST (integer[] AS bloom) WITH FUNCTION array_to_bloom(integer[]);
CREATE CAST (bigint[] AS bloom) WITH FUNCTION array_to_bloom(bigint[]);
CREATE CAST (text[] AS bloom) WITH FUNCTION array_to_bloom(text[]);
"#,
name = "bloom_type_casts",
requires = [
Bloom,
array_to_bloom_smallint,
array_to_bloom_integer,
array_to_bloom_bigint,
array_to_bloom_text,
]
);

#[pg_extern(immutable, parallel_safe, name = "elem_in_bloom", requires = [Bloom])]
fn elem_in_bloom_numeric(elem: i32, bloom: Bloom) -> bool {
let bloom: BloomFilter = bloom.into();
bloom.contains(&elem)
}

#[pg_extern(immutable, parallel_safe, name = "elem_in_bloom", requires = [Bloom])]
fn elem_in_bloom_text(elem: String, bloom: Bloom) -> bool {
let bloom: BloomFilter = bloom.into();
bloom.contains(&elem)
}
2 changes: 1 addition & 1 deletion lantern_extras/src/bm25_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pgrx::extension_sql_file;

extension_sql_file!("./bm25_api.sql", requires = [Bloom]);
extension_sql_file!("./bm25_api.sql", requires = [Bloom, "bloom_type_casts"]);

#[cfg(any(test, feature = "pg_test"))]
#[pgrx::pg_schema]
Expand Down

0 comments on commit b207077

Please sign in to comment.