【问题标题】:How to set schema for janusgraph for batch-loading using python如何为janusgraph设置模式以使用python进行批量加载
【发布时间】:2018-05-16 19:12:58
【问题描述】:

我正在尝试通过 HBase 将数据批量加载到 janusgraph 0.2 中。我正在使用 python 的 gremlinpython 库。对于批量加载,我将storage.batch-loading 设置为true,现在必须为图形定义架构。

我找到了为图表设置架构的文档 (https://docs.janusgraph.org/0.2.0/schema.html & https://docs.janusgraph.org/0.2.0/advanced-schema.html)。

它建议了一些基本的架构代码:

mgmt = graph.openManagement()
follow = mgmt.makeEdgeLabel('follow').multiplicity(MULTI).make()
mother = mgmt.makeEdgeLabel('mother').multiplicity(MANY2ONE).make()
mgmt.commit()

我使用 python 的 gremlinpython 库连接到图形。这就是我正在做的:

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
from    gremlin_python.process.traversal                import  T
from    gremlin_python.process.traversal                import  Order
from    gremlin_python.process.traversal                import  Cardinality
from    gremlin_python.process.traversal                import  Column
from    gremlin_python.process.traversal                import  Direction
from    gremlin_python.process.traversal                import  Operator
from    gremlin_python.process.traversal                import  P
from    gremlin_python.process.traversal                import  Pop
from    gremlin_python.process.traversal                import  Scope
from    gremlin_python.process.traversal                import  Barrier

from    config                                          import  graph_url, graph_name

graph = Graph()
drc = DriverRemoteConnection(graph_url, graph_name)

g = graph.traversal().withRemote(drc)

# I successfully get g here, I check it by :
# g.V().count().next()

现在我的问题是,我应该在哪里设置架构。我尝试在注释掉的行之后执行mgmt = graph.openManagement(),但它不起作用。


更新

它在 gremlin 控制台上工作为:

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> 
gremlin> :> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@625dfab4 

但是任何进一步的命令在这里都不起作用:

:> follow = mgmt.makeEdgeLabel('follow').multiplicity(MULTI).make()
No such property: mgmt for class: Script10

【问题讨论】:

    标签: python gremlin bulk-load janusgraph gremlin-server


    【解决方案1】:

    gremlinpython 驱动程序是Gremlin Language Variant (GLV),它允许您在编程语言 Python 中本地使用 Gremlin。 JanusGraph 架构定义特定于 JanusGraph db,但是 gremlinpython GLV 是通用的 TinkerPop 驱动程序,因此它没有调用特定于 db 的 API 的构造。

    如您所述,您可以通过 Gremlin 控制台声明您的架构。另一种选择是使用基于字符串的 Gremlin 驱动程序,例如 gremlinclient 或 gremlinpy,并将您的架构作为字符串查询发送到服务器。

    【讨论】:

    • 在 gremlin 控制台上,定义 mgmt 后,我无法再次使用它,正如我在最后提到的那样。你知道这是为什么吗?
    • 因为您将远程连接创建为无会话。查看 TinkerPop 文档,了解如何使用 sessions。 :remote connect tinkerpop.server conf/remote.yaml session
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多