-
Notifications
You must be signed in to change notification settings - Fork 582
Add calculated predicate search plumbing #6721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ use quickwit_directories::write_hotcache; | |
| use quickwit_doc_mapper::NamedField; | ||
| use quickwit_doc_mapper::tag_pruning::append_to_tag_set; | ||
| use quickwit_proto::search::{ListFieldsEntry, ListFieldsMetadata, ListFieldsType}; | ||
| use tantivy::index::FieldMetadata; | ||
| use tantivy::index::{FieldMetadata, SegmentComponent}; | ||
| use tantivy::schema::{FieldType, Type}; | ||
| use tantivy::{InvertedIndexReader, ReloadPolicy, SegmentMeta}; | ||
| use tokio::runtime::Handle; | ||
|
|
@@ -187,15 +187,24 @@ fn list_split_files( | |
| scratch_directory: &TempDirectory, | ||
| ) -> io::Result<Vec<PathBuf>> { | ||
| let mut split_files = vec![scratch_directory.path().join("meta.json")]; | ||
| let segment_components = [ | ||
| SegmentComponent::Postings, | ||
| SegmentComponent::Positions, | ||
| SegmentComponent::Terms, | ||
| SegmentComponent::Store, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above. |
||
| SegmentComponent::FastFields, | ||
| SegmentComponent::FieldNorms, | ||
| SegmentComponent::Delete, | ||
| ]; | ||
|
|
||
| // list the segment files | ||
| for segment_meta in segment_metas { | ||
| for relative_path in segment_meta.list_files() { | ||
| for segment_component in &segment_components { | ||
| let relative_path = segment_meta.relative_path(segment_component.clone()); | ||
| let filepath = scratch_directory.path().join(relative_path); | ||
| if filepath.try_exists()? { | ||
| // If the file is missing, this is fine. | ||
| // segment_meta.list_files() may actually returns files that | ||
| // may not exist. | ||
| // Segment metadata may reference optional files that do not exist. | ||
| split_files.push(filepath); | ||
| } | ||
| } | ||
|
|
@@ -361,6 +370,7 @@ fn tantivy_type_to_list_field_type(typ: Type) -> ListFieldsType { | |
| Type::Json => ListFieldsType::Json, | ||
| Type::Str => ListFieldsType::Str, | ||
| Type::U64 => ListFieldsType::U64, | ||
| Type::Custom => ListFieldsType::Custom, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,10 +200,85 @@ enum ListFieldsType { | |
| BYTES = 7; | ||
| IP_ADDR = 8; | ||
| JSON = 9; | ||
| CUSTOM = 10; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this in protobuf land? Shouldn't we just return an error or panic before? |
||
| } | ||
|
|
||
| // -- Search ------------------- | ||
|
|
||
| // A predicate expression evaluated against fast-field values on each leaf | ||
| // segment. The expression is lowered to tantivy::query::CalculatedPredicateQuery | ||
| // by the search leaf. | ||
| message CalculatedPredicate { | ||
| CalculatedPredicateExpr expr = 1; | ||
| } | ||
|
|
||
| message CalculatedPredicateExpr { | ||
| oneof node { | ||
| CalculatedPredicateLiteral literal = 1; | ||
| // Fast-field name read by the calculated predicate query. | ||
| string variable = 2; | ||
| CalculatedPredicateFuncCall func_call = 3; | ||
| } | ||
| } | ||
|
|
||
| message CalculatedPredicateLiteral { | ||
| oneof value { | ||
| int64 int_value = 1; | ||
| uint64 uint_value = 2; | ||
| // IEEE-754 bits for an f64 literal. This keeps SearchRequest Eq/Hash-safe. | ||
| fixed64 double_value_bits = 3; | ||
| string string_value = 4; | ||
| bool bool_value = 5; | ||
| } | ||
| } | ||
|
|
||
| message CalculatedPredicateFuncCall { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The query ast is expressed using json today. I don't think it we need to change this? |
||
| enum Function { | ||
| FUNCTION_UNSPECIFIED = 0; | ||
| FUNCTION_ABS = 1; | ||
| FUNCTION_AND = 2; | ||
| FUNCTION_CEIL = 3; | ||
| FUNCTION_CONCAT = 4; | ||
| FUNCTION_ADD = 5; | ||
| FUNCTION_DIVIDE = 6; | ||
| FUNCTION_EQ = 7; | ||
| FUNCTION_FLOOR = 8; | ||
| FUNCTION_GT = 9; | ||
| FUNCTION_GT_EQ = 10; | ||
| FUNCTION_IF = 11; | ||
| FUNCTION_INT_MOD = 12; | ||
| FUNCTION_LEFT = 13; | ||
| FUNCTION_LT = 14; | ||
| FUNCTION_LT_EQ = 15; | ||
| FUNCTION_IS_NOT_NULL = 16; | ||
| FUNCTION_IS_NULL = 17; | ||
| FUNCTION_LOWER = 18; | ||
| FUNCTION_MAX = 19; | ||
| FUNCTION_MIN = 20; | ||
| FUNCTION_MULTIPLY = 21; | ||
| FUNCTION_NEQ = 22; | ||
| FUNCTION_NOT = 23; | ||
| FUNCTION_OR = 24; | ||
| FUNCTION_POW = 25; | ||
| FUNCTION_SQRT = 26; | ||
| FUNCTION_REGEXP_EXTRACT = 27; | ||
| FUNCTION_REGEXP_LIKE = 28; | ||
| FUNCTION_RIGHT = 29; | ||
| FUNCTION_ROUND = 30; | ||
| FUNCTION_SPLIT_AFTER = 31; | ||
| FUNCTION_SPLIT_BEFORE = 32; | ||
| FUNCTION_SUBTRACT = 33; | ||
| FUNCTION_SUBSTRING = 34; | ||
| FUNCTION_SUBSTRING_COUNT = 35; | ||
| FUNCTION_TEXT_JOIN = 36; | ||
| FUNCTION_TRIM = 37; | ||
| FUNCTION_UPPER = 38; | ||
| } | ||
|
|
||
| Function function = 1; | ||
| repeated CalculatedPredicateExpr args = 2; | ||
| } | ||
|
|
||
| message SearchRequest { | ||
| // Index ID patterns | ||
| repeated string index_id_patterns = 1; | ||
|
|
@@ -280,6 +355,9 @@ message SearchRequest { | |
| // Scheduling priority for leaf search execution. Negative values are allowed, | ||
| // and lower values have higher priority. Callers that omit it get priority 0. | ||
| int32 priority = 21; | ||
|
|
||
| // Predicate expression evaluated by Tantivy against fast fields on each leaf. | ||
| optional CalculatedPredicate calculated_predicate = 22; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand how this can make sense with the existing query_ast. |
||
| } | ||
|
|
||
| enum CountHits { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understadn what this is about?
You were hit by the new tantivy plugin change that the list_files method does not exist anymore? I think there is another utility to do that computation no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we DO need to modify tantivy.