Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Interceptor for AuthInterceptor {
mut req: Request<()>,
) -> std::result::Result<tonic::Request<()>, tonic::Status> {
if let Some(ref token) = self.token {
let header_value = format!("{}", token);
let header_value = token.to_string();
req.metadata_mut()
.insert("authorization", header_value.parse().unwrap());
}
Expand Down
8 changes: 7 additions & 1 deletion src/data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::convert::TryFrom;

use crate::{
proto::schema::{
Expand Down Expand Up @@ -58,7 +59,7 @@ impl From<schema::FieldData> for FieldColumn {
.unwrap_or((Some(1), None));

let value: ValueVec = fd.field.map(Into::into).unwrap_or(ValueVec::None);
let dtype = DataType::from_i32(fd.r#type).unwrap_or(DataType::None);
let dtype = DataType::try_from(fd.r#type).unwrap_or(DataType::None);

FieldColumn {
name: fd.field_name,
Expand Down Expand Up @@ -135,6 +136,11 @@ impl FieldColumn {
self.value.len() / self.dim as usize
}

#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn copy_with_metadata(&self) -> Self {
Self {
dim: self.dim,
Expand Down
15 changes: 1 addition & 14 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::{error::*, proto};
/// .force_deny_writing(false)
/// .force_deny_reading(false);
/// ```
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct CreateDbOptions {
/// Number of replicas for the database
replica_number: Option<i32>,
Expand All @@ -76,19 +76,6 @@ pub struct CreateDbOptions {
/// Type alias for database properties, currently equivalent to CreateDbOptions
type DbProperties = CreateDbOptions;

impl Default for CreateDbOptions {
fn default() -> Self {
Self {
replica_number: None,
resource_groups: None,
diskquota_mb: None,
max_collections: None,
force_deny_writing: None,
force_deny_reading: None,
}
}
}

impl CreateDbOptions {
/// Creates a new `CreateDbOptions` instance with default values.
///
Expand Down
2 changes: 1 addition & 1 deletion src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl From<IndexDescription> for IndexInfo {
index_name: description.index_name.clone(),
field_name: description.field_name.clone(),
id: description.index_id,
params: params,
params,
state: description.state(),
}
}
Expand Down
20 changes: 6 additions & 14 deletions src/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@ use crate::{
value::ValueVec,
};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct InsertOptions {
pub(crate) partition_name: String,
}

impl Default for InsertOptions {
fn default() -> Self {
Self {
partition_name: String::new(),
}
}
}

impl InsertOptions {
pub fn new() -> Self {
Self::default()
Expand Down Expand Up @@ -126,7 +118,7 @@ impl Client {
base: Some(MsgBase::new(MsgType::Delete)),
db_name: "".to_string(),
collection_name: collection_name.clone(),
expr: expr,
expr,
partition_name: options.partition_name.clone(),
hash_keys: Vec::new(),
consistency_level: crate::proto::common::ConsistencyLevel::Strong.into(),
Expand Down Expand Up @@ -154,22 +146,22 @@ impl Client {
(DataType::Int64, ValueVec::Long(values)) => {
for (i, v) in values.iter().enumerate() {
if i > 0 {
expr.push_str(",");
expr.push(',');
}
expr.push_str(format!("{}", v).as_str());
}
expr.push_str("]");
expr.push(']');
expr
}

(DataType::VarChar, ValueVec::String(values)) => {
for (i, v) in values.iter().enumerate() {
if i > 0 {
expr.push_str(",");
expr.push(',');
}
expr.push_str(v.as_str());
}
expr.push_str("]");
expr.push(']');
expr
}

Expand Down
10 changes: 1 addition & 9 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,11 @@ impl LoadOptions {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct GetLoadStateOptions {
pub(crate) partition_names: Vec<String>,
}

impl Default for GetLoadStateOptions {
fn default() -> Self {
Self {
partition_names: vec![],
}
}
}

impl GetLoadStateOptions {
pub fn new() -> Self {
Self::default()
Expand Down
39 changes: 12 additions & 27 deletions src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
/// load_partitions' waitting time
const WAIT_LOAD_DURATION_MS: u64 = 100;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct LoadPartitionsOption {
resource_groups: Vec<String>,
refresh: bool,
Expand All @@ -22,18 +22,6 @@ pub struct LoadPartitionsOption {
load_params: HashMap<String, String>,
}

impl Default for LoadPartitionsOption {
fn default() -> Self {
LoadPartitionsOption {
resource_groups: Vec::new(),
refresh: false,
load_fields: Vec::new(),
skip_load_dynamic_field: false,
load_params: HashMap::new(),
}
}
}

impl Client {
/// Creates a new partition in the specified collection.
///
Expand Down Expand Up @@ -103,19 +91,16 @@ impl Client {
///
/// Returns a `Result` containing a vector of partition names if successful, or an error if the operation fails.
pub async fn list_partitions(&self, collection_name: String) -> Result<Vec<String>> {
let res = self
.client
.clone()
.show_partitions(crate::proto::milvus::ShowPartitionsRequest {
base: Some(MsgBase::new(MsgType::ShowPartitions)),
db_name: "".to_string(), // reserved
collection_name,
collection_id: 0, // reserved
partition_names: vec![], // reserved
r#type: 0, // reserved
})
.await?
.into_inner();
let req = crate::proto::milvus::ShowPartitionsRequest {
base: Some(MsgBase::new(MsgType::ShowPartitions)),
db_name: "".to_string(),
collection_name,
collection_id: 0,
partition_names: vec![],
..Default::default()
};

let res = self.client.clone().show_partitions(req).await?.into_inner();
status_to_result(&res.status)?;
Ok(res.partition_names)
}
Expand Down Expand Up @@ -208,7 +193,7 @@ impl Client {
base: Some(MsgBase::new(MsgType::LoadPartitions)),
db_name: "".to_string(),
collection_name: collection_name.into(),
partition_names: partition_names,
partition_names,
})
.await?
.into_inner();
Expand Down
12 changes: 6 additions & 6 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl From<schema::FieldSchema> for FieldSchema {
.and_then(|x| x.value.parse().ok())
.unwrap_or(1);

let dtype = DataType::from_i32(fld.data_type).unwrap();
let dtype = DataType::try_from(fld.data_type).unwrap();

FieldSchema {
name: fld.name,
Expand Down Expand Up @@ -410,7 +410,7 @@ impl From<FieldSchema> for schema::FieldSchema {

schema::FieldSchema {
field_id: 0,
name: fld.name.into(),
name: fld.name.clone(),
is_primary_key: fld.is_primary,
description: fld.description,
data_type: fld.dtype as i32,
Expand Down Expand Up @@ -452,7 +452,7 @@ impl CollectionSchema {
}

pub fn validate(&self) -> Result<()> {
self.primary_column().ok_or_else(|| Error::NoPrimaryKey)?;
self.primary_column().ok_or(Error::NoPrimaryKey)?;
// TODO addidtional schema checks need to be added here
Ok(())
}
Expand All @@ -477,7 +477,7 @@ impl CollectionSchema {
}
}
}
return Err(error::Error::from(Error::NoSuchKey(field_name.to_owned())));
Err(error::Error::from(Error::NoSuchKey(field_name.to_owned())))
}
}

Expand Down Expand Up @@ -597,10 +597,10 @@ impl CollectionSchemaBuilder {
return Err(error::Error::from(Error::NoPrimaryKey));
}

let this = std::mem::replace(self, CollectionSchemaBuilder::new("".into(), ""));
let this = std::mem::replace(self, CollectionSchemaBuilder::new("", ""));

Ok(CollectionSchema {
fields: this.inner.into(),
fields: this.inner,
name: this.name,
description: this.description,
enable_dynamic_field: self.enable_dynamic_field,
Expand Down
4 changes: 3 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::convert::TryFrom;

use crate::proto::{self, schema::DataType};

pub(crate) type Timestamp = u64;
Expand All @@ -17,7 +19,7 @@ impl From<proto::schema::FieldSchema> for Field {
id: value.field_id,
name: value.name,
description: value.description,
dtype: DataType::from_i32(value.data_type).unwrap_or(DataType::None),
dtype: DataType::try_from(value.data_type).unwrap_or(DataType::None),
is_primary_key: value.is_primary_key,
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,21 @@ impl ValueVec {
}

pub fn check_dtype(&self, dtype: DataType) -> bool {
match (self, dtype) {
matches!(
(self, dtype),
(ValueVec::Binary(..), DataType::BinaryVector)
| (ValueVec::Float(..), DataType::FloatVector)
| (ValueVec::Float(..), DataType::Float)
| (ValueVec::Int(..), DataType::Int8)
| (ValueVec::Int(..), DataType::Int16)
| (ValueVec::Int(..), DataType::Int32)
| (ValueVec::Long(..), DataType::Int64)
| (ValueVec::Bool(..), DataType::Bool)
| (ValueVec::String(..), DataType::String)
| (ValueVec::String(..), DataType::VarChar)
| (ValueVec::None, _)
| (ValueVec::Double(..), DataType::Double) => true,
_ => false,
}
| (ValueVec::Float(..), DataType::FloatVector)
| (ValueVec::Float(..), DataType::Float)
| (ValueVec::Int(..), DataType::Int8)
| (ValueVec::Int(..), DataType::Int16)
| (ValueVec::Int(..), DataType::Int32)
| (ValueVec::Long(..), DataType::Int64)
| (ValueVec::Bool(..), DataType::Bool)
| (ValueVec::String(..), DataType::String)
| (ValueVec::String(..), DataType::VarChar)
| (ValueVec::None, _)
| (ValueVec::Double(..), DataType::Double)
)
}

#[inline]
Expand Down