From 858b6d53b9dc335e9d38ac95f17c090af75b3787 Mon Sep 17 00:00:00 2001 From: BingqingLyu Date: Thu, 21 Sep 2023 13:35:47 +0800 Subject: [PATCH] [Proto] refine proto by adding a is_count_only flag in SCAN, and fix ci tests --- .../rust/client/src/physical_builder.rs | 2 + .../executor/ir/common/src/utils.rs | 1 + .../executor/ir/core/src/glogue/pattern.rs | 1 + .../executor/ir/core/src/plan/ffi.rs | 1 + .../executor/ir/core/src/plan/logical.rs | 24 +++++++-- .../executor/ir/core/src/plan/physical.rs | 14 +++++ .../ir/core/tests/test_multi_source.rs | 43 ++++++++++++--- .../ir/integrated/tests/apply_test.rs | 2 + .../ir/integrated/tests/auxilia_test.rs | 3 +- .../ir/integrated/tests/expand_test.rs | 12 ++++- .../ir/integrated/tests/graph_query_test.rs | 3 ++ .../executor/ir/integrated/tests/join_test.rs | 6 +++ .../ir/integrated/tests/match_test.rs | 1 + .../ir/integrated/tests/nested_branch_test.rs | 2 + .../ir/integrated/tests/pathxd_test.rs | 4 ++ .../ir/integrated/tests/sample_test.rs | 2 + .../executor/ir/integrated/tests/scan_test.rs | 53 ++++++++++++++----- .../executor/ir/integrated/tests/sink_test.rs | 1 + .../executor/ir/proto/algebra.proto | 8 ++- .../executor/ir/proto/physical.proto | 6 +-- .../ir/runtime/src/process/operator/source.rs | 30 ++++++++--- 21 files changed, 179 insertions(+), 40 deletions(-) diff --git a/interactive_engine/executor/ir/clients/rust/client/src/physical_builder.rs b/interactive_engine/executor/ir/clients/rust/client/src/physical_builder.rs index 345808c2ed65..eef9b2e7dab7 100644 --- a/interactive_engine/executor/ir/clients/rust/client/src/physical_builder.rs +++ b/interactive_engine/executor/ir/clients/rust/client/src/physical_builder.rs @@ -564,6 +564,7 @@ mod test { alias: None, params: None, idx_predicate: None, + is_count_only: false, meta_data: None, }; let sink_pb = algebra_pb::Sink { tags: vec![], sink_target: None }; @@ -587,6 +588,7 @@ mod test { alias: None, params: None, idx_predicate: None, + is_count_only: false, meta_data: None, }; let scan2_pb = scan1_pb.clone(); diff --git a/interactive_engine/executor/ir/common/src/utils.rs b/interactive_engine/executor/ir/common/src/utils.rs index c01a59a43dc2..b6e807331a7f 100644 --- a/interactive_engine/executor/ir/common/src/utils.rs +++ b/interactive_engine/executor/ir/common/src/utils.rs @@ -792,6 +792,7 @@ impl From for physical_pb::Scan { alias: scan.alias.map(|tag| tag.try_into().unwrap()), params: scan.params, idx_predicate: scan.idx_predicate, + is_count_only: scan.is_count_only, } } } diff --git a/interactive_engine/executor/ir/core/src/glogue/pattern.rs b/interactive_engine/executor/ir/core/src/glogue/pattern.rs index 6aac9019c93b..d8935af4c11c 100644 --- a/interactive_engine/executor/ir/core/src/glogue/pattern.rs +++ b/interactive_engine/executor/ir/core/src/glogue/pattern.rs @@ -678,6 +678,7 @@ fn generate_source_operator( alias: Some((source_vertex_id as KeyId).into()), params: Some(source_vertex_param), idx_predicate: None, + is_count_only: false, meta_data: None, }; Ok(source_scan.into()) diff --git a/interactive_engine/executor/ir/core/src/plan/ffi.rs b/interactive_engine/executor/ir/core/src/plan/ffi.rs index 76874596bf64..1b1de7938d62 100644 --- a/interactive_engine/executor/ir/core/src/plan/ffi.rs +++ b/interactive_engine/executor/ir/core/src/plan/ffi.rs @@ -1740,6 +1740,7 @@ mod scan { extra: HashMap::new(), }), idx_predicate: None, + is_count_only: false, meta_data: None, }); Box::into_raw(scan) as *const c_void diff --git a/interactive_engine/executor/ir/core/src/plan/logical.rs b/interactive_engine/executor/ir/core/src/plan/logical.rs index 1f6e140fdb11..9a72fc98f5a9 100644 --- a/interactive_engine/executor/ir/core/src/plan/logical.rs +++ b/interactive_engine/executor/ir/core/src/plan/logical.rs @@ -20,13 +20,12 @@ use std::fmt; use std::iter::FromIterator; use std::rc::Rc; +use fraction::Fraction; use ir_common::error::ParsePbError; use ir_common::generated::algebra as pb; use ir_common::generated::algebra::pattern::binder::Item; use ir_common::generated::common as common_pb; use ir_common::{KeyId, LabelId, NameOrId}; - -use fraction::Fraction; use vec_map::VecMap; use crate::error::{IrError, IrResult}; @@ -1580,7 +1579,7 @@ impl AsLogical for pb::Unfold { let curr_node = plan_meta.get_curr_node(); let tag_id = get_or_set_tag_id(tag, plan_meta)?; // plan_meta.set_tag_nodes(tag_id, plan_meta.get_curr_referred_nodes().to_vec()); - + let tag_nodes = plan_meta.get_tag_nodes(tag_id).to_vec(); plan_meta.refer_to_nodes(curr_node, tag_nodes.clone()); } @@ -2073,6 +2072,7 @@ mod test { extra: HashMap::new(), }), idx_predicate: Some(vec!["software".to_string()].into()), + is_count_only: false, meta_data: None, }; scan.preprocess(&meta, &mut plan_meta).unwrap(); @@ -2152,6 +2152,7 @@ mod test { extra: HashMap::new(), }), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2198,6 +2199,7 @@ mod test { extra: HashMap::new(), }), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2230,6 +2232,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -2285,6 +2288,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -2362,6 +2366,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -2483,6 +2488,7 @@ mod test { alias: None, params: Some(query_params(vec!["person".into()], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; let mut opr_id = plan @@ -2621,6 +2627,7 @@ mod test { extra: Default::default(), }), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2649,6 +2656,7 @@ mod test { extra: Default::default(), }), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2686,6 +2694,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -2763,6 +2772,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -2826,6 +2836,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -2884,6 +2895,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -2931,6 +2943,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -2990,6 +3003,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -3081,6 +3095,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -3127,6 +3142,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; plan.append_operator_as_node(scan.into(), vec![0]) @@ -3223,6 +3239,7 @@ mod test { alias: Some("v".into()), params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -3302,6 +3319,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; diff --git a/interactive_engine/executor/ir/core/src/plan/physical.rs b/interactive_engine/executor/ir/core/src/plan/physical.rs index f8fdef18ed03..0ee8e42f844d 100644 --- a/interactive_engine/executor/ir/core/src/plan/physical.rs +++ b/interactive_engine/executor/ir/core/src/plan/physical.rs @@ -1129,6 +1129,7 @@ mod test { alias: None, params: Some(query_params(vec![], columns)), idx_predicate: None, + is_count_only: false, meta_data: None, } } @@ -1636,6 +1637,7 @@ mod test { alias: None, params: Some(query_params(vec!["person".into()], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; let select_opr = pb::Select { predicate: str_to_expr_pb("@.id == 10".to_string()).ok() }; @@ -1692,6 +1694,7 @@ mod test { alias: None, params: Some(query_params(vec!["person".into()], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -1730,6 +1733,7 @@ mod test { alias: None, params: Some(query_params(vec!["person".into()], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -1793,6 +1797,7 @@ mod test { alias: None, params: Some(query_params(vec!["person".into()], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -1882,6 +1887,7 @@ mod test { alias: None, params: Some(query_params(vec!["person".into()], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -1994,6 +2000,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2026,6 +2033,7 @@ mod test { alias: Some(0.into()), params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2115,6 +2123,7 @@ mod test { alias: Some(0.into()), params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2180,6 +2189,7 @@ mod test { alias: Some(0.into()), params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2250,6 +2260,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; let expand_opr = pb::EdgeExpand { @@ -2309,6 +2320,7 @@ mod test { alias: Some(0.into()), params: None, idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -2426,6 +2438,7 @@ mod test { alias: Some(0.into()), params: None, idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -3058,6 +3071,7 @@ mod test { alias: None, params: Some(query_params(vec!["person".into()], vec![])), idx_predicate: None, + is_count_only: false, meta_data: None, }; diff --git a/interactive_engine/executor/ir/core/tests/test_multi_source.rs b/interactive_engine/executor/ir/core/tests/test_multi_source.rs index fee1e8f9c5d2..877609378fae 100644 --- a/interactive_engine/executor/ir/core/tests/test_multi_source.rs +++ b/interactive_engine/executor/ir/core/tests/test_multi_source.rs @@ -39,8 +39,14 @@ mod tests { // join(scan.match1, scan.match2) fn single_source_multi_match_join_logical_plan() -> LogicalPlan { - let scan_opr = - pb::Scan { scan_opt: 0, alias: None, params: None, idx_predicate: None, meta_data: None }; + let scan_opr = pb::Scan { + scan_opt: 0, + alias: None, + params: None, + idx_predicate: None, + is_count_only: false, + meta_data: None, + }; let expand_opr1 = pb::EdgeExpand { v_tag: None, @@ -112,8 +118,14 @@ mod tests { // join(scan1.match1, scan2.match2) fn multi_source_multi_match_join_logical_plan() -> LogicalPlan { - let scan_opr = - pb::Scan { scan_opt: 0, alias: None, params: None, idx_predicate: None, meta_data: None }; + let scan_opr = pb::Scan { + scan_opt: 0, + alias: None, + params: None, + idx_predicate: None, + is_count_only: false, + meta_data: None, + }; let expand_opr1 = pb::EdgeExpand { v_tag: None, @@ -189,8 +201,14 @@ mod tests { // join(join(scan1.match1, scan2.match2), scan3.match3) fn multi_source_multi_match_multi_join_logical_plan() -> LogicalPlan { - let scan_opr = - pb::Scan { scan_opt: 0, alias: None, params: None, idx_predicate: None, meta_data: None }; + let scan_opr = pb::Scan { + scan_opt: 0, + alias: None, + params: None, + idx_predicate: None, + is_count_only: false, + meta_data: None, + }; let expand_opr = pb::EdgeExpand { v_tag: None, @@ -344,8 +362,14 @@ mod tests { // join(join(scan1.match1, scan2.match2), scan3.match3) fn multi_join_logical_plan() -> LogicalPlan { - let scan_opr = - pb::Scan { scan_opt: 0, alias: None, params: None, idx_predicate: None, meta_data: None }; + let scan_opr = pb::Scan { + scan_opt: 0, + alias: None, + params: None, + idx_predicate: None, + is_count_only: false, + meta_data: None, + }; let join_opr = pb::Join { kind: 0, left_keys: vec![common_pb::Variable { tag: None, property: None, node_type: None }], @@ -403,6 +427,7 @@ mod tests { alias: Some(0.into()), params: None, idx_predicate: None, + is_count_only: false, meta_data: None, }; let scan2_opr = pb::Scan { @@ -410,6 +435,7 @@ mod tests { alias: Some(1.into()), params: None, idx_predicate: None, + is_count_only: false, meta_data: None, }; let scan3_opr = pb::Scan { @@ -417,6 +443,7 @@ mod tests { alias: Some(2.into()), params: None, idx_predicate: None, + is_count_only: false, meta_data: None, }; let dummy_opr = pb::Root {}; diff --git a/interactive_engine/executor/ir/integrated/tests/apply_test.rs b/interactive_engine/executor/ir/integrated/tests/apply_test.rs index e3b0be36c267..679e6a7d4bff 100644 --- a/interactive_engine/executor/ir/integrated/tests/apply_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/apply_test.rs @@ -38,6 +38,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -148,6 +149,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; diff --git a/interactive_engine/executor/ir/integrated/tests/auxilia_test.rs b/interactive_engine/executor/ir/integrated/tests/auxilia_test.rs index 6b9261101259..78a02d071ae5 100644 --- a/interactive_engine/executor/ir/integrated/tests/auxilia_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/auxilia_test.rs @@ -43,7 +43,8 @@ mod test { fn source_gen(alias: Option) -> Box + Send> { let graph = create_exp_store(Arc::new(TestCluster {})); register_graph(graph); - let scan_opr_pb = pb::Scan { scan_opt: 0, alias, params: None, idx_predicate: None }; + let scan_opr_pb = + pb::Scan { scan_opt: 0, alias, params: None, idx_predicate: None, is_count_only: false }; let source = SourceOperator::new(scan_opr_pb.into(), Arc::new(TestRouter::default())).unwrap(); source.gen_source(0).unwrap() } diff --git a/interactive_engine/executor/ir/integrated/tests/expand_test.rs b/interactive_engine/executor/ir/integrated/tests/expand_test.rs index 7e24618cbb47..7c71e9b03f1f 100644 --- a/interactive_engine/executor/ir/integrated/tests/expand_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/expand_test.rs @@ -43,7 +43,13 @@ mod test { // g.V() fn source_gen(alias: Option) -> Box + Send> { - source_gen_with_scan_opr(pb::Scan { scan_opt: 0, alias, params: None, idx_predicate: None }) + source_gen_with_scan_opr(pb::Scan { + scan_opt: 0, + alias, + params: None, + idx_predicate: None, + is_count_only: false, + }) } fn source_gen_with_scan_opr(scan_opr_pb: pb::Scan) -> Box + Send> { @@ -688,6 +694,7 @@ mod test { alias: Some(TAG_A.into()), params: None, idx_predicate: Some(vec![1].into()), + is_count_only: false, }); let mut stream = input.input_from(source_iter)?; let flatmap_func1 = expand1.gen_flat_map().unwrap(); @@ -767,6 +774,7 @@ mod test { alias: Some(TAG_A.into()), params: None, idx_predicate: Some(vec![1].into()), + is_count_only: false, }); let mut stream = input.input_from(source_iter)?; let flatmap_func1 = expand1.gen_flat_map().unwrap(); @@ -848,6 +856,7 @@ mod test { alias: Some(TAG_A.into()), params: None, idx_predicate: Some(vec![1].into()), + is_count_only: false, }); let mut stream = input.input_from(source_iter)?; let flatmap_func1 = expand1.gen_flat_map().unwrap(); @@ -994,6 +1003,7 @@ mod test { alias: Some(TAG_A.into()), params: None, idx_predicate: Some(vec![1].into()), + is_count_only: false, }); let mut stream = input.input_from(source_iter)?; let flatmap_func1 = expand1.gen_flat_map().unwrap(); diff --git a/interactive_engine/executor/ir/integrated/tests/graph_query_test.rs b/interactive_engine/executor/ir/integrated/tests/graph_query_test.rs index 2637d8640523..44291ad5eb22 100644 --- a/interactive_engine/executor/ir/integrated/tests/graph_query_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/graph_query_test.rs @@ -37,6 +37,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec!["id".into()], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; let select_opr = pb::Select { predicate: Some(str_to_expr_pb("@.id == 1".to_string()).unwrap()) }; @@ -100,6 +101,7 @@ mod test { alias: None, params: Some(query_params_all_columns(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -126,6 +128,7 @@ mod test { alias: Some(TAG_A.into()), params: Some(query_params_all_columns(vec![], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; diff --git a/interactive_engine/executor/ir/integrated/tests/join_test.rs b/interactive_engine/executor/ir/integrated/tests/join_test.rs index 38eb3d3288e0..5a96d3807114 100644 --- a/interactive_engine/executor/ir/integrated/tests/join_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/join_test.rs @@ -40,6 +40,7 @@ mod test { alias: Some(TAG_A.into()), params: Some(query_params(vec![], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -49,6 +50,7 @@ mod test { alias: Some(TAG_A.into()), params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -321,6 +323,7 @@ mod test { alias: Some(TAG_A.into()), params: Some(query_params(vec![], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -330,6 +333,7 @@ mod test { alias: Some(TAG_B.into()), params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -394,6 +398,7 @@ mod test { alias: Some(TAG_A.into()), params: Some(query_params(vec![], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -403,6 +408,7 @@ mod test { alias: Some(TAG_B.into()), params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; diff --git a/interactive_engine/executor/ir/integrated/tests/match_test.rs b/interactive_engine/executor/ir/integrated/tests/match_test.rs index 7c893126f659..dbe19c4e124c 100644 --- a/interactive_engine/executor/ir/integrated/tests/match_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/match_test.rs @@ -58,6 +58,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, } } diff --git a/interactive_engine/executor/ir/integrated/tests/nested_branch_test.rs b/interactive_engine/executor/ir/integrated/tests/nested_branch_test.rs index 221c537eea98..a6f02ef44a92 100644 --- a/interactive_engine/executor/ir/integrated/tests/nested_branch_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/nested_branch_test.rs @@ -51,6 +51,7 @@ mod test { alias, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, } } @@ -61,6 +62,7 @@ mod test { alias, params: Some(query_params(vec![SOFTWARE_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, } } diff --git a/interactive_engine/executor/ir/integrated/tests/pathxd_test.rs b/interactive_engine/executor/ir/integrated/tests/pathxd_test.rs index 60cf06645a97..e297c1155809 100644 --- a/interactive_engine/executor/ir/integrated/tests/pathxd_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/pathxd_test.rs @@ -37,6 +37,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -86,6 +87,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -125,6 +127,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -882,6 +885,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; diff --git a/interactive_engine/executor/ir/integrated/tests/sample_test.rs b/interactive_engine/executor/ir/integrated/tests/sample_test.rs index d5d3b3c3413d..b47f2876cd8a 100644 --- a/interactive_engine/executor/ir/integrated/tests/sample_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/sample_test.rs @@ -56,6 +56,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; @@ -74,6 +75,7 @@ mod test { alias: None, params: Some(query_params(vec![], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; diff --git a/interactive_engine/executor/ir/integrated/tests/scan_test.rs b/interactive_engine/executor/ir/integrated/tests/scan_test.rs index 3993ceb38408..30f3e4463355 100644 --- a/interactive_engine/executor/ir/integrated/tests/scan_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/scan_test.rs @@ -43,8 +43,13 @@ mod test { // g.V() #[test] fn scan_test() { - let source_iter = - scan_gen(pb::Scan { scan_opt: 0, alias: None, params: None, idx_predicate: None }); + let source_iter = scan_gen(pb::Scan { + scan_opt: 0, + alias: None, + params: None, + idx_predicate: None, + is_count_only: false, + }); let mut result_ids = vec![]; let v1: DefaultId = LDBCVertexParser::to_global_id(1, 0); let v2: DefaultId = LDBCVertexParser::to_global_id(2, 0); @@ -71,6 +76,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, }); let mut result_ids = vec![]; let v1: DefaultId = LDBCVertexParser::to_global_id(1, 0); @@ -96,6 +102,7 @@ mod test { alias: None, params: Some(query_params(vec![PERSON_LABEL.into(), SOFTWARE_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, }); let mut result_ids = vec![]; let v1: DefaultId = LDBCVertexParser::to_global_id(1, 0); @@ -123,6 +130,7 @@ mod test { alias: None, params: None, idx_predicate: Some(vec![1].into()), + is_count_only: false, }); let mut result_ids = vec![]; @@ -146,6 +154,7 @@ mod test { alias: None, params: None, idx_predicate: Some(vec![1, 2].into()), + is_count_only: false, }); let mut result_ids = vec![]; @@ -167,8 +176,13 @@ mod test { fn scan_sample_test() { let mut params = query_params(vec![], vec![], None); params.sample_ratio = 0.1; - let source_iter = - scan_gen(pb::Scan { scan_opt: 0, alias: None, params: Some(params), idx_predicate: None }); + let source_iter = scan_gen(pb::Scan { + scan_opt: 0, + alias: None, + params: Some(params), + idx_predicate: None, + is_count_only: false, + }); let mut result_count = 0; for record in source_iter { if let Some(_element) = record.get(None).unwrap().as_vertex() { @@ -182,8 +196,13 @@ mod test { // g.E() #[test] fn scan_edge_test() { - let source_iter = - scan_gen(pb::Scan { scan_opt: 1, alias: None, params: None, idx_predicate: None }); + let source_iter = scan_gen(pb::Scan { + scan_opt: 1, + alias: None, + params: None, + idx_predicate: None, + is_count_only: false, + }); let mut result_ids = vec![]; let v1: DefaultId = LDBCVertexParser::to_global_id(1, 0); let v2: DefaultId = LDBCVertexParser::to_global_id(2, 0); @@ -210,6 +229,7 @@ mod test { alias: None, params: Some(query_params(vec![KNOWS_LABEL.into()], vec![], None)), idx_predicate: None, + is_count_only: false, }); let mut result_ids = vec![]; let v1: DefaultId = LDBCVertexParser::to_global_id(1, 0); @@ -231,8 +251,13 @@ mod test { fn scan_edge_sample_test() { let mut params = query_params(vec![], vec![], None); params.sample_ratio = 0.1; - let source_iter = - scan_gen(pb::Scan { scan_opt: 1, alias: None, params: Some(params), idx_predicate: None }); + let source_iter = scan_gen(pb::Scan { + scan_opt: 1, + alias: None, + params: Some(params), + idx_predicate: None, + is_count_only: false, + }); let mut result_count = 0; for record in source_iter { if let Some(_element) = record.get(None).unwrap().as_edge() { @@ -248,10 +273,11 @@ mod test { fn scan_vertex_count_test() { let params = query_params(vec![], vec![], None); let source_iter = scan_gen(pb::Scan { - scan_opt: 3, // vcount + scan_opt: 0, // vertex alias: None, params: Some(params), idx_predicate: None, + is_count_only: true, }); let expected = 6; let mut result = 0; @@ -268,10 +294,11 @@ mod test { fn scan_person_vertex_count_test() { let params = query_params(vec![PERSON_LABEL.into()], vec![], None); let source_iter = scan_gen(pb::Scan { - scan_opt: 3, // vcount + scan_opt: 0, // vertex alias: None, params: Some(params), idx_predicate: None, + is_count_only: true, }); let expected = 4; let mut result = 0; @@ -288,10 +315,11 @@ mod test { fn scan_edge_count_test() { let params = query_params(vec![], vec![], None); let source_iter = scan_gen(pb::Scan { - scan_opt: 4, // ecount + scan_opt: 1, // edge alias: None, params: Some(params), idx_predicate: None, + is_count_only: true, }); let expected = 6; let mut result = 0; @@ -308,10 +336,11 @@ mod test { fn scan_knows_edge_count_test() { let params = query_params(vec![KNOWS_LABEL.into()], vec![], None); let source_iter = scan_gen(pb::Scan { - scan_opt: 4, // ecount + scan_opt: 1, // edge alias: None, params: Some(params), idx_predicate: None, + is_count_only: true, }); let expected = 2; let mut result = 0; diff --git a/interactive_engine/executor/ir/integrated/tests/sink_test.rs b/interactive_engine/executor/ir/integrated/tests/sink_test.rs index 2a4523079454..18c1367e8b0c 100644 --- a/interactive_engine/executor/ir/integrated/tests/sink_test.rs +++ b/interactive_engine/executor/ir/integrated/tests/sink_test.rs @@ -41,6 +41,7 @@ mod test { alias: source_alias.map(|tag| tag.into()), params: Some(query_params(vec![], vec![], None)), idx_predicate: None, + is_count_only: false, meta_data: None, }; diff --git a/interactive_engine/executor/ir/proto/algebra.proto b/interactive_engine/executor/ir/proto/algebra.proto index 21a66cfcb882..533d9dff4e56 100644 --- a/interactive_engine/executor/ir/proto/algebra.proto +++ b/interactive_engine/executor/ir/proto/algebra.proto @@ -235,10 +235,6 @@ message Scan { EDGE = 1; // Scanning a relational table TABLE = 2; - // Scanning to get the vertex count - VERTEX_COUNT = 3; - // Scanning to get the edge count - EDGE_COUNT = 4; } ScanOpt scan_opt = 1; // The alias of the item if it is a vertex or edge @@ -247,7 +243,9 @@ message Scan { QueryParams params = 3; // The optional filtering predicate for the field that have been indexed IndexPredicate idx_predicate = 4; - MetaData meta_data = 5; + // The flag that indicates SCAN + COUNT + bool is_count_only = 5; + MetaData meta_data = 6; } // It is typical to use the operator together with EdgeExpand or PathExpand, with the functionality of diff --git a/interactive_engine/executor/ir/proto/physical.proto b/interactive_engine/executor/ir/proto/physical.proto index 358d5739013c..3297bca6fb61 100644 --- a/interactive_engine/executor/ir/proto/physical.proto +++ b/interactive_engine/executor/ir/proto/physical.proto @@ -143,10 +143,6 @@ message Scan { EDGE = 1; // Scanning a relational table TABLE = 2; - // Scanning to get the vertex count - VERTEX_COUNT = 3; - // Scanning to get the edge count - EDGE_COUNT = 4; } ScanOpt scan_opt = 1; // The alias of the item if it is a vertex or edge @@ -155,6 +151,8 @@ message Scan { algebra.QueryParams params = 3; // The optional filtering predicate for the field that have been indexed algebra.IndexPredicate idx_predicate = 4; + // The flag that indicates to SCAN + COUNT + bool is_count_only = 5; } // It is typical to use the operator when: diff --git a/interactive_engine/executor/ir/runtime/src/process/operator/source.rs b/interactive_engine/executor/ir/runtime/src/process/operator/source.rs index e6786610941f..32a264cfae3d 100644 --- a/interactive_engine/executor/ir/runtime/src/process/operator/source.rs +++ b/interactive_engine/executor/ir/runtime/src/process/operator/source.rs @@ -37,6 +37,7 @@ pub enum SourceType { Table, VCount, ECount, + TableCount, Dummy, } @@ -179,7 +180,7 @@ impl SourceOperator { let count = graph.count_edge(&self.query_params)?; Ok(Box::new(vec![Record::new(object!(count), self.alias.clone())].into_iter())) } - SourceType::Table => Err(FnGenError::unsupported_error( + SourceType::Table | SourceType::TableCount => Err(FnGenError::unsupported_error( "neither `Edge` nor `Vertex` but `Table` type `Source` opr", ))?, SourceType::Dummy => { @@ -196,12 +197,29 @@ impl TryFrom for SourceOperator { fn try_from(scan_pb: pb::Scan) -> Result { let scan_opt: algebra_pb::scan::ScanOpt = unsafe { ::std::mem::transmute(scan_pb.scan_opt) }; + let is_count_only = scan_pb.is_count_only; let source_type = match scan_opt { - algebra_pb::scan::ScanOpt::Vertex => SourceType::Vertex, - algebra_pb::scan::ScanOpt::Edge => SourceType::Edge, - algebra_pb::scan::ScanOpt::Table => SourceType::Table, - algebra_pb::scan::ScanOpt::VertexCount => SourceType::VCount, - algebra_pb::scan::ScanOpt::EdgeCount => SourceType::ECount, + algebra_pb::scan::ScanOpt::Vertex => { + if is_count_only { + SourceType::VCount + } else { + SourceType::Vertex + } + } + algebra_pb::scan::ScanOpt::Edge => { + if is_count_only { + SourceType::ECount + } else { + SourceType::Edge + } + } + algebra_pb::scan::ScanOpt::Table => { + if is_count_only { + SourceType::TableCount + } else { + SourceType::Table + } + } }; let query_params = QueryParams::try_from(scan_pb.params)?; Ok(SourceOperator {