Skip to content
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

feat(es): respect format parameter in range query #5208

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 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 @@ -18,8 +18,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use std::ops::Bound;
use std::str::FromStr;

use serde::Deserialize;
use quickwit_datetime::{DateTimeInputFormat, parse_date_time_str, StrptimeParser};

use crate::elastic_query_dsl::one_field_map::OneFieldMap;
use crate::elastic_query_dsl::ConvertableToQueryAst;
Expand All @@ -40,7 +42,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,8 +57,20 @@ impl ConvertableToQueryAst for RangeQuery {
lt,
lte,
boost,
format: _,
format,
} = self.value;
let (gt, gte, lt, lte) =
if let Some(JsonLiteral::String(fmt)) = format {
(
gt.map(|v| parse_and_convert(v, &fmt)).transpose()?,
gte.map(|v| parse_and_convert(v, &fmt)).transpose()?,
lt.map(|v| parse_and_convert(v, &fmt)).transpose()?,
lte.map(|v| parse_and_convert(v, &fmt)).transpose()?,
)
} else {
(gt, gte, lt, lte)
};

let range_query_ast = crate::query_ast::RangeQuery {
field,
lower_bound: match (gt, gte) {
Expand All @@ -81,3 +94,15 @@ impl ConvertableToQueryAst for RangeQuery {
Ok(ast.boost(boost))
}
}


fn parse_and_convert(value: JsonLiteral, fmt: &str) -> anyhow::Result<JsonLiteral> {
etolbakov marked this conversation as resolved.
Show resolved Hide resolved
if let JsonLiteral::String(s) = value {
let date_format = DateTimeInputFormat::from_str(fmt).unwrap();
let date_time = parse_date_time_str(&s, &[date_format]).unwrap();
Ok(JsonLiteral::String(date_time.to_string())) // TODO no `to_string` method
} else {
dbg!(value.clone());
Ok(value)
}
}
Loading