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

Fix fmt. #3599

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 12 additions & 4 deletions quickwit/quickwit-actors/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,13 @@ impl Scheduler {

/// Schedules a Timeout event callback if necessary.
fn schedule_next_timeout(&mut self) {
let Some(scheduler_client) = self.scheduler_client() else { return };
let Some(scheduler_client) = self.scheduler_client() else {
return;
};
let simulated_now = self.simulated_now();
let Some(next_deadline) = self.next_event_deadline() else { return; };
let Some(next_deadline) = self.next_event_deadline() else {
return;
};
let timeout: Duration = if next_deadline <= simulated_now {
// This should almost never happen, because we supposedly triggered
// all pending events.
Expand Down Expand Up @@ -320,14 +324,18 @@ impl Scheduler {
/// - no message is queued for processing, no initialize or no finalize
/// is being processed.
fn advance_time_if_necessary(&mut self) {
let Some(scheduler_client) = self.scheduler_client() else { return; };
let Some(scheduler_client) = self.scheduler_client() else {
return;
};
if !scheduler_client.time_is_accelerated() {
return;
}
if scheduler_client.is_advance_time_forbidden() {
return;
}
let Some(advance_to_instant) = self.next_event_deadline() else { return; };
let Some(advance_to_instant) = self.next_event_deadline() else {
return;
};
let now = self.simulated_now();
if let Some(time_shift) = advance_to_instant.checked_duration_since(now) {
self.simulated_time_shift += time_shift;
Expand Down
15 changes: 12 additions & 3 deletions quickwit/quickwit-cluster/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,10 @@ mod tests {
assert_eq!(events.len(), 1);

let ClusterChange::Add(_node) = events[0].clone() else {
panic!("Expected `ClusterChange::Add` event, got `{:?}`.", events[0]);
panic!(
"Expected `ClusterChange::Add` event, got `{:?}`.",
events[0]
);
};

let events = compute_cluster_change_events(
Expand Down Expand Up @@ -765,7 +768,10 @@ mod tests {
assert_eq!(events.len(), 1);

let ClusterChange::Update(_node) = events[0].clone() else {
panic!("Expected `ClusterChange::Update` event, got `{:?}`.", events[0]);
panic!(
"Expected `ClusterChange::Update` event, got `{:?}`.",
events[0]
);
};

// Node left the cluster.
Expand All @@ -781,7 +787,10 @@ mod tests {
assert_eq!(events.len(), 1);

let ClusterChange::Remove(_node) = events[0].clone() else {
panic!("Expected `ClusterChange::Remove` event, got `{:?}`.", events[0]);
panic!(
"Expected `ClusterChange::Remove` event, got `{:?}`.",
events[0]
);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ fn validate_timestamp_field(
timestamp_field_path: &str,
mapping_root_node: &MappingNode,
) -> anyhow::Result<()> {
let Some(timestamp_field_type) = mapping_root_node.find_field_mapping_type(timestamp_field_path) else {
let Some(timestamp_field_type) =
mapping_root_node.find_field_mapping_type(timestamp_field_path)
else {
bail!("Could not find timestamp field `{timestamp_field_path}` in field mappings.");
};
if let FieldMappingType::DateTime(date_time_option, cardinality) = &timestamp_field_type {
Expand Down Expand Up @@ -1350,8 +1352,11 @@ mod tests {

{
let json_field = schema.get_field("json_field").unwrap();
let FieldType::JsonObject(json_options) = schema.get_field_entry(json_field).field_type()
else { panic!() };
let FieldType::JsonObject(json_options) =
schema.get_field_entry(json_field).field_type()
else {
panic!()
};
let text_indexing_options = json_options.get_text_indexing_options().unwrap();
assert_eq!(
text_indexing_options.tokenizer(),
Expand All @@ -1366,7 +1371,9 @@ mod tests {
{
let text_field = schema.get_field("text_field").unwrap();
let FieldType::Str(text_options) = schema.get_field_entry(text_field).field_type()
else { panic!() };
else {
panic!()
};
assert_eq!(
text_options.get_indexing_options().unwrap().tokenizer(),
super::QuickwitTextTokenizer::Default.get_name()
Expand Down
10 changes: 8 additions & 2 deletions quickwit/quickwit-doc-mapper/src/doc_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ mod tests {
let json_doc = br#"{"title": "hello", "body": "world"}"#;
doc_mapper.doc_from_json_bytes(json_doc).unwrap();

let DocParsingError::NotJsonObject(json_doc_sample) = doc_mapper.doc_from_json_bytes(br#"Not a JSON object"#).unwrap_err() else {
let DocParsingError::NotJsonObject(json_doc_sample) = doc_mapper
.doc_from_json_bytes(br#"Not a JSON object"#)
.unwrap_err()
else {
panic!("Expected `DocParsingError::NotJsonObject` error");
};
assert_eq!(json_doc_sample, "Not a JSON object...");
Expand All @@ -261,7 +264,10 @@ mod tests {
let json_doc = r#"{"title": "hello", "body": "world"}"#;
doc_mapper.doc_from_json_str(json_doc).unwrap();

let DocParsingError::NotJsonObject(json_doc_sample) = doc_mapper.doc_from_json_str(r#"Not a JSON object"#).unwrap_err() else {
let DocParsingError::NotJsonObject(json_doc_sample) = doc_mapper
.doc_from_json_str(r#"Not a JSON object"#)
.unwrap_err()
else {
panic!("Expected `DocParsingError::NotJsonObject` error");
};
assert_eq!(json_doc_sample, "Not a JSON object...");
Expand Down
49 changes: 27 additions & 22 deletions quickwit/quickwit-doc-mapper/src/routing_expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,31 +235,36 @@ impl FromStr for InnerRoutingExpr {
fn convert_ast(ast: Vec<expression_dsl::ExpressionAst>) -> anyhow::Result<InnerRoutingExpr> {
use expression_dsl::{Argument, ExpressionAst};

let mut result = ast.into_iter().map(|ast_elem|
match ast_elem {
let mut result = ast
.into_iter()
.map(|ast_elem| match ast_elem {
ExpressionAst::Field(field_name) => Ok(InnerRoutingExpr::Field(field_name)),
ExpressionAst::Function { name, mut args } => {
match &*name {
"hash_mod" => {
if args.len() !=2 {
anyhow::bail!("Invalid arguments for `hash_mod`: expected 2 arguments, found {}", args.len());
}

let Argument::Expression(fields) = args.remove(0) else {
anyhow::bail!("Invalid 1st argument for `hash_mod`: expected expression");
};

let Argument::Number(modulo) = args.remove(0) else {
anyhow::bail!("Invalid 2nd argument for `hash_mod`: expected number");
};

Ok(InnerRoutingExpr::Modulo(Box::new(convert_ast(fields)?), modulo))
},
_ => anyhow::bail!("Unknown function `{}`", name),
ExpressionAst::Function { name, mut args } => match &*name {
"hash_mod" => {
if args.len() != 2 {
anyhow::bail!(
"Invalid arguments for `hash_mod`: expected 2 arguments, found {}",
args.len()
);
}

let Argument::Expression(fields) = args.remove(0) else {
anyhow::bail!("Invalid 1st argument for `hash_mod`: expected expression");
};

let Argument::Number(modulo) = args.remove(0) else {
anyhow::bail!("Invalid 2nd argument for `hash_mod`: expected number");
};

Ok(InnerRoutingExpr::Modulo(
Box::new(convert_ast(fields)?),
modulo,
))
}
_ => anyhow::bail!("Unknown function `{}`", name),
},
}
).collect::<Result<Vec<_>, _>>()?;
})
.collect::<Result<Vec<_>, _>>()?;
if result.is_empty() {
Ok(InnerRoutingExpr::default())
} else if result.len() == 1 {
Expand Down
3 changes: 2 additions & 1 deletion quickwit/quickwit-indexing/src/actors/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ impl Indexer {
batch_parent_span,
indexing_permit,
..
}) = self.indexing_workbench_opt.take() else {
}) = self.indexing_workbench_opt.take()
else {
return Ok(());
};
// Dropping the indexing permit explicitly here for enhanced readability.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ impl FileBackedIndex {
for &split_id in split_ids {
// Check for the existence of split.
let Some(metadata) = self.splits.get_mut(split_id) else {
split_not_found_ids.push(split_id.to_string());
continue;
};
split_not_found_ids.push(split_id.to_string());
continue;
};
if metadata.split_state == SplitState::Staged {
metadata.split_state = SplitState::Published;
metadata.update_timestamp = now_timestamp;
Expand Down
9 changes: 8 additions & 1 deletion quickwit/quickwit-query/src/elastic_query_dsl/match_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ mod tests {
},
};
let ast = match_query.convert_to_query_ast().unwrap();
let QueryAst::FullText(FullTextQuery { field, text, params }) = ast else { panic!() } ;
let QueryAst::FullText(FullTextQuery {
field,
text,
params,
}) = ast
else {
panic!()
};
assert_eq!(field, "body");
assert_eq!(text, "hello");
assert_eq!(
Expand Down
4 changes: 3 additions & 1 deletion quickwit/quickwit-query/src/elastic_query_dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ mod tests {
}
}"#;
let query_dsl = serde_json::from_str(term_query_json).unwrap();
let ElasticQueryDsl(ElasticQueryDslInner::Term(term_query)) = query_dsl else { panic!() };
let ElasticQueryDsl(ElasticQueryDslInner::Term(term_query)) = query_dsl else {
panic!()
};
assert_eq!(
&term_query,
&term_query_from_field_value("product_id", "61809")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ impl<'de, V: Deserialize<'de>> Visitor<'de> for OneFieldMapVisitor<V> {
}
}
let Some((key, val)) = map.next_entry()? else {
return Err(serde::de::Error::custom("Expected a single field. Got none."));
return Err(serde::de::Error::custom(
"Expected a single field. Got none.",
));
};
if let Some(second_key) = map.next_key::<String>()? {
return Err(serde::de::Error::custom(format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ mod tests {
default_operator: crate::BooleanOperand::Or,
boost: None,
};
let QueryAst::UserInput(user_input_query) = query_string_query.convert_to_query_ast().unwrap() else {
let QueryAst::UserInput(user_input_query) =
query_string_query.convert_to_query_ast().unwrap()
else {
panic!();
};
assert_eq!(user_input_query.default_operator, BooleanOperand::Or);
Expand All @@ -87,7 +89,9 @@ mod tests {
default_operator: crate::BooleanOperand::And,
boost: None,
};
let QueryAst::UserInput(user_input_query) = query_string_query.convert_to_query_ast().unwrap() else {
let QueryAst::UserInput(user_input_query) =
query_string_query.convert_to_query_ast().unwrap()
else {
panic!();
};
assert_eq!(user_input_query.default_operator, BooleanOperand::And);
Expand All @@ -101,7 +105,9 @@ mod tests {
default_operator: crate::BooleanOperand::Or,
boost: None,
};
let QueryAst::UserInput(user_input_query) = query_string_query.convert_to_query_ast().unwrap() else {
let QueryAst::UserInput(user_input_query) =
query_string_query.convert_to_query_ast().unwrap()
else {
panic!();
};
assert_eq!(user_input_query.default_operator, BooleanOperand::Or);
Expand All @@ -116,7 +122,9 @@ mod tests {
default_operator: crate::BooleanOperand::Or,
boost: None,
};
let QueryAst::UserInput(user_input_query) = query_string_query.convert_to_query_ast().unwrap() else {
let QueryAst::UserInput(user_input_query) =
query_string_query.convert_to_query_ast().unwrap()
else {
panic!();
};
assert!(user_input_query.default_fields.is_none());
Expand Down
4 changes: 3 additions & 1 deletion quickwit/quickwit-query/src/json_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ const LENIENT_BASE64_ENGINE: base64::engine::GeneralPurpose = base64::engine::Ge

impl<'a> InterpretUserInput<'a> for Vec<u8> {
fn interpret_str(mut text: &str) -> Option<Vec<u8>> {
let Some(first_byte) = text.as_bytes().first().copied() else { return Some(Vec::new()); };
let Some(first_byte) = text.as_bytes().first().copied() else {
return Some(Vec::new());
};
let mut buffer = Vec::with_capacity(text.len() * 3 / 4);
if first_byte == b'!' {
// We use ! as a marker to force base64 decoding.
Expand Down
8 changes: 6 additions & 2 deletions quickwit/quickwit-query/src/query_ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ mod tests {
}
.parse_user_query(&[])
.unwrap();
let QueryAst::Bool(bool_query) = query_ast else { panic!() };
let QueryAst::Bool(bool_query) = query_ast else {
panic!()
};
assert_eq!(bool_query.must.len(), 2);
}

Expand All @@ -317,7 +319,9 @@ mod tests {
}
.parse_user_query(&[])
.unwrap();
let QueryAst::Bool(bool_query) = query_ast else { panic!() };
let QueryAst::Bool(bool_query) = query_ast else {
panic!()
};
assert_eq!(bool_query.should.len(), 2);
}
}
24 changes: 18 additions & 6 deletions quickwit/quickwit-query/src/query_ast/user_input_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ mod tests {
}
.parse_user_query(&["defaultfield".to_string()])
.unwrap();
let QueryAst::FullText(phrase_query) = ast else { panic!() };
let QueryAst::FullText(phrase_query) = ast else {
panic!()
};
assert_eq!(&phrase_query.field, "defaultfield");
assert_eq!(&phrase_query.text, "hello");
assert_eq!(
Expand All @@ -330,7 +332,9 @@ mod tests {
}
.parse_user_query(&[])
.unwrap();
let QueryAst::PhrasePrefix(phrase_prefix_query) = ast else { panic!() };
let QueryAst::PhrasePrefix(phrase_prefix_query) = ast else {
panic!()
};
assert_eq!(&phrase_prefix_query.field, "field");
assert_eq!(&phrase_prefix_query.phrase, "hello");
assert_eq!(phrase_prefix_query.max_expansions, 50);
Expand All @@ -349,7 +353,9 @@ mod tests {
}
.parse_user_query(&["defaultfieldweshouldignore".to_string()])
.unwrap();
let QueryAst::FullText(phrase_query) = ast else { panic!() };
let QueryAst::FullText(phrase_query) = ast else {
panic!()
};
assert_eq!(&phrase_query.field, "defaultfield");
assert_eq!(&phrase_query.text, "hello");
assert_eq!(
Expand All @@ -367,7 +373,9 @@ mod tests {
}
.parse_user_query(&["defaultfieldweshouldignore".to_string()])
.unwrap();
let QueryAst::Bool(BoolQuery { should, ..}) = ast else { panic!() };
let QueryAst::Bool(BoolQuery { should, .. }) = ast else {
panic!()
};
assert_eq!(should.len(), 2);
}

Expand All @@ -380,7 +388,9 @@ mod tests {
}
.parse_user_query(&["fieldtoignore".to_string()])
.unwrap();
let QueryAst::FullText(full_text_query) = ast else { panic!() };
let QueryAst::FullText(full_text_query) = ast else {
panic!()
};
assert_eq!(&full_text_query.field, "myfield");
assert_eq!(&full_text_query.text, "hello");
assert_eq!(
Expand All @@ -399,7 +409,9 @@ mod tests {
}
.parse_user_query(&[])
.unwrap();
let QueryAst::FullText(full_text_query) = ast else { panic!() };
let QueryAst::FullText(full_text_query) = ast else {
panic!()
};
full_text_query
};
{
Expand Down
Loading
Loading