如何将部署在GCP中的Janusgraph与Python运行时连接?

huangapple go评论55阅读模式
英文:

How to connect Janusgraph deployed in GCP with Python runtime?

问题

I have deployed the Janusgraph using Helm in Google Cloud Containers, following the below documentation:

https://cloud.google.com/architecture/running-janusgraph-with-bigtable,

I'm able to fire the Gremlin query using Google Cloud Shell.

Snapshot of Google Cloud Shell

Now I want to access the Janusgraph using Python. I tried the below line of code, but it's unable to connect to Janusgraph inside the GCP container.

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('gs://127.0.0.1:8182/gremlin','g'))
value = g.V().has('name','hercules').values('age')
print(value)

Here's the output I'm getting:

[['V'], ['has', 'name', 'hercules'], ['values', 'age']]

Whereas the output should be:

30

Is there someone who has tried to access Janusgraph using Python inside GCP?

英文:

I have deployed the Janusgraph using Helm in Google cloud Containers, following the below documentation:

https://cloud.google.com/architecture/running-janusgraph-with-bigtable,

I'm able to fire the gremline query using Google Cloud Shell.

Snapshot of GoogleCLoud Shell

Now I want to access the Janusgraph using Python, I tried below line of code but it's unable to connect to Janusgraph inside GCP container.

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('gs://127.0.0.1:8182/gremlin','g'))
value = g.V().has('name','hercules').values('age')
print(value)

here's the output I'm getting

[['V'], ['has', 'name', 'hercules'], ['values', 'age']]

Whereas the output should be -

30

Is there someone tried to access Janusgraph using Python inside GCP.

答案1

得分: 1

你需要以终端步骤,如 nexttoList 结束查询。您看到的是查询字节码,因为由于缺少终端步骤,查询从未提交到服务器。所以您需要类似这样的内容:

value = g.V().has('name','hercules').values('age').next()
print(value)
英文:

You need to end the query with a terminal step such as next or toList. What you are seeing is the query bytecode printed as the query was never submitted to the server due to the missing terminal step. So you need something like this:

value = g.V().has('name','hercules').values('age').next()
print(value)

huangapple
  • 本文由 发表于 2023年1月9日 17:57:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055600.html
  • google-cloud-bigtable
  • google-cloud-platform
  • google-kubernetes-engine
  • gremlinpython
  • janusgraph
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定