Create Query returns null

I am using a collab notebook and pyTigerGraph accessing a tigercloud solution.
I’ve already created vertices and edges with properties.
I was able to create a query with INSERT commands but when I create the query bellow with SELECT and PRINT commands it is not working. I received a “null” message and no error message

results = conn.gsql('''

  USE GRAPH MyGraph
  CREATE QUERY start_date_qualifier() FOR GRAPH MyGraph { 
    people ={Person.*};

    R = SELECT r.* INTO R1 
    FROM people:p -(:r) ->Country:c
    WHERE c.name == "United Kingdom" AND r.date_of_start == 2014;

    PRINT R;

    R = SELECT n.*, f.*, k.* INTO R2 
    FROM people:n -(FRIENDS_WITH:k) ->Person:f
    WHERE k.date_of_start > 2010;

    PRINT R;

    R = SELECT n.*, f2.*, k2.*   INTO R3
    FROM people:n -(FRIENDS_WITH:k1) ->Person:f1, people:n -(FRIENDS_WITH:k2) ->Person:f2 
    WHERE k2.date_of_start > k1.date_of_start;

    PRINT R;

    R = SELECT n1.*, n2.*, k1.*, n3.*, n4.*, k2.*  AS since INTO R4
    FROM people:n1 -(FRIENDS_WITH:k1) ->Person:n3, people:n2 -(FRIENDS_WITH:k2) ->Person:n4
    WHERE k2.date_of_start == k1.date_of_start and n1.id != n2.id;

    PRINT R;

    R = SELECT n1.*, n2.*, l1.*, c1.*, c2.*, l2.*  INTO R5
    FROM people:n1 -(LIVING_IN:l1) ->Country:c1, people:n2 -(LIVING_IN:l2) ->Country:c2
    WHERE l1.date_of_start == l2.date_of_start  and n1.id != n2.id;

    PRINT R;

  }
  INTERPRET QUERY start_date_qualifier()

  ''')

pprint(results)

OUTUPUT

“Using graph ‘MyGraph’
null
Failed to create queries: [start_date_qualifier].”

I tried to create through GraphStudio and the “null” message appeared.

Hi,

Can you review and share the logs under:

/home/tigergraph/tigergraph/log/gsql/

to see if something more informative appears?

@versant.2612 INTERPRET QUERY does have some limitations. https://docs.tigergraph.com/gsql-ref/current/querying/appendix-query/interpreted-gsql-limitations

Can you CREATE QUERY then, INSTALL QUERY finally call the installed query?

Create Query:

