From 1d177987fae1a3aa9d90c916cc576b3557e00518 Mon Sep 17 00:00:00 2001 From: "bingqing.lbq" Date: Mon, 16 Oct 2023 07:01:51 +0000 Subject: [PATCH] refine the codes Committed-by: bingqing.lbq from Dev container --- .../executor/ir/common/src/utils.rs | 44 ++++++++----------- .../executor/ir/core/src/plan/ffi.rs | 9 ++-- .../executor/ir/core/src/plan/logical.rs | 10 ++--- .../graph_proxy/src/utils/expr/eval_pred.rs | 4 +- .../executor/ir/proto/algebra.proto | 16 +++---- 5 files changed, 37 insertions(+), 46 deletions(-) diff --git a/interactive_engine/executor/ir/common/src/utils.rs b/interactive_engine/executor/ir/common/src/utils.rs index 487f776711d7..97a972b68824 100644 --- a/interactive_engine/executor/ir/common/src/utils.rs +++ b/interactive_engine/executor/ir/common/src/utils.rs @@ -254,36 +254,36 @@ impl From for common_pb::Variable { } } -impl From for pb::index_predicate::PkValue { +impl From for pb::index_predicate::triplet::Value { fn from(value: i32) -> Self { let val: common_pb::Value = value.into(); val.into() } } -impl From for pb::index_predicate::PkValue { +impl From for pb::index_predicate::triplet::Value { fn from(value: i64) -> Self { let val: common_pb::Value = value.into(); val.into() } } -impl From for pb::index_predicate::PkValue { +impl From for pb::index_predicate::triplet::Value { fn from(value: String) -> Self { let val: common_pb::Value = value.into(); val.into() } } -impl From for pb::index_predicate::PkValue { +impl From for pb::index_predicate::triplet::Value { fn from(value: common_pb::Value) -> Self { - pb::index_predicate::PkValue { item: Some(pb::index_predicate::pk_value::Item::Value(value)) } + pb::index_predicate::triplet::Value::Const(value) } } -impl From for pb::index_predicate::PkValue { +impl From for pb::index_predicate::triplet::Value { fn from(param: common_pb::DynamicParam) -> Self { - pb::index_predicate::PkValue { item: Some(pb::index_predicate::pk_value::Item::DynParam(param)) } + pb::index_predicate::triplet::Value::Param(param) } } @@ -383,18 +383,12 @@ impl TryFrom for Vec { let (key, value) = (predicate.key.as_ref(), predicate.value.as_ref()); let key = key.ok_or("key is empty in kv_pair in indexed_scan")?; if let Some(common_pb::property::Item::Id(_id_key)) = key.item.as_ref() { - let value_item = value - .ok_or(ParsePbError::EmptyFieldError( - "`Value` is empty in kv_pair in indexed_scan".to_string(), - ))? - .item - .as_ref() - .ok_or(ParsePbError::EmptyFieldError( - "`Value.item` is emtpy in kv_pair in indexed_scan".to_string(), - ))?; + let value_item = value.ok_or(ParsePbError::EmptyFieldError( + "`Value` is empty in kv_pair in indexed_scan".to_string(), + ))?; match value_item { - pb::index_predicate::pk_value::Item::Value(value) => match value.item.as_ref() { + pb::index_predicate::triplet::Value::Const(value) => match value.item.as_ref() { Some(common_pb::value::Item::I64(v)) => { global_ids.push(*v); } @@ -411,7 +405,7 @@ impl TryFrom for Vec { "indexed value other than integer (I32, I64) and integer array".to_string(), ))?, }, - pb::index_predicate::pk_value::Item::DynParam(_) => Err(ParsePbError::Unsupported( + pb::index_predicate::triplet::Value::Param(_) => Err(ParsePbError::Unsupported( "indexed value other than integer (I32, I64) and integer array".to_string(), ))?, } @@ -446,15 +440,15 @@ impl TryFrom for Vec<(NameOrId, Object)> { "Other keys rather than property key in kv_pair in indexed_scan".to_string(), ))?, }; - let value = match value_pb.item { - Some(pb::index_predicate::pk_value::Item::Value(value)) => value, - _ => Err(ParsePbError::Unsupported(format!( + if let pb::index_predicate::triplet::Value::Const(value) = value_pb { + let obj_val = Object::try_from(value)?; + primary_key_values.push((key, obj_val)); + } else { + Err(ParsePbError::Unsupported(format!( "unsupported indexed predicate value {:?}", value_pb - )))?, - }; - let obj_val = Object::try_from(value)?; - primary_key_values.push((key, obj_val)); + )))? + } } Ok(primary_key_values) } diff --git a/interactive_engine/executor/ir/core/src/plan/ffi.rs b/interactive_engine/executor/ir/core/src/plan/ffi.rs index c505ebb9c080..6139ec234875 100644 --- a/interactive_engine/executor/ir/core/src/plan/ffi.rs +++ b/interactive_engine/executor/ir/core/src/plan/ffi.rs @@ -1755,10 +1755,11 @@ mod scan { fn parse_equiv_predicate( key: FfiProperty, value: FfiConst, ) -> Result { - let pk_value = pb::index_predicate::PkValue { - item: Some(pb::index_predicate::pk_value::Item::Value(value.try_into()?)), - }; - Ok(pb::index_predicate::Triplet { key: key.try_into()?, value: Some(pk_value), cmp: None }) + Ok(pb::index_predicate::Triplet { + key: key.try_into()?, + value: Some(pb::index_predicate::triplet::Value::Const(value.try_into()?)), + cmp: None, + }) } #[no_mangle] diff --git a/interactive_engine/executor/ir/core/src/plan/logical.rs b/interactive_engine/executor/ir/core/src/plan/logical.rs index 94d2251c8bd4..4739d7244ae1 100644 --- a/interactive_engine/executor/ir/core/src/plan/logical.rs +++ b/interactive_engine/executor/ir/core/src/plan/logical.rs @@ -1404,13 +1404,11 @@ impl AsLogical for pb::IndexPredicate { } common_pb::property::Item::Label(_) => { if let Some(val) = pred.value.as_mut() { - if let Some(item) = val.item.as_mut() { - match item { - pb::index_predicate::pk_value::Item::Value(val) => { - preprocess_label(val, meta, plan_meta)? - } - pb::index_predicate::pk_value::Item::DynParam(_) => {} + match val { + pb::index_predicate::triplet::Value::Const(val) => { + preprocess_label(val, meta, plan_meta)? } + pb::index_predicate::triplet::Value::Param(_) => {} } } } diff --git a/interactive_engine/executor/ir/graph_proxy/src/utils/expr/eval_pred.rs b/interactive_engine/executor/ir/graph_proxy/src/utils/expr/eval_pred.rs index 159e729e617d..450ec4eaedf8 100644 --- a/interactive_engine/executor/ir/graph_proxy/src/utils/expr/eval_pred.rs +++ b/interactive_engine/executor/ir/graph_proxy/src/utils/expr/eval_pred.rs @@ -169,8 +169,8 @@ impl TryFrom for Predicates { fn try_from(triplet: pb::index_predicate::Triplet) -> Result { let value = if let Some(value) = &triplet.value { - match &value.item { - Some(pb::index_predicate::pk_value::Item::Value(v)) => Some(v.clone()), + match &value { + pb::index_predicate::triplet::Value::Const(v) => Some(v.clone()), _ => Err(ParsePbError::Unsupported(format!( "unsupported indexed predicate value {:?}", value diff --git a/interactive_engine/executor/ir/proto/algebra.proto b/interactive_engine/executor/ir/proto/algebra.proto index 639e0fccc894..a0559c43efc1 100644 --- a/interactive_engine/executor/ir/proto/algebra.proto +++ b/interactive_engine/executor/ir/proto/algebra.proto @@ -191,18 +191,16 @@ message Limit { // where the values referred by k1, k2, ... are indexed and hence the // predicate can be efficiently verified by leveraging the index. message IndexPredicate { - message PkValue { - oneof item { - common.Value value = 1; - common.DynamicParam dyn_param = 2; - } - } - // A triplet defines that a key must be **equal** to a given constant value. + // A triplet defines that a key must be **equal** to a given value. + // The value can be a constant value, or a dynamic parameter. message Triplet { common.Property key = 1; - PkValue value = 2; + oneof value { + common.Value const = 2; + common.DynamicParam param = 3; + } // TODO(longbin) More comparators (gt, ge, lt, le, ne) other than equivalence (eq) may be required - common.None cmp = 3; + common.None cmp = 4; } // A collection of `Triplet` that forms a logical **AND** of all `Predicate`s. message AndPredicate {