【问题标题】:How to build index in a single groovy script?如何在单个 groovy 脚本中构建索引?
【发布时间】:2020-02-06 07:11:20
【问题描述】:

当我更新了我的 janus 图模式时,我创建了一个属性键但忘记构建索引。如果我使用该属性的这个 buildIndex 运行同一段代码,那么我的数据将获得冗余数据。所以我试图直接在 gremlin 控制台中构建索引。 我试过的是

    :remote connect tinkerpop.server conf/remote.yaml
    // myScript = new File('/tmp/scripts/dbscripts/campaignTypeSchema/01_campaignTypeSchema.groovy').getText('UTF-8')
    // :> @myScript
    :> m = graph.openManagement()


    /** Getting Vertex Labels **/
    :> Campaign = m.getVertexLabel('Campaign')

    /** Vertex Properties creation **/
    :> campaignType = graph.openManagement().getPropertyKey('campaignType')

    /** Vertex supporting indexes **/
    :> graph.openManagement().buildIndex('campaignTypeByCampaign', Vertex.class).addKey(graph.openManagement().getPropertyKey('campaignType')).buildCompositeIndex()
    println "Finished updating schema"
    :remote close
    :x

但最终出现错误

    Error in /tmp/scripts/dbscripts/campaignTypeSchema/run.groovy at [9: :> Campaign = m.getVertexLabel('Campaign')] - No such property: m for class: Script36
    org.apache.tinkerpop.gremlin.jsr223.console.RemoteException: No such property: m for class: Script36
    at org.apache.tinkerpop.gremlin.console.jsr223.DriverRemoteAcceptor.submit(DriverRemoteAcceptor.java:178)
    at org.apache.tinkerpop.gremlin.console.commands.SubmitCommand.execute(SubmitCommand.groovy:41)
    at org.codehaus.groovy.tools.shell.Shell.execute(Shell.groovy:104)
    at org.codehaus.groovy.tools.shell.Groovysh.super$2$execute(Groovysh.groovy)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:145)
    at org.codehaus.groovy.tools.shell.Groovysh.executeCommand(Groovysh.groovy:273)
    at org.codehaus.groovy.tools.shell.Groovysh.execute(Groovysh.groovy:164)
    at org.apache.tinkerpop.gremlin.console.GremlinGroovysh.super$3$execute(GremlinGroovysh.groovy)
    at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:145)
    at org.apache.tinkerpop.gremlin.console.GremlinGroovysh.execute(GremlinGroovysh.groovy:72)
    at org.apache.tinkerpop.gremlin.console.Console$_executeInShell_closure16.doCall(Console.groovy:371)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
    at groovy.lang.Closure.call(Closure.java:418)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.eachWithIndex(DefaultGroovyMethods.java:2041)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.eachWithIndex(DefaultGroovyMethods.java:2021)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.eachWithIndex(DefaultGroovyMethods.java:2071)
    at org.codehaus.groovy.runtime.dgm$175.doMethodInvoke(Unknown Source)
    at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:236)
    at org.apache.tinkerpop.gremlin.console.Console.executeInShell(Console.groovy:348)
    at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:236)
    at org.apache.tinkerpop.gremlin.console.Console.<init>(Console.groovy:141)
    at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:236)
    at org.apache.tinkerpop.gremlin.console.Console.main(Console.groovy:453)

然后我尝试直接在gremlin控制台中运行

    gremlin> :> graph.openManagement().buildIndex('campaignTypeByCampaign', Vertex.class).addKey(graph.openManagement().getPropertyKey('campaignType')).buildCompositeIndex()

为此我收到一条错误消息

    The vertex or type is not associated with this transaction [campaignType]

【问题讨论】:

    标签: groovy gremlin janusgraph


    【解决方案1】:

    您需要将远程连接创建为会话:

    :remote connect tinkerpop.server conf/remote.yaml session
    

    here 所述,否则变量状态将不会在命令之间保持不变。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 2021-03-23
      • 1970-01-01
      相关资源
      最近更新 更多