Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Superhero network use case. Proposed PGQL for finding neighbors returns 0 results

Luis Rodriguez FernandezJun 16 2017 — edited Aug 20 2020

Hello there,

It looks like there is something wrong with the example query. It seems that the graph is built correctly:

pgx>  G = session.readGraphWithProperties("/home/lurodrig/development/workspaces/openlab/pgx/superhero-network/hero-network.csv.json").undirect()

==> PgxGraph[name=hero-network_sub-graph_1,N=6426,E=574467,created=1497625143428]

pgx> G.getNumEdges()

==> 574467

pgx> G.getNumVertices()

==> 6426

I can run the pageRank algorithm:

pgx> pageRank = analyst.pagerank(G, 0.0001, 0.85, 100)

==> VertexProperty[name=pagerank,type=double,graph=hero-network_sub-graph_1]

pgx> pageRank.getTopKValues(10)

==> PgxVertex[ID=CAPTAIN AMERICA]=0.0110658307488833

==> PgxVertex[ID=SPIDER-MAN/PETER PAR]=0.010883248192971052

==> PgxVertex[ID=IRON MAN/TONY STARK ]=0.00822400232340639

==> PgxVertex[ID=WOLVERINE/LOGAN ]=0.007184179121356004

==> PgxVertex[ID=THOR/DR. DONALD BLAK]=0.007111076442093899

==> PgxVertex[ID=THING/BENJAMIN J. GR]=0.007040224708813351

==> PgxVertex[ID=HUMAN TORCH/JOHNNY S]=0.006715685790441994

==> PgxVertex[ID=MR. FANTASTIC/REED R]=0.006474776413326844

==> PgxVertex[ID=SCARLET WITCH/WANDA ]=0.006292296186722285

==> PgxVertex[ID=INVISIBLE WOMAN/SUE ]=0.00607097561105347

[rest of output truncated]

I can do some basic pgql:

pgx> G.queryPgql("SELECT n.id(), n.pagerank WHERE (n) ORDER BY n.pagerank DESC").print(10)

+-----------------------------------------------+

| n.id()                 | n.pagerank           |

+-----------------------------------------------+

| "CAPTAIN AMERICA"      | 0.0110658307488833   |

| "SPIDER-MAN/PETER PAR" | 0.010883248192971052 |

| "IRON MAN/TONY STARK " | 0.00822400232340639  |

| "WOLVERINE/LOGAN "     | 0.007184179121356004 |

| "THOR/DR. DONALD BLAK" | 0.007111076442093899 |

| "THING/BENJAMIN J. GR" | 0.007040224708813351 |

| "HUMAN TORCH/JOHNNY S" | 0.006715685790441994 |

| "MR. FANTASTIC/REED R" | 0.006474776413326844 |

| "SCARLET WITCH/WANDA " | 0.006292296186722285 |

| "INVISIBLE WOMAN/SUE " | 0.00607097561105347  |

+-----------------------------------------------+

==> null

However when I ask for neighbors...

pgx> Results = G.queryPgql("SELECT x WHERE\

pgx>          (a @ 'SHANG-CHI')->(x),\

pgx>          (b @ 'WHITE TIGER/HECTOR A')->(x),\

pgx>          (c @ 'IRON FIST/DANIEL RAN')->(x)")

==> PgqlResultSetImpl[graph=hero-network_sub-graph_1,numResults=0]

... I do not get any result

And the characters are there, e.g:

pgx> G.queryPgql("SELECT n.id(), n.pagerank WHERE (n@'SHANG-CHI')").print()

+------------------------------------+

| n.id()      | n.pagerank           |

+------------------------------------+

| "SHANG-CHI" | 7.022436563813896E-4 |

+------------------------------------+

==> null

My environment looks like this:

Description:    Ubuntu 16.04.2 LTS

Java(TM) SE Runtime Environment (build 1.8.0_101-b13)

Java HotSpot(TM) 64-Bit Server VM

PGX Shell 2.4.1

Perhaps am I missing something?

Thanks in advance,

Luis

This post has been answered by oskarvanrest-Oracle on Jun 19 2017
Jump to Answer

Comments

Hello there,

If I recall correctly a colleague this morning gave me a hint (BTW thanks!) related with the fact that I am undirect the graph and my query is looking for directed "->"relations:

SELECT x WHERE (a @ 'SHANG-CHI')->(x), (b @ 'WHITE TIGER/HECTOR A')->(x), (c @ 'IRON FIST/DANIEL RAN')->(x)

So I reload the graph removing the undirection :

pgx> G = session.readGraphWithProperties("/home/lurodrig/development/workspaces/openlab/pgx/superhero-network/hero-network.csv.json")

And now I can find the neighbors of SHANG-CHI

G = session.readGraphWithProperties("/home/lurodrig/development/workspaces/openlab/pgx/superhero-network/hero-network.csv.json")

==> PgxGraph[name=hero-network_2,N=6426,E=574467,created=1497625143082]

pgx> Results = G.queryPgql("SELECT x WHERE (a @ 'SHANG-CHI')->(x)")

==> PgqlResultSetImpl[graph=hero-network_2,numResults=372]

pgx> Results.print(10);

+------------------------------------+

| x                                  |

+------------------------------------+

| PgxVertex[ID=IRON MAN/TONY STARK ] |

| PgxVertex[ID=IRON MAN/TONY STARK ] |

| PgxVertex[ID=FU MANCHU]            |

| PgxVertex[ID=FU MANCHU]            |

| PgxVertex[ID=FU MANCHU]            |

| PgxVertex[ID=FU MANCHU]            |

| PgxVertex[ID=FU MANCHU]            |

| PgxVertex[ID=FU MANCHU]            |

| PgxVertex[ID=FU MANCHU]            |

| PgxVertex[ID=FU MANCHU]            |

+------------------------------------+

So now if I try the original one:

pgx> Results = G.queryPgql("SELECT x WHERE (a @ 'SHANG-CHI')->(x), (b @ 'WHITE TIGER/HECTOR A')->(x), (c @ 'IRON FIST/DANIEL RAN')->(x)")

==> PgqlResultSetImpl[graph=hero-network_2,numResults=551]

It works!

Perhaps the documentation could be updated. Then another question comes to my mind, how to make these kind of queries in a undirected graph. I guess that I will open a new discussion

Hope it helps,

Luis

oskarvanrest-Oracle

Hi Luis,

Thank you for reporting this. Indeed our documentation hasn't been updated properly. PGQL now also supports undirected query edges, so (v1) - (v2) instead of (v1) -> (v2). The semantics are as follows:

  • Directed query edges match only with directed data edges (in directed graphs)
  • Undirected query edges match with undirected data edges (in undirected graphs) and with directed data edges (in directed graphs)

So, to do the query on the undirected graph, it should be:

SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') - (x)

In the PGX version you're using (I think it must be 2.3), there is no exception but an empty result set is returned when using directed query edges on undirected graph.
This appeared to be confusing so in PGX 2.4 we changed it to throw an exception instead: "java.lang.IllegalArgumentException: graph is undirected but at least one edge in the query is directed; use only undirected query edges in combination with undirected graphs (e.g. () - () instead of () -> ())".

We'll update the documentation but the updates will only appear in PGX 2.5.

Thanks again,

Oskar

Hello Oskar,

Thank you very much for your reply.

OK, if I understood correctly from your message If I keep my graph undirected...

G = session.readGraphWithProperties("/home/lurodrig/development/workspaces/openlab/pgx/superhero-network/hero-network.csv.json").undirect()

... I should be able of running my query...

Results = G.queryPgql("SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') - (x)")

...however:

13:50:22,229 ERROR Task - >> [ERROR] MalformedQueryException on analysis-pool: QUERY_PGQL failed

13:50:22,229 ERROR Task - 0. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                     ^

Syntax error, expected: '->'

----------1. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                         ^

Syntax error, expected: '->'

----------2. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                                                           ^

Syntax error, expected: ','

----------3 ERRORS

oracle.pgx.api.MalformedQueryException: 0. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                     ^

Syntax error, expected: '->'

----------1. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                         ^

Syntax error, expected: '->'

----------2. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                                                           ^

Syntax error, expected: ','

----------3 ERRORS

    at oracle.pgx.engine.pgql.PgqlQueryManagerImpl.run(PgqlQueryManagerImpl.java:137)

    at oracle.pgx.engine.CorePgqlImpl.lambda$queryPgql$0(CorePgqlImpl.java:32)

    at oracle.pgx.engine.exec.FunctionRequest.doCall(FunctionRequest.java:33)

    at oracle.pgx.engine.exec.Task.call(Task.java:249)

    at oracle.pgx.engine.exec.Task.run(Task.java:181)

    at oracle.pgx.engine.exec.RtsTask.run(RtsTask.java:39)

    at com.oracle.rts.Job$1.run(Job.java:140)

ERROR: oracle.pgx.api.MalformedQueryException: 0. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                     ^

Syntax error, expected: '->'

----------1. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                         ^

Syntax error, expected: '->'

----------2. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                                                           ^

Syntax error, expected: ','

----------3 ERRORS

I am using pgx 2.4.1:

Hello Oskar,

Thank you very much for your reply.

OK, if I understood correctly from your message If I keep my graph undirected...

G = session.readGraphWithProperties("/home/lurodrig/development/workspaces/openlab/pgx/superhero-network/hero-network.csv.json").undirect()

... I should be able of running my query...

Results = G.queryPgql("SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') - (x)")

...however:

13:50:22,229 ERROR Task - >> [ERROR] MalformedQueryException on analysis-pool: QUERY_PGQL failed

13:50:22,229 ERROR Task - 0. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                     ^

Syntax error, expected: '->'

----------1. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                         ^

Syntax error, expected: '->'

----------2. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                                                           ^

Syntax error, expected: ','

----------3 ERRORS

oracle.pgx.api.MalformedQueryException: 0. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                     ^

Syntax error, expected: '->'

----------1. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                         ^

Syntax error, expected: '->'

----------2. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                                                           ^

Syntax error, expected: ','

----------3 ERRORS

    at oracle.pgx.engine.pgql.PgqlQueryManagerImpl.run(PgqlQueryManagerImpl.java:137)

    at oracle.pgx.engine.CorePgqlImpl.lambda$queryPgql$0(CorePgqlImpl.java:32)

    at oracle.pgx.engine.exec.FunctionRequest.doCall(FunctionRequest.java:33)

    at oracle.pgx.engine.exec.Task.call(Task.java:249)

    at oracle.pgx.engine.exec.Task.run(Task.java:181)

    at oracle.pgx.engine.exec.RtsTask.run(RtsTask.java:39)

    at com.oracle.rts.Job$1.run(Job.java:140)

ERROR: oracle.pgx.api.MalformedQueryException: 0. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                     ^

Syntax error, expected: '->'

----------1. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                         ^

Syntax error, expected: '->'

----------2. ERROR at line 0:

    SELECT x WHERE (a @ 'SHANG-CHI') - (x), (b @ 'WHITE TIGER/HECTOR A') - (x), (c @ 'IRON FIST/DANIEL RAN') -

                                                                                                           ^

Syntax error, expected: ','

----------3 ERRORS

Which I think is correct, because if I have a look at the pgql specification (1.0):

WHERE Clause

WhereClause := 'WHERE' {Constraint ','}+
Constraint := TopologyConstraint |
  ValueConstraint
TopologyConstraint := PathPattern
PathPattern := QueryVertex (QueryConnection QueryVertex)*
QueryVertex := '(' VariableName? LabelConstraint? InlinedConstraints? ')'
QueryConnection := QueryEdge |
  QueryPath // see Section 'Path Queries'
QueryEdge := '->' | '<-' | '-->' | '<--' |
  '-[' VariableName? LabelConstraint? InlinedConstraints? ']->' |
  '<-[' VariableName? LabelConstraint? InlinedConstraints? ']-'
LabelConstraint := ':' {Label '|'}+
InlinedConstraints := 'WITH' {InlinedConstraint ','}+
ValueConstraint := Expression // see Section Expressions
InlinedConstraint := Expression // see Section Expressions

In the QueryEdge part I do not see '-' char anywhere. Perhaps are you working in a new version of the pgql specification?

Thanks in advance,

Luis

BTW, I am using pgx 2.4.1:

pgx --version

[WARNING] neither HADOOP_HOME nor HADOOP_CONF_DIR is set. If loading/storing from/to HDFS, Hadoop default configuration values will be used.

setenv.sh found!

JAVA_HOME set to /home/lurodrig/development/jdks/jdk1.8.0_101

PGX Shell 2.4.1

oskarvanrest-Oracle
Answer

Hi Luis,

I had a look at our change log, but you are right, the undirected query support was not yet there in 2.4.1. It will only be part of 2.5.0 which is not out yet but will be soon (I'll try to remember to let you know through this thread).

So, this is to confirm that in 2.4.1 there is no way to query undirected graphs using PGQL.

Regards,

Oskar

Marked as Answer by Luis Rodriguez Fernandez · Sep 27 2020

Hello Oskar,

Thank you very much for your prompt reply.

OK, great, looking forward for the 2.5.0!

Cheers,

Luis

1 - 5

Post Details

Added on Jun 16 2017
5 comments
748 views