From 32b0ee1a5493bebf4abe36cdd21b76d0f388307a Mon Sep 17 00:00:00 2001 From: Eugene Tolbakov Date: Tue, 9 Jul 2024 10:42:09 +0100 Subject: [PATCH] feat(es): add format support for RangeQuery --- quickwit/quickwit-jaeger/src/lib.rs | 14 ++++++++++++-- .../src/elastic_query_dsl/range_query.rs | 12 ++++++++++-- .../quickwit-query/src/query_ast/range_query.rs | 4 +++- .../src/query_ast/user_input_query.rs | 1 + quickwit/quickwit-search/src/leaf.rs | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/quickwit/quickwit-jaeger/src/lib.rs b/quickwit/quickwit-jaeger/src/lib.rs index fe663cd4d8c..104a87e4d3d 100644 --- a/quickwit/quickwit-jaeger/src/lib.rs +++ b/quickwit/quickwit-jaeger/src/lib.rs @@ -682,6 +682,7 @@ fn build_search_query( field: "span_start_timestamp_nanos".to_string(), lower_bound: Bound::Unbounded, upper_bound: Bound::Unbounded, + format: None, }; if let Some(min_span_start_timestamp_secs) = min_span_start_timestamp_secs_opt { @@ -711,6 +712,7 @@ fn build_search_query( field: "span_duration_millis".to_string(), lower_bound: Bound::Unbounded, upper_bound: Bound::Unbounded, + format: None, }; if let Some(min_span_duration_millis) = min_span_duration_millis_opt { @@ -1500,7 +1502,8 @@ mod tests { vec![RangeQuery { field: "span_start_timestamp_nanos".to_string(), lower_bound: Bound::Included("1970-01-01T00:00:03Z".to_string().into()), - upper_bound: Bound::Unbounded + upper_bound: Bound::Unbounded, + format: None, } .into()] ); @@ -1529,6 +1532,7 @@ mod tests { field: "span_start_timestamp_nanos".to_string(), lower_bound: Bound::Unbounded, upper_bound: Bound::Included("1970-01-01T00:00:33Z".to_string().into()), + format: None, } .into()] ); @@ -1557,6 +1561,7 @@ mod tests { field: "span_start_timestamp_nanos".to_string(), lower_bound: Bound::Included("1970-01-01T00:00:03Z".to_string().into()), upper_bound: Bound::Included("1970-01-01T00:00:33Z".to_string().into()), + format: None, } .into()] ); @@ -1584,7 +1589,8 @@ mod tests { vec![RangeQuery { field: "span_duration_millis".to_string(), lower_bound: Bound::Included(7u64.into()), - upper_bound: Bound::Unbounded + upper_bound: Bound::Unbounded, + format: None, } .into()] ); @@ -1613,6 +1619,7 @@ mod tests { field: "span_duration_millis".to_string(), lower_bound: Bound::Unbounded, upper_bound: Bound::Included(77u64.into()), + format: None, } .into()] ); @@ -1641,6 +1648,7 @@ mod tests { field: "span_duration_millis".to_string(), lower_bound: Bound::Included(7u64.into()), upper_bound: Bound::Included(77u64.into()), + format: None, } .into()] ); @@ -1875,12 +1883,14 @@ mod tests { field: "span_start_timestamp_nanos".to_string(), lower_bound: Bound::Included("1970-01-01T00:00:03Z".to_string().into()), upper_bound: Bound::Included("1970-01-01T00:00:33Z".to_string().into()), + format: None, } .into(), RangeQuery { field: "span_duration_millis".to_string(), lower_bound: Bound::Included(7u64.into()), upper_bound: Bound::Included(77u64.into()), + format: None, } .into(), ] diff --git a/quickwit/quickwit-query/src/elastic_query_dsl/range_query.rs b/quickwit/quickwit-query/src/elastic_query_dsl/range_query.rs index 88b9df05c11..cb3f151080c 100644 --- a/quickwit/quickwit-query/src/elastic_query_dsl/range_query.rs +++ b/quickwit/quickwit-query/src/elastic_query_dsl/range_query.rs @@ -40,7 +40,6 @@ pub struct RangeQueryParams { lte: Option, #[serde(default)] boost: Option, - // Currently NO-OP (see #5109) #[serde(default)] format: Option, } @@ -56,7 +55,7 @@ impl ConvertableToQueryAst for RangeQuery { lt, lte, boost, - format: _, + format, } = self.value; let range_query_ast = crate::query_ast::RangeQuery { field, @@ -76,6 +75,15 @@ impl ConvertableToQueryAst for RangeQuery { (None, Some(lte)) => Bound::Included(lte), (None, None) => Bound::Unbounded, }, + format: match format { + None => None, + Some(v) => { + match v { + JsonLiteral::String(s) => Some(s), + _ => None + } + } + }, }; let ast: QueryAst = range_query_ast.into(); Ok(ast.boost(boost)) diff --git a/quickwit/quickwit-query/src/query_ast/range_query.rs b/quickwit/quickwit-query/src/query_ast/range_query.rs index 225c26fa815..a95961e8bdc 100644 --- a/quickwit/quickwit-query/src/query_ast/range_query.rs +++ b/quickwit/quickwit-query/src/query_ast/range_query.rs @@ -38,6 +38,8 @@ pub struct RangeQuery { pub field: String, pub lower_bound: Bound, pub upper_bound: Bound, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub format: Option, } struct NumericalBoundaries { @@ -235,7 +237,7 @@ impl BuildTantivyAst for RangeQuery { "range queries are only supported for fast fields. (`{}` is not a fast field)", field_entry.name() ))); - } + } Ok(match field_entry.field_type() { tantivy::schema::FieldType::Str(_) => { return Err(InvalidQuery::RangeQueryNotSupportedForField { diff --git a/quickwit/quickwit-query/src/query_ast/user_input_query.rs b/quickwit/quickwit-query/src/query_ast/user_input_query.rs index 5f02f7553cb..64f425ddfdb 100644 --- a/quickwit/quickwit-query/src/query_ast/user_input_query.rs +++ b/quickwit/quickwit-query/src/query_ast/user_input_query.rs @@ -151,6 +151,7 @@ fn convert_user_input_ast_to_query_ast( field, lower_bound: convert_bound(lower), upper_bound: convert_bound(upper), + format: None, }; Ok(range_query.into()) } diff --git a/quickwit/quickwit-search/src/leaf.rs b/quickwit/quickwit-search/src/leaf.rs index 5f73757ea56..db3bfc98323 100644 --- a/quickwit/quickwit-search/src/leaf.rs +++ b/quickwit/quickwit-search/src/leaf.rs @@ -652,6 +652,7 @@ fn remove_redundant_timestamp_range( upper_bound: map_bound(final_end_timestamp, |bound| { bound.into_timestamp_nanos().into() }), + format: None, }; new_ast = if let QueryAst::Bool(mut bool_query) = new_ast { if bool_query.must.is_empty()