【问题标题】:How to add properties with a specific type into gremlinpython?如何将具有特定类型的属性添加到 gremlinpython?
【发布时间】:2021-02-12 13:18:14
【问题描述】:

目前我正在尝试通过gremlinpython 以编程方式从 igraph 导入一个大图。我对 gremlin 和我可能使用它的端点相当陌生。我目前面临的问题是节点/边中的属性可以有多种类型。 (例如:-> Bool 或 None 类型 | Int、Long 等。)

在将其导入此gremlin-server 时,我没有注意到任何错误(这是否称为 Apache TinkerGraph-Server?我应该如何称呼它?)。看来相同属性的类型可以是任意的。

但是,当使用 JanusGraph 时,我收到多个错误: gremlin_python.driver.protocol.GremlinServerError: 500: Value [XXX] is not an instance of the expected data type for property key [YYY] and cannot be converted. Expected: class <SomeClass>, found: class <SomeOtherClass>

例如执行:

conn = DriverRemoteConnection("ws://localhost:8182/gremlin", "g")
remote_graph = traversal().withRemote(conn)

remote_graph.addV().property("test", 10000).next()
remote_graph.addV().property("test", 100000000000000000000000).next()  # <- Causes an error on JanusGraph

我可以将一些属性转换为其他数据类型(Bool/None-Type-> -1,0,1),所以我可以避免这个错误。但我不确定我应该如何处理上面提供的示例。有没有办法显式设置属性的类型(至少对于数字类型),以便服务器知道存储它,例如作为 Long/BigInt 而不是 Int?尤其是在 python3 中,long(/bigint) 和 int 之间没有区别了。

那么具体来说有没有类似以下的内容?: 例如。执行:


remote_graph.addV().property("test", 10000).asLong().next()
remote_graph.addV().property("test", 10000, <Type: Long>).next()

【问题讨论】:

    标签: gremlin janusgraph gremlinpython


    【解决方案1】:

    Gremlin 确实有一个 special class 用于确保 Java Long。你可以只做 long(10000) 给定适当的导入,如:from gremlin_python.statics import long

    【讨论】:

    • 谢谢。它确实适用于此导入。这也记录在某处吗?
    • 这并不像应有的那样明确。我将对参考文档进行补充。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    相关资源
    最近更新 更多