conn.gsql('''

  USE GRAPH MyGraph
  CREATE QUERY start_date_qualifier() 

...

Install Query:

conn.gsql('''
  USE GRAPH MyGraph
  INSTALL QUERY start_date_qualifier() 
''')

Run Query:

conn.runInstalledQuery("start_date_qualifier")

I’ve tried, see bellow

conn.gsql('''

  USE GRAPH MyGraph
  CREATE QUERY start_date_qualifier() 

...

"Using graph ‘MyGraph’
null
Failed to create queries: [start_date_qualifier]."

Install Query:

conn.gsql('''
  USE GRAPH MyGraph
  INSTALL QUERY start_date_qualifier() 
''')

"Using graph ‘MyGraph’
Semantic Check Fails: The query start_date_qualifier cannot be found!
Query installation failed!"

I am using a collab notebook and pyTigerGraph accessing a tigercloud solution.

Is there a way to enable to send the log messages to the UI? Or to run create query with a verbose mode?

@Jon_Herke any new suggestions?

Your main issue has to do with the formatting of SELECT statements.

For example, let’s look at line 5 of your code. If you are trying to select all matching instances of r for a simple statement when you write SELECT r.* then the proper syntax is SELECT r and there is no need for the extra .* characters.

Next, you cannot use an edge variable (like r) as the SELECT target . For instance, in your first SELECT statement you would have to write SELECT p or SELECT c (instead of SELECT r) because those are the source/target vertex aliases, and the SELECT statement cannot be used to compile a list/set of edges.

Also, are you using the SQL-like SELECT statement on purpose? It is characterized by the INTO part of your statement and is generally not used for graph querying examples.

If you are just getting started with GraphStudio, you should probably be using the standard SELECT statement, which has more capabilities for accumulation and graph-based querying, among other things.

The only change you would really need to make in your code is to remove the INTO clause.

I thought that r.* would bring all edge properties values for each edge that satisfied the from pattern and where clause filter.

I changed to R = SELECT r INTO R1 and it raised an error
(4, 15) Error: The expression ‘r’ supports [], but the expression ‘r’ supports []. They contradict each other.

Since you said that “SELECT statement cannot be used to compile a list/set of edges.” what GSQL command shoud I use to retrieve all edge properties values for each edge that satisfied the from pattern and where clause filter?

I changed to R = SELECT p, c INTO R1 and it raised an error
(4, 15) Error: The expression ‘p’ supports [], but the expression ‘p’ supports []. They contradict each other.

How can I use the SELECT statment to retrieve all nodes properties values for each pair of nodes that satisfied the from pattern and where clause filter?

I’m using INTO because it raised error when I didn’t

R = SELECT r.* FROM people:p -(:r) ->Country:c
(4, 19) Error: mismatched input ‘from’ expecting {INTO, ‘,’}

How about this?

 SetAccum<EDGE> @@edges;
  P = SELECT p FROM people:p -(:r) ->Country:c ACCUM @@edges += r;
  PRINT @@edges;
2 Likes

Nice! Mark’s solution will work for compiling a set of edges and represents the proper formatting of a standard SELECT statement. Note that you can utilize ListAccum @@edges in the same manner, but it will also give you access to indexing and single element extraction.

(You can reference the Accumulator Docs for more details.)

Thank you @markmegerian , it worked as I expected.

I adapted the second query and it also works. But when I tried to adapt the third one, the null message appeared again

CREATE QUERY start_date_qual(/* Parameters here */) FOR GRAPH MyGraph {

people ={Person.*};
SetAccum<EDGE> @@edges;
SetAccum<VERTEX> @@source;
SetAccum<VERTEX> @@target;

PRINT "first query!"; 

R = SELECT p   
FROM people:p -(:r) ->Country:c
WHERE c.name == "United Kingdom" AND r.date_of_start == to_datetime("2014-01-01")
ACCUM @@edges += r;

PRINT @@edges;

PRINT "second query!"; 

R = SELECT p 
FROM people:p -(FRIENDS_WITH:r) ->Person:f
WHERE r.date_of_start > to_datetime("2010-01-01")
ACCUM @@edges += r, @@source += p, @@target += f;

PRINT @@edges, @@source, @@target;

PRINT "third query!"; 

R = SELECT p 
FROM people:p -(FRIENDS_WITH:r1) ->Person:f1, people:p -(FRIENDS_WITH:r2) ->Person:f2 
WHERE r2.date_of_start > r1.date_of_start
ACCUM @@edges += r2, @@source += p, @@target += f2;

PRINT @@edges, @@source, @@target;

PRINT “start_date_qual works!”;
}

Can you explain what you are trying to do with the 3rd query? Its not clear to me why you have two different paths from person to person. The other thing you should keep in mind is that when you populate 3 different global accumulators, you have lost the relationship between the elements. You may want to consider a TUPLE for that.

It your goal is to find any occurrences where a friendship started later than another friendship, there are better ways to achieve that.

@versant.2612

If you are trying to write a 2-hop consecutive query (where one friendship leads into the next) you will need to use syntax v2. You can declare it in the header like this:

CREATE QUERY start_date_qual(/* Parameters here */) FOR GRAPH MyGraph SYNTAX v2 {

The third query will then look like this (the directed edges have new syntax, but undirected edges look the same as they do in v1):

R3 = SELECT p 
FROM people:p - (FRIENDS_WITH>:r1) - Person:f1 - (FRIENDS_WITH>:r2) -Person:f2 
WHERE r2.date_of_start > r1.date_of_start
ACCUM @@edges += r2, @@edges += r1, @@source += p, @@target += f2;

However, if you are instead trying to obtain all pairs of friendships where the start of one is before the other, then that cannot really be done in GSQL (as far as I am aware).

In the case of this query, I want to find, for the same person (source vertex of the edge) and for each friendship pair, the one that started later than the other.

But the essential purpose of this query is to check if GSQL allows me to compare the properties of differents edges in the WHERE clause.

General speaking I have a set of queries that I tested using SPARQL+Named Graphs, SPARQL-Star+RDF-Star and Cypher+PG (Neo4J) and now I need to test them using GSQL+PG (TigerGraph). This sets of queries corresponds to BGP, CGP and NGP retrieving and manipulating (filtering,comparing, …) the edges/triples properties.

I changed to what you suggested since my goal is to verify the use of edges properties in the where clause but it raised erros

(11, 35) Error: no viable alternative at input ‘from people:p -(FRIENDS_WITH:r1>’

In my next query I will compare pair of edges using their properties, is it not possible with any version of GSQL?

Yes - you can compare the properties of edges in the WHERE clause and HAVING clause.

Imagine a multi-hop query like this (note that you must specify SYNTAX V2) and yes this is different than your example, but it shows the comparison of edge attributes

/* find posts that occurred after the friendship started */
R3 = SELECT s FROM people:p -(FRIENDS_WITH>:r1)- Person -(POSTED>:r2)- SocialMediaPost:s
WHERE r2.date_of_post > r1.date_of_start;