Understanding tg_pagerank_pers example

The docs contain an example for personalized pagerank: Personalized PageRank :: TigerGraph Graph Data Science Library.

Can someone please exlain the first parameter mentioned there [("Fiona","Person")]. The signature of tg_pagerank_pers (gsql-graph-algorithms/tg_pagerank_pers.gsql at master · tigergraph/gsql-graph-algorithms · GitHub) does expect a SET<VERTEX> as first argument.
I wonder how the given string array is converted into this.

Bonus question: is it possible to write a query that uses a SELECT to fetch some start vertices based on some criteria and then feed those into tg_pagerank_pers. I have not yet found a way to do a RUN QUERY from within another query.

Hi Grizard,

When specifying a vertex as an input, you need to give both the vertex id and the vertex type. In this example “Fiona” is the vertex id and “Person” is the vertex type, so (“Fiona”, “Person”) is a vertex type Person with the ID of Fiona. The array specifies that this is a set so you could potentially do [(“Fiona”, “Person”), (“Greg”, “Person”)] if you wanted to include multiple starting points.

For the bonus question, including a RETURN statement will allow a query to be run as a sub-query. In this case, you would add the line RETURN @@top_cores_heap to the end of the query and you would want to add the RETURNS statement to the query definition line.
It would change from:
CREATE QUERY tg_pagerank_pers(SET<VERTEX> source, STRING e_type, FLOAT max_change=0.001, INT max_iter=25, FLOAT damping = 0.85, INT top_k = 100, BOOL print_accum = TRUE, STRING result_attr = "", STRING file_path = "") SYNTAX V1 {
To:
CREATE QUERY tg_pagerank_pers(SET<VERTEX> source, STRING e_type, FLOAT max_change=0.001, INT max_iter=25, FLOAT damping = 0.85, INT top_k = 100, BOOL print_accum = TRUE, STRING result_attr = "", STRING file_path = "") RETURNS (HeapAccum<Vertex_Score>) SYNTAX V1 {

Then you can call this query from the one with your SELECT statement.
Here’s the docs page on writing and running subqueries: Operators and Expressions :: GSQL Language Reference

3 Likes