Skip to content

Commit

Permalink
refine the codes
Browse files Browse the repository at this point in the history
Committed-by: bingqing.lbq from Dev container
  • Loading branch information
BingqingLyu committed Oct 16, 2023
1 parent 0f3b27b commit 1d17798
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 46 deletions.
44 changes: 19 additions & 25 deletions interactive_engine/executor/ir/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,36 +254,36 @@ impl From<String> for common_pb::Variable {
}
}

impl From<i32> for pb::index_predicate::PkValue {
impl From<i32> for pb::index_predicate::triplet::Value {
fn from(value: i32) -> Self {
let val: common_pb::Value = value.into();
val.into()
}
}

impl From<i64> for pb::index_predicate::PkValue {
impl From<i64> for pb::index_predicate::triplet::Value {
fn from(value: i64) -> Self {
let val: common_pb::Value = value.into();
val.into()
}
}

impl From<String> for pb::index_predicate::PkValue {
impl From<String> for pb::index_predicate::triplet::Value {
fn from(value: String) -> Self {
let val: common_pb::Value = value.into();
val.into()
}
}

impl From<common_pb::Value> for pb::index_predicate::PkValue {
impl From<common_pb::Value> 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<common_pb::DynamicParam> for pb::index_predicate::PkValue {
impl From<common_pb::DynamicParam> 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)
}
}

Expand Down Expand Up @@ -383,18 +383,12 @@ impl TryFrom<pb::IndexPredicate> for Vec<i64> {
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);
}
Expand All @@ -411,7 +405,7 @@ impl TryFrom<pb::IndexPredicate> for Vec<i64> {
"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(),
))?,
}
Expand Down Expand Up @@ -446,15 +440,15 @@ impl TryFrom<pb::IndexPredicate> 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)
}
Expand Down
9 changes: 5 additions & 4 deletions interactive_engine/executor/ir/core/src/plan/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1755,10 +1755,11 @@ mod scan {
fn parse_equiv_predicate(
key: FfiProperty, value: FfiConst,
) -> Result<pb::index_predicate::Triplet, FfiResult> {
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]
Expand Down
10 changes: 4 additions & 6 deletions interactive_engine/executor/ir/core/src/plan/logical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ impl TryFrom<pb::index_predicate::Triplet> for Predicates {

fn try_from(triplet: pb::index_predicate::Triplet) -> Result<Self, Self::Error> {
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
Expand Down
16 changes: 7 additions & 9 deletions interactive_engine/executor/ir/proto/algebra.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1d17798

Please sign in to comment.