How to get the number of nodes or edges in GSQL query and save them as variables for later use

I try to do this to get the number of nodes:

Start = SELECT s FROM Bus:s;
PRINT Start.size();
ArrayAccum<SumAccum<DOUBLE>> @@Y[Start.size()][Start.size()];

But it was wrong:
image

I printed Start.size(), which can normally obtain the number of nodes:
image

I want to know why can’t Start.size() be used as the length variable of ArrrayAccum two-dimensional vector

It will work only if it is set to a specific number, for example ArrayAccum<SumAccum<DOUBLE>> @@Y[50][50]

I found that the previous problem was not described correctly

The question I want to ask should be:

How to use variables(such as the number of nodes queried) as ArratAccum< > preallocated length?

What you are looking for here is the reallocate function for ArrayAccums.

As per the docs, you can declare an array with empty size parameters and then set them later using variables instead of integer constants.

For your code, it would look like this:

Start = SELECT s FROM Bus:s;
ArrayAccum<SumAccum<DOUBLE>> @@Y[][];
@@Y.reallocate(Start.size(), Start.size());

@lshestakov Thank you very much for your reply

After your reply, I made some attempts and found some strange problems

  1. If I specify its dimension when defining arrayaccum < >, it can work normally:

2.But when I resized it, I found that it didn’t work properly, Like this:


When the query is run, it will prompt me to timeout the query, even if I set the timeout to 60 seconds

3.But here’s how it works

Therefore, I found that if the size is not predefined, it seems that it cannot be assigned in the query

1 Like