如何用mogwai执行gremlin查询 [英] How to execute gremlin query with mogwai

查看:199
本文介绍了如何用mogwai执行gremlin查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过mogwai查询一个titan db 0.5.4,但是当我运行下面的脚本时,我得到这个错误:rexpro.exceptions.RexProScriptException:事务没有打开



我在这里发现了相同的问题



PS没有mogwai的标签



脚本:

 #!/ usr / bin / env python3 $ b $ m from mogwai.connection import execute_query,setup 


con = setup('127.0.0.1',graph_name =bio4j,username =re,password =re)

results = execute_query(2 * a,params = { a:2},connection = con)
print(results)

$ b $ result = execute_query(bio4j.E,params = {},connection = con)
print(results)

log:

  $ ./bin/rexster.sh --start 
0 [main] INFO com.tinkerpop.rexster.Application - 。:欢迎来到Rexst呃:.
93 [main] INFO com.tinkerpop.rexster.server.RexsterProperties - 使用[/Users/Phoenix/Dropbox/Graph4Bio/Titan/rexhome/config/rexster.xml]作为配置源。
102 [main] INFO com.tinkerpop.rexster.Application - Rexster正在观看[/Users/Phoenix/Dropbox/Graph4Bio/Titan/rexhome/config/rexster.xml]进行更改。
730 [main] INFO com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration - 生成的唯一实例id = 0a69045d1736 -AngryMac-local1
804 [main] INFO com.thinkaurelius.titan.diskstorage。后端 - 启动的后端操作线程池的大小为8
905 [main] INFO com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLog - 加载未识别的ReadMarker开始时间时间点[1455128079919000μs]转换为com.thinkaurelius.titan。 diskstorage.log.kcvs.KCVSLog$MessagePuller@302c971f
908 [main] INFO com.tinkerpop.rexster.RexsterApplicationGraph - Graph [bio4j] - 配置了允许的命名空间[tp:gremlin]
932 [main] INFO com.tinkerpop.rexster.config.GraphConfigurationContainer - Graph bio4j - titangraph [berkeleyje:/ Users / Phoenix / Dropbox / Graph4Bio / Bio4j / bio4j] loaded
939 [main] INFO com.tinkerpop.rexster.server.metrics .HttpReporterConfig - 配置的HTTP Metric Reporter。
941 [main] INFO com.tinkerpop.rexster.server.metrics.ConsoleReporterConfig - 配置的控制台度量报告器。
2058 [main] INFO com.tinkerpop.rexster.server.HttpRexsterServer - HTTP / REST线程池配置:kernal [4/4] worker [8/8]
2060 [main] INFO com.tinkerpop .rexster.server.HttpRexsterServer - 对于HTTP / REST使用org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy IOStrategy。
2160 [main] INFO com.tinkerpop.rexster.server.HttpRexsterServer - Rexster Server运行于:[http:// localhost:8182]
2160 [main] INFO com.tinkerpop.rexster.server。 RexProRexsterServer - 对于RexPro使用org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy IOStrategy。
2160 [main] INFO com.tinkerpop.rexster.server.RexProRexsterServer - RexPro线程池配置:kernal [4/4] worker [8/8]
2162 [main] INFO com.tinkerpop.rexster .server.RexProRexsterServer - 使用[DefaultSecurity]配置的Rexster。
2163 [main] INFO com.tinkerpop.rexster.server.RexProRexsterServer - RexPro Server绑定到[0.0.0.0:8184]
2177 [main] INFO com.tinkerpop.rexster.server.ShutdownManager - 绑定关闭套接字到/127.0.0.1:8183。为关闭请求启动侦听器线程。
152568 [Grizzly(2)SelectorRunner] INFO com.tinkerpop.rexster.protocol.EngineController - ScriptEngineManager的工厂用于:ECMAScript
152568 [Grizzly(2)SelectorRunner] INFO com.tinkerpop.rexster.protocol。 EngineController - ScriptEngineManager的工厂为:gremlin-groovy
152568 [Grizzly(2)SelectorRunner] INFO com.tinkerpop.rexster.protocol.EngineController - Registered ScriptEngine for:gremlin-groovy
152569 [Grizzly(2) SelectorRunner] INFO com.tinkerpop.rexster.protocol.EngineHolder - 使用其他导入初始化gremlin-groovy引擎。
153259 [Grizzly(2)SelectorRunner] INFO com.tinkerpop.rexster.protocol.EngineHolder - 使用自定义脚本初始化ScriptEngine
154074 [Grizzly(2)SelectorRunner] INFO com.tinkerpop.rexster.protocol。 EngineController - ScriptEngineManager的工厂用于:Groovy
154076 [Grizzly(2)SelectorRunner] INFO com.tinkerpop.rexster.protocol.session.RexProSessions - RexPro创建的会话:a2b416ce-75ea-4ecb-9835-b287162c90cb
154354 [Grizzly(4)] INFO com.tinkerpop.rexster.protocol.session.RexProessessions - 尝试销毁RexPro Session:a2b416ce-75ea-4ecb-9835-b287162c90cb
154355 [Grizzly(4)] INFO com.tinkerpop .rexster.protocol.session.RexProessions - RexPro会话被销毁或不存在:a2b416ce-75ea-4ecb-9835-b287162c90cb
154356 [Grizzly(5)] INFO com.tinkerpop.rexster.protocol.session。 RexProSessions - RexPro创建的会话:5b8a669f-615d-4f84-9d1e-2d10624347f0
154525 [Grizzly(7)] WARN com.tinkerpop.rexster.protocol.server.S criptServer - 无法在会话[[B @ 6634722f]和请求[[B @ 68f38099]
154527 [Grizzly(8)] INFO com.tinkerpop.rexster上处理语言[groovy]的脚本[bio4j.E]。 protocol.session.RexProessessions - 尝试销毁RexPro会话:5b8a669f-615d-4f84-9d1e-2d10624347f0
154527 [Grizzly(8)] INFO com.tinkerpop.rexster.protocol.session.RexProSessions - RexPro会话被破坏或不会否则存在:5b8a669f-615d-4f84-9d1e-2d10624347f0
154529 [Grizzly(1)] INFO com.tinkerpop.rexster.protocol.session.RexProSessions - 尝试销毁RexPro会话:00000000-0000-0000- 0000-000000000000
154529 [Grizzly(1)] INFO com.tinkerpop.rexster.protocol.session.RexProSessions - RexPro会话被销毁或不存在:00000000-0000-0000-0000-000000000000


解决方案

mogwai的维护人员在这里。



你正在使用什么版本的mogwai?在0.7.7中没有设置方法的返回值,并且连接对象不应该被传递。事实上,当你调用setup时,它会创建一个连接池(一个同步rexpro连接池,因为没有指定并发选项)。所以一般来说,在你的应用程序的整个生命周期中调用一次setup,你就可以在不带任何引用的情况下使用execute查询。

这个消息特别突出:

  154525 [Grizzly(7)] WARN com.tinkerpop.rexster.protocol.server.ScriptServer  - 无法处理脚本[bio4j.E]对于会话[[B @ 6634722f]和请求[[B @ 68f38099] 



的语言[groovy]您的图形是否配置了图形名称bio4j?默认的titan图形名称是图形,默认图形对象名称mogwai使用的是g。如果你有一个图形名称为bio4j,你不会直接引用它,你可以使用与事务关联的图形对象名称。您可以将图名称视为SQL数据库中的数据库名称,而图形对象是对所述数据库的事务引用。这是在启动泰坦时在xml配置文件中配置的。特别是:

 <图表> 
<图表>
<图表名称>图表< /图表名称>
....
< /图表>
< /图表>所以假设你将其从graph更改为bio4j,并在设置中保留默认的graph_obj_name函数为g,那么你的查询应该是gE。


Im trying to query a titan db 0.5.4 via mogwai, but when I run the following script i get the error: rexpro.exceptions.RexProScriptException: transaction is not open

and I found the same question here

P.S there is no tag for mogwai

script:

#!/usr/bin/env python3
from mogwai.connection import execute_query, setup


con = setup('127.0.0.1', graph_name="bio4j", username="re", password="re")

results = execute_query("2 * a",params={"a":2}, connection= con)
print(results)


results = execute_query("bio4j.E",params={}, connection= con)
print(results)

log:

$ ./bin/rexster.sh --start
0    [main] INFO  com.tinkerpop.rexster.Application  - .:Welcome to Rexster:.
93   [main] INFO  com.tinkerpop.rexster.server.RexsterProperties  - Using [/Users/Phoenix/Dropbox/Graph4Bio/Titan/rexhome/config/rexster.xml] as configuration source.
102  [main] INFO  com.tinkerpop.rexster.Application  - Rexster is watching [/Users/Phoenix/Dropbox/Graph4Bio/Titan/rexhome/config/rexster.xml] for change.
730  [main] INFO  com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration  - Generated unique-instance-id=0a69045d1736-AngryMac-local1
804  [main] INFO  com.thinkaurelius.titan.diskstorage.Backend  - Initiated backend operations thread pool of size 8
905  [main] INFO  com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLog  - Loaded unidentified ReadMarker start time Timepoint[1455128079919000 μs] into com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLog$MessagePuller@302c971f
908  [main] INFO  com.tinkerpop.rexster.RexsterApplicationGraph  - Graph [bio4j] - configured with allowable namespace [tp:gremlin]
932  [main] INFO  com.tinkerpop.rexster.config.GraphConfigurationContainer  - Graph bio4j - titangraph[berkeleyje:/Users/Phoenix/Dropbox/Graph4Bio/Bio4j/bio4j] loaded
939  [main] INFO  com.tinkerpop.rexster.server.metrics.HttpReporterConfig  - Configured HTTP Metric Reporter.
941  [main] INFO  com.tinkerpop.rexster.server.metrics.ConsoleReporterConfig  - Configured Console Metric Reporter.
2058 [main] INFO  com.tinkerpop.rexster.server.HttpRexsterServer  - HTTP/REST thread pool configuration: kernal[4 / 4] worker[8 / 8] 
2060 [main] INFO  com.tinkerpop.rexster.server.HttpRexsterServer  - Using org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy IOStrategy for HTTP/REST.
2160 [main] INFO  com.tinkerpop.rexster.server.HttpRexsterServer  - Rexster Server running on: [http://localhost:8182]
2160 [main] INFO  com.tinkerpop.rexster.server.RexProRexsterServer  - Using org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy IOStrategy for RexPro.
2160 [main] INFO  com.tinkerpop.rexster.server.RexProRexsterServer  - RexPro thread pool configuration: kernal[4 / 4] worker[8 / 8] 
2162 [main] INFO  com.tinkerpop.rexster.server.RexProRexsterServer  - Rexster configured with [DefaultSecurity].
2163 [main] INFO  com.tinkerpop.rexster.server.RexProRexsterServer  - RexPro Server bound to [0.0.0.0:8184]
2177 [main] INFO  com.tinkerpop.rexster.server.ShutdownManager  - Bound shutdown socket to /127.0.0.1:8183. Starting listener thread for shutdown requests.
152568 [Grizzly(2) SelectorRunner] INFO  com.tinkerpop.rexster.protocol.EngineController  - ScriptEngineManager has factory for: ECMAScript
152568 [Grizzly(2) SelectorRunner] INFO  com.tinkerpop.rexster.protocol.EngineController  - ScriptEngineManager has factory for: gremlin-groovy
152568 [Grizzly(2) SelectorRunner] INFO  com.tinkerpop.rexster.protocol.EngineController  - Registered ScriptEngine for: gremlin-groovy
152569 [Grizzly(2) SelectorRunner] INFO  com.tinkerpop.rexster.protocol.EngineHolder  - Initializing gremlin-groovy engine with additional imports.
153259 [Grizzly(2) SelectorRunner] INFO  com.tinkerpop.rexster.protocol.EngineHolder  - ScriptEngine initializing with a custom script
154074 [Grizzly(2) SelectorRunner] INFO  com.tinkerpop.rexster.protocol.EngineController  - ScriptEngineManager has factory for: Groovy
154076 [Grizzly(2) SelectorRunner] INFO  com.tinkerpop.rexster.protocol.session.RexProSessions  - RexPro Session created: a2b416ce-75ea-4ecb-9835-b287162c90cb
154354 [Grizzly(4)] INFO  com.tinkerpop.rexster.protocol.session.RexProSessions  - Try to destroy RexPro Session: a2b416ce-75ea-4ecb-9835-b287162c90cb
154355 [Grizzly(4)] INFO  com.tinkerpop.rexster.protocol.session.RexProSessions  - RexPro Session destroyed or doesn't otherwise exist: a2b416ce-75ea-4ecb-9835-b287162c90cb
154356 [Grizzly(5)] INFO  com.tinkerpop.rexster.protocol.session.RexProSessions  - RexPro Session created: 5b8a669f-615d-4f84-9d1e-2d10624347f0
154525 [Grizzly(7)] WARN  com.tinkerpop.rexster.protocol.server.ScriptServer  - Could not process script [bio4j.E] for language [groovy] on session [[B@6634722f] and request [[B@68f38099]
154527 [Grizzly(8)] INFO  com.tinkerpop.rexster.protocol.session.RexProSessions  - Try to destroy RexPro Session: 5b8a669f-615d-4f84-9d1e-2d10624347f0
154527 [Grizzly(8)] INFO  com.tinkerpop.rexster.protocol.session.RexProSessions  - RexPro Session destroyed or doesn't otherwise exist: 5b8a669f-615d-4f84-9d1e-2d10624347f0
154529 [Grizzly(1)] INFO  com.tinkerpop.rexster.protocol.session.RexProSessions  - Try to destroy RexPro Session: 00000000-0000-0000-0000-000000000000
154529 [Grizzly(1)] INFO  com.tinkerpop.rexster.protocol.session.RexProSessions  - RexPro Session destroyed or doesn't otherwise exist: 00000000-0000-0000-0000-000000000000

解决方案

Maintainer of mogwai here.

What version of mogwai are you using? in 0.7.7 there is no return value for setup method and the connection object should not be passed around. In fact when you call setup it creates a connection pool (a synchronous rexpro connection pool since there was no concurrency option specified). So in general, just call setup once for the life of your app and you can use execute query without any references.

Also this message in particular stands out:

154525 [Grizzly(7)] WARN  com.tinkerpop.rexster.protocol.server.ScriptServer  - Could not process script [bio4j.E] for language [groovy] on session [[B@6634722f] and request [[B@68f38099]

Is your graph configured with a graph name of "bio4j"? The default titan graph name is "graph" and the default graph object name mogwai uses is "g". If you have a graph name of "bio4j" you wouldn't reference this directly, you'd use the graph object name associated to the transaction. You can think of a graph-name as a database name in a SQL database, and the graph object being the transactional reference to said database. This is configured in the xml configuration file when starting titan. Particularly:

<graphs>
    <graph>
        <graph-name>graph</graph-name>
        ....
    </graph>
</graphs>

So assuming you changed that from "graph" to "bio4j" and left the default graph_obj_name in the setup function as "g", then your query should read "g.E".

这篇关于如何用mogwai执行gremlin查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