How to define conditional edge types in GSQL

Is it possible to do something like below?

  EDGE_TYPES = {};
  IF FLAG_1 THEN EDGE_TYPES += edge_type1; END;
  IF FLAG_2 THEN EDGE_TYPES += edge_type2; END;
  tmp = SELECT t FROM Source:s -(EDGE_TYPES:e)- :t;

I want to write a query that user can pass boolean FLAG_1 and FLAG_1 to control the edge types to scan. (They don’t need to know the exact edge type to pass there as string instead).
But I don’t know how to write the query.

Hi @gyx2cn,

You can absolutely do that by utilizing SetAccum for the edge types!

You can also pass edge types as a list of STRING too.

Example 1: Define “conditional edge types” in GSQL using Boolean F;ag:

CREATE OR REPLACE QUERY test_conditional_edge_type(BOOL FLAG_1, BOOL FLAG_2) {
    SetAccum<STRING> @@e_type_set;
    
    IF FLAG_1 THEN @@e_type_set += "edge_type1_str"; END;
    IF FLAG_2 THEN @@e_type_set += "edge_type2_str"; END;
    tmp = SELECT t FROM Source:s -(EDGE_TYPES:e)- :t;
}

Example 2: Passing edge types as Set into your GSQL query:

CREATE OR REPLACE QUERY test_pass_edge_types(SET<STRING> input_e_types) {
    tmp = SELECT t FROM Source:s -(input_e_types:e)- :t;
}

I hope this helps!

Best,
Supawish Limprasert (Jim)
Solution Engineer, TigerGraph

Thanks! It works.
I was almost there. I didn’t put quote on “edge_type1_str” and the queries editor doesn’t warn me just got silence no response when I click run button.

1 Like