pietermartin / sqlg

TinkerPop graph over sql
MIT License
246 stars 51 forks source link

Implementing shortest path, does sqlg supports repeat().times().cap() #380

Closed MartinBrugnara closed 4 years ago

MartinBrugnara commented 4 years ago

Hi all, I've got 1 error and 2 questions... Error

Caused by: java.lang.NoSuchMethodError: 'void org.apache.tinkerpop.gremlin.process.traversal.Traverser$Admin.incrLoops(java.lang.String)'
    at org.umlg.sqlg.step.barrier.SqlgRepeatStepBarrier$SqlgRepeatEndStepBarrier.standardAlgorithm(SqlgRepeatStepBarrier.java:317)

Questions 1) does sqlg support the repeat().times().cap() pattern? 2) if yes, why is the following exploding?

Context

Version

        <dependency>
            <groupId>org.umlg</groupId>
            <artifactId>sqlg-core</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.umlg</groupId>
            <artifactId>sqlg-postgres-dialect</artifactId>
            <version>2.0.1</version>
        </dependency>

Code

BFS Find the number of paths from source_id with up to depth edges.

gts.V(source_id)
   .repeat(__.both().where(P.without("x")).aggregate("x"))
   .times(depth)
   .cap("x")
   .count()
   .next();

Shortest path

gts.V(source_id)
  .repeat(__.both().where(P.without("x")).aggregate("x"))
  .until(__.hasId(target_id))
  .limit(1).path().count(Scope.local).next();

Stack trace

https://pastebin.com/B0fuik4V

MartinBrugnara commented 4 years ago

I have actually drilled down the problem to the repeat() step.

I have tried to replace the "x" with the more standard .repeat(__.both().simplePath()), but it produces the same exception.

The only way it works is by allowing cycles, tough this is not useful for BFS or shortest path...

--
Does anyone have a pattern to implement bfs and shortest path?

pietermartin commented 4 years ago

Hi, it is suppose to work. I have used the same query quite a few times. Can you post some sample data then I'll try reproduce your error.

Ok sorry only reading your error properly now. It seems more of a dependency version issue.

Can you try it just with plain java and not via some or other shell?

pietermartin commented 4 years ago
        List<Path> vertices = this.sqlgGraph.traversal()
                .V()
                .hasLabel("Transmission")
                .repeat(__.both("link").simplePath())
                .until(
                        __.or(
                                __.has("type", P.within("HubSite", "ASwitch", "BSwitch")),
                                __.has("excluded", true),
                                __.loops().is(12)
                        )
                )
                .path()
                .simplePath()
                .toList();

This is a query that I have running on a production system.

MartinBrugnara commented 4 years ago

Thanks @pietermartin for the quick response.

This is the dataset we are using for development: https://pastebin.com/3YpCcKz3 . It is "thinker pop modern" with the addition of a property to all nodes, uid, that act as a unique identifier over all nodes.

I am interacting directly from java. The "shell" you see in the stacktrace is just one of my packages. But I understand the confusion =)

I will try your solution and report back, thanks again!

MartinBrugnara commented 4 years ago

I noticed I forgot to mention the version of thinkerpop I am using, here it is:

       <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-core</artifactId>
            <version>3.4.2</version>
        </dependency>

I tested the following query as you suggested but it still raises the same exception (the query itself is god, I tested it against other systems).

List<Path> p = gts.V(source_id)
        .repeat(__.both().simplePath())
        .until(__.loops().is(depth))
        .path()
        .simplePath()
        .toList();

I also tried:

pietermartin commented 4 years ago

Sqlg already imports the TinkerPop version it runs on. Sqlg 2.0.1 runs on TinkerPop 3.3.4 If want more up to date you can try Sqlg 2.0.2-SNAPSHOT which runs on TinkerPop 3.4.1

MartinBrugnara commented 4 years ago

This seams an interesting debug path; I noticed there no tag yet for 2.0.2-SNAPSHOT, nor artifact, and the commit mentioning it (258fcda338b051484a25acb4c96caa27dff069b8) still uses 3.3.4.

Do you suggest to build from HEAD or do you have any particular commit in mind?

Thanks!

pietermartin commented 4 years ago

2.0.2-SNAPSHOT is uploaded to maven snapshot repo. It is the current master branch. https://github.com/pietermartin/sqlg/blob/master/pom.xml references 3.4.1

I am hoping to release it but alas work pressure is just not making me get there. There is one bug/change on postgresql 11 that still needs sorting.

For what its worth I am running on 2.0.2-SNAPSHOT for quite some time in production already. So its quite stable.

MartinBrugnara commented 4 years ago

I confirm this fixes the issue. So I guess it was a thinkerpop api compatibility issue.

Thanks for sqlg and the help @pietermartin !!

pietermartin commented 4 years ago

Nice, glad its working.