Query argument type jsonarray

Hello

On https://docs.tigergraph.com/dev/gsql-ref/querying/data-types#query-parameter-types I see:

Input parameters to a query can be base type (except EDGE or JSONOBJECT)

So looking up the base types: https://docs.tigergraph.com/dev/gsql-ref/querying/data-types#base-types:

Any of these base types may be used when defining a global variable, a local variable, a query return value, a parameter, part of a tuple, or an element of a container accumulator.

And in the list

EDGE
| JSONOBJECT
| JSONARRAY
| DATETIME

But trying to create a query in GraphStudio Developer Edition fails with the following message.

(1, 35) Error: Argument type ‘JSONARRAY’ is not supported yet!

Why?

How to reproduce:

CREATE QUERY setsExists (jsonarray sets) FOR GRAPH MyGraph syntax(“v2”) {
/* Write query logic here */
PRINT “setsExists works!”;
}

Not sure if I’m searching in the right direction to solve my issue, In the end, I want the following:

I have the following graph: A -> B -> C

I want to know, in the fastest way possible, for an unknown amount of different A,B,C ids if they exist and are linked to each other per set.

Version info:

GSQL version: 2.4

GSQL commit number: f422d403dab4db5c96bd22822e79e7fd5a581283

GSQL commit date: 2019-06-10 16:18:59 -0700

Best regards

Bert

Hi Bert,

Thanks for your question.

Let me confirm your requirement first.

Is it given an ordered list, A, B, C, D. In the graph, check if subgraph A->B->C>D exists?

Or take an unordered set as input, check if any connected subgraph that is composited only by those vertexes?

Currently, we don’t directly support having JSONARRAY as a query parameter, but we support taking a JSONARRAY string as input then parse it into JSONARRAY in GSQL query.

https://docs.tigergraph.com/dev/gsql-ref/querying/operators-functions-and-expressions#jsonobject-and-jsonarray-functions

If the order is not important for you can use set as your parameter type.

Thanks.

Hello Xinyu

Thanks for your response.

It is ordered list and indeed checking if subgraph exists.

The input would be something like this:

[[A1, B1, C1],[A2, B2, C2],[A3, B3, C3],[A4, B4, C4],[A5, B5, C5], … ]

I want to know for each set if A->B->C exists.

Best regards

Bert

Hi Bert,

You can iterate over a JSONARRAY by using a FOREACH statement.

Since you have size() and getJsonArray(idx) function of a JSONARRAY, you can use foreach statement to traverse a range.

https://docs.tigergraph.com/dev/gsql-ref/querying/operators-functions-and-expressions#jsonobject-and-jsonarray-functions
https://docs.tigergraph.com/dev/gsql-ref/querying/control-flow-statements#foreach-in-range

Here is an example code:

CREATE QUERY test3(string strA) FOR GRAPH graph_name {

SetAccum @@strSet;
SetAccum @@vSet;
MinAccum @@v1, @@v2, @@v3;

JSONARRAY jsonA;

jsonA = parse_json_array( strA );

foreach i in range[0, jsonA.size()-1] do

@@strSet.clear();
@@vSet.clear();
@@strSet += jsonA.getJsonArray(i).getString(0);
@@v1 = to_vertex( jsonA.getJsonArray(i).getString(0), “vertex_type”);
@@v2 = to_vertex( jsonA.getJsonArray(i).getString(1), “vertex_type”);
@@v3 = to_vertex( jsonA.getJsonArray(i).getString(2), “vertex_type”);
@@vSet += @@v1;

start = {@@vSet};
start = select t from start:s-(:e)-:t having t == @@v2;
start = select t from start:s-(:e)-:t having t == @@v3;

if start.size() > 0 then
print “input " + to_string(i) + " matches the pattern”;
else
print “input " + to_string(i) + " doesn’t match the pattern”;
end;
end;
}

1 Like