Skip to content

Commit

Permalink
feat(es): add format support for RangeQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
etolbakov authored Jul 9, 2024
1 parent fc0c52e commit 32b0ee1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
14 changes: 12 additions & 2 deletions quickwit/quickwit-jaeger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()]
);
Expand Down Expand Up @@ -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()]
);
Expand Down Expand Up @@ -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()]
);
Expand Down Expand Up @@ -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()]
);
Expand Down Expand Up @@ -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()]
);
Expand Down Expand Up @@ -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()]
);
Expand Down Expand Up @@ -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(),
]
Expand Down
12 changes: 10 additions & 2 deletions quickwit/quickwit-query/src/elastic_query_dsl/range_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub struct RangeQueryParams {
lte: Option<JsonLiteral>,
#[serde(default)]
boost: Option<NotNaNf32>,
// Currently NO-OP (see #5109)
#[serde(default)]
format: Option<JsonLiteral>,
}
Expand All @@ -56,7 +55,7 @@ impl ConvertableToQueryAst for RangeQuery {
lt,
lte,
boost,
format: _,
format,
} = self.value;
let range_query_ast = crate::query_ast::RangeQuery {
field,
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion quickwit/quickwit-query/src/query_ast/range_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct RangeQuery {
pub field: String,
pub lower_bound: Bound<JsonLiteral>,
pub upper_bound: Bound<JsonLiteral>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub format: Option<String>,
}

struct NumericalBoundaries {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions quickwit/quickwit-query/src/query_ast/user_input_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
1 change: 1 addition & 0 deletions quickwit/quickwit-search/src/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 32b0ee1

Please sign in to comment.