From c3b92a5412284433e2ee717245c76b09b8a2a766 Mon Sep 17 00:00:00 2001 From: PSeitz Date: Tue, 11 Jun 2024 17:03:50 +0900 Subject: [PATCH] fix compiler warning, cleanup (#2393) fix compiler warning for missing feature flag remove unused variables cleanup unused methods --- common/Cargo.toml | 3 ++ src/indexer/segment_writer.rs | 51 ++++++++++---------------- src/query/query_parser/logical_ast.rs | 4 +- src/query/query_parser/query_parser.rs | 8 +--- src/schema/document/value.rs | 21 ----------- 5 files changed, 24 insertions(+), 63 deletions(-) diff --git a/common/Cargo.toml b/common/Cargo.toml index a04bfcdb3..3cd02ab8e 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -22,3 +22,6 @@ serde = { version = "1.0.136", features = ["derive"] } [dev-dependencies] proptest = "1.0.0" rand = "0.8.4" + +[features] +unstable = [] # useful for benches. diff --git a/src/indexer/segment_writer.rs b/src/indexer/segment_writer.rs index 16f9e41cd..fabd72d3a 100644 --- a/src/indexer/segment_writer.rs +++ b/src/indexer/segment_writer.rs @@ -202,9 +202,8 @@ impl SegmentWriter { match field_entry.field_type() { FieldType::Facet(_) => { let mut facet_tokenizer = FacetTokenizer::default(); // this can be global - for value_access in values { - // Used to help with linting and type checking. - let value = value_access as D::Value<'_>; + for value in values { + let value = value.as_value(); let facet_str = value.as_facet().ok_or_else(make_schema_error)?; let mut facet_tokenizer = facet_tokenizer.token_stream(facet_str); @@ -220,15 +219,14 @@ impl SegmentWriter { } FieldType::Str(_) => { let mut indexing_position = IndexingPosition::default(); - for value_access in values { - // Used to help with linting and type checking. - let value = value_access as D::Value<'_>; + for value in values { + let value = value.as_value(); let mut token_stream = if let Some(text) = value.as_str() { let text_analyzer = &mut self.per_field_text_analyzers[field.field_id() as usize]; text_analyzer.token_stream(text) - } else if let Some(tok_str) = value.as_pre_tokenized_text() { + } else if let Some(tok_str) = value.into_pre_tokenized_text() { BoxTokenStream::new(PreTokenizedStream::from(*tok_str.clone())) } else { continue; @@ -250,9 +248,8 @@ impl SegmentWriter { } FieldType::U64(_) => { let mut num_vals = 0; - for value_access in values { - // Used to help with linting and type checking. - let value = value_access as D::Value<'_>; + for value in values { + let value = value.as_value(); num_vals += 1; let u64_val = value.as_u64().ok_or_else(make_schema_error)?; @@ -265,10 +262,8 @@ impl SegmentWriter { } FieldType::Date(_) => { let mut num_vals = 0; - for value_access in values { - // Used to help with linting and type checking. - let value_access = value_access as D::Value<'_>; - let value = value_access.as_value(); + for value in values { + let value = value.as_value(); num_vals += 1; let date_val = value.as_datetime().ok_or_else(make_schema_error)?; @@ -282,9 +277,8 @@ impl SegmentWriter { } FieldType::I64(_) => { let mut num_vals = 0; - for value_access in values { - // Used to help with linting and type checking. - let value = value_access as D::Value<'_>; + for value in values { + let value = value.as_value(); num_vals += 1; let i64_val = value.as_i64().ok_or_else(make_schema_error)?; @@ -297,10 +291,8 @@ impl SegmentWriter { } FieldType::F64(_) => { let mut num_vals = 0; - for value_access in values { - // Used to help with linting and type checking. - let value = value_access as D::Value<'_>; - + for value in values { + let value = value.as_value(); num_vals += 1; let f64_val = value.as_f64().ok_or_else(make_schema_error)?; term_buffer.set_f64(f64_val); @@ -312,10 +304,8 @@ impl SegmentWriter { } FieldType::Bool(_) => { let mut num_vals = 0; - for value_access in values { - // Used to help with linting and type checking. - let value = value_access as D::Value<'_>; - + for value in values { + let value = value.as_value(); num_vals += 1; let bool_val = value.as_bool().ok_or_else(make_schema_error)?; term_buffer.set_bool(bool_val); @@ -327,10 +317,8 @@ impl SegmentWriter { } FieldType::Bytes(_) => { let mut num_vals = 0; - for value_access in values { - // Used to help with linting and type checking. - let value = value_access as D::Value<'_>; - + for value in values { + let value = value.as_value(); num_vals += 1; let bytes = value.as_bytes().ok_or_else(make_schema_error)?; term_buffer.set_bytes(bytes); @@ -364,9 +352,8 @@ impl SegmentWriter { } FieldType::IpAddr(_) => { let mut num_vals = 0; - for value_access in values { - // Used to help with linting and type checking. - let value = value_access as D::Value<'_>; + for value in values { + let value = value.as_value(); num_vals += 1; let ip_addr = value.as_ip_addr().ok_or_else(make_schema_error)?; diff --git a/src/query/query_parser/logical_ast.rs b/src/query/query_parser/logical_ast.rs index 436b033d3..ce57b710b 100644 --- a/src/query/query_parser/logical_ast.rs +++ b/src/query/query_parser/logical_ast.rs @@ -2,7 +2,7 @@ use std::fmt; use std::ops::Bound; use crate::query::Occur; -use crate::schema::{Field, Term, Type}; +use crate::schema::{Term, Type}; use crate::Score; #[derive(Clone)] @@ -20,8 +20,6 @@ pub enum LogicalLiteral { upper: Bound, }, Set { - field: Field, - value_type: Type, elements: Vec, }, All, diff --git a/src/query/query_parser/query_parser.rs b/src/query/query_parser/query_parser.rs index d668e8eaf..1a6c3aaf4 100644 --- a/src/query/query_parser/query_parser.rs +++ b/src/query/query_parser/query_parser.rs @@ -832,17 +832,11 @@ impl QueryParser { let (field, json_path) = try_tuple!(self .split_full_path(&full_path) .ok_or_else(|| QueryParserError::FieldDoesNotExist(full_path.clone()))); - let field_entry = self.schema.get_field_entry(field); - let value_type = field_entry.field_type().value_type(); let (elements, errors) = elements .into_iter() .map(|element| self.compute_boundary_term(field, json_path, &element)) .partition_result(); - let logical_ast = LogicalAst::Leaf(Box::new(LogicalLiteral::Set { - elements, - field, - value_type, - })); + let logical_ast = LogicalAst::Leaf(Box::new(LogicalLiteral::Set { elements })); (Some(logical_ast), errors) } UserInputLeaf::Exists { .. } => ( diff --git a/src/schema/document/value.rs b/src/schema/document/value.rs index a8f8839da..de1067ce6 100644 --- a/src/schema/document/value.rs +++ b/src/schema/document/value.rs @@ -17,15 +17,6 @@ pub trait Value<'a>: Send + Sync + Debug { /// Returns the field value represented by an enum which borrows it's data. fn as_value(&self) -> ReferenceValue<'a, Self>; - #[inline] - /// Returns if the value is `null` or not. - fn is_null(&self) -> bool { - matches!( - self.as_value(), - ReferenceValue::Leaf(ReferenceValueLeaf::Null) - ) - } - #[inline] /// If the Value is a leaf, returns the associated leaf. Returns None otherwise. fn as_leaf(&self) -> Option> { @@ -117,18 +108,6 @@ pub trait Value<'a>: Send + Sync + Debug { None } } - - #[inline] - /// Returns true if the Value is an array. - fn is_array(&self) -> bool { - matches!(self.as_value(), ReferenceValue::Object(_)) - } - - #[inline] - /// Returns true if the Value is an object. - fn is_object(&self) -> bool { - matches!(self.as_value(), ReferenceValue::Object(_)) - } } /// A enum representing a leaf value for tantivy to index.