northwesternmutual / grammes

A Go package built to communicate with Apache TinkerPop™ Graph computing framework using Gremlin; a graph traversal language used by graph databases such as JanusGraph®, MS Cosmos DB, AWS Neptune, and DataStax® Enterprise Graph.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Steps .Where() and .Or() are not working. (Neptune)

sizovilya opened this issue · comments

Hello guys.
While i was writing some not trivial query with grammes i saw that steps .Where() and .Or() are not working. (Or i did something wrong.)
Can you check the syntax of my query ?

		jsonRes, executionError = gremlin.Client.ExecuteQuery(
			g.
				V(vertex.ID()).
				OutE(ConsistsEdgeLabel).
				InV().
				Has(PostVertexLabel, DeletedProperty, false).
				Where(
					g.Or(
						g.
								InE(CreatedEdgeLabel).
								OutV().
								Has(UserVertexLabel, DeletedProperty, false).
								Has(UserVertexLabel, PrivacyProperty, 1),
						g.
								InE(CreatedEdgeLabel).
								OutV().
								Has(UserVertexLabel, DeletedProperty, false).
								Has(UserVertexLabel, PrivacyProperty, 0).
								InE(SubscribedEdgeLabel).
								OutV().
								Has(UserVertexLabel, UserIdProperty, userId),
						),
				).
				Not(
				g.
						InE(CreatedEdgeLabel).
						OutV().
						Has(UserVertexLabel, DeletedProperty, false).
						OutE(BlacklistEdgeLabel).
						InV().
						Has(UserVertexLabel, UserIdProperty, userId),
				).
				Order().By(sort, traversal.Custom(order)).
				Fold().
				As("posts", "count").
				Select("posts", "count").
				By(g.Range(scope.Local, offset, offset+count)).
				By(g.Count(scope.Local)),
		)

Is it right ?
Logs:

2020-07-24T17:33:59.052+0300    debug   logging/debuglogger.go:46       [Grammes]       {"query": "g.V(\"4cb9c099-f25d-ffa6-2048-c15bcd957193\").outE(\"consists\").inV().has(\"post\",\"deleted\",false).where(g.or(inE(\"created\").outV().has(\"user\",\"deleted\",false).has(\"user\",\"privacy\",1),inE(\"created\").outV().has(\"user\",\"deleted\",false).has(\"user\",\"privacy\",0).inE(\"subscribed\").outV().has(\"user\",\"userId\",\"5\"))).not(inE(\"created\").outV().has(\"user\",\"deleted\",false).outE(\"blacklist\").inV().has(\"user\",\"userId\",\"5\")).order().by(\"date_created\",desc).fold().as(\"posts\",\"count\").select(\"posts\",\"count\").by(range(local,2,12)).by(count(local))"}
2020-07-24T17:33:59.111+0300    error   logging/debuglogger.go:51       retrieving response     {"error": "{\"type\":\"GRAMMES_ERROR\"},{\"function\":\"executeRequest\"},{\"error\":\"{\"type\":\"NETWORK_ERROR\"},{\"status code\":\"499\"},{\"error\":\"INVALID REQUEST ARGUMENTS\"},{\"original error\":\"{\"requestId\":\"b612f3d8-cdba-11ea-ab1c-6c96cfdf7989\",\"code\":\"MalformedQueryException\",\"detailedMessage\":\"Query parsing failed at line 1, character position at 103, error message : no viable alternative at input 'g.V(\\\"4cb9c099-f25d-ffa6-2048-c15bcd957193\\\").outE(\\\"consists\\\").inV().has(\\\"post\\\",\\\"deleted\\\",false).where(g.or'\"}\"}\"}"}
github.com/northwesternmutual/grammes/logging.(*DebugLogger).Error
        /Users/ilya/Documents/git/pkg/mod/github.com/northwesternmutual/grammes@v1.2.0/logging/debuglogger.go:51
github.com/northwesternmutual/grammes.(*Client).executeRequest
        /Users/ilya/Documents/git/pkg/mod/github.com/northwesternmutual/grammes@v1.2.0/request.go:58
github.com/northwesternmutual/grammes/manager.(*queryManager).ExecuteBoundStringQuery
        /Users/ilya/Documents/git/pkg/mod/github.com/northwesternmutual/grammes@v1.2.0/manager/query.go:83
github.com/northwesternmutual/grammes/manager.(*queryManager).ExecuteQuery
        /Users/ilya/Documents/git/pkg/mod/github.com/northwesternmutual/grammes@v1.2.0/manager/query.go:55
gitlab.allabout.me/new-app/hashtag/hashtag-service/model.Hashtag.GetPosts
        /Users/ilya/Documents/git/hashtag-service/model/hashtag_get_posts.go:93
gitlab.allabout.me/new-app/hashtag/hashtag-service/hashtag.Server.GetPosts
        /Users/ilya/Documents/git/hashtag-service/hashtag/get_posts.go:67
gitlab.allabout.me/new-app/libraries/protos/codegen/go/hashtag._Hashtag_GetPosts_Handler
        /Users/ilya/Documents/git/pkg/mod/gitlab.allabout.me/new-app/libraries/protos@v1.0.4-0.20200716091454-c16a7ee10811/codegen/go/hashtag/hashtag.pb.go:1700
google.golang.org/grpc.(*Server).processUnaryRPC
        /Users/ilya/Documents/git/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1082
google.golang.org/grpc.(*Server).handleStream
        /Users/ilya/Documents/git/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1405
google.golang.org/grpc.(*Server).serveStreams.func1.1
        /Users/ilya/Documents/git/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:746

PS:
I reproduced this query with gremlin.js and it works right.

  const currentUserId = "5";
  const res = await g
    .V()
    .has('hashtag', 'val', 'vacation')
    .outE("consists")
    .inV()
    .has("post","deleted",false)
    .where(
      _.or(
        _.inE("created")
          .outV()
          .has("user","deleted",false)
          .has("user","privacy",1),
        _.inE("created")
          .outV()
          .has("user","deleted",false)
          .has("user","privacy",0)
          .inE("subscribed")
          .outV()
          .has("user","userId",currentUserId)
      )
    )
    .not(
      _.inE("created")
        .outV()
        .has("user","deleted",false)
        .outE("blacklist")
        .inV()
        .has("user","userId",currentUserId)
    )
    .order().by("date_created",order.desc)
    .fold()
    .as("posts","count")
    .select("posts","count")
    .by(gremlin.process.statics.range(gremlin.process.scope.local,0,10))
    .by(gremlin.process.statics.count(gremlin.process.scope.local))
    .toList();

Hi, can you print g to console and paste the output here in order to see query output?