首页 文章

gremlin CosmosDB中的存储过程

提问于
浏览
1

我是 gremlincosmos DB 的新手,并且正在尝试在cosmos DB gremlin API中使用 Stored Procedure .

我从Quick-start-nodejs doc开始创建一个与CosmosDB gremlin API连接的node.js应用程序 . 现在我想在该应用程序中使用存储过程 . 我发现cosmos DB中的存储过程只有单个doc,并且's only for Document DB (in SQL). I didn't在gremlin中找到了与存储过程相关的任何文档 .

任何人都可以指导我,怎么做?

提前致谢 .

2 回答

  • 0

    你的用例是什么?

    Gremlin是一种遍历图形的语言 . Gremlin不了解CosmosDB存储过程,因此您无法通过gremlin真正执行存储过程 .

    但是,CosmosDB是多模型的 . 您可以通过gremlin以及原生DocumentDB API与之交谈 .

    您应该了解如何通过DocumentDB API执行存储过程 .

  • 0

    根据您对问题的第一个答案的评论:"Actually I want to add some edges every time a new vertex is created. For example, whenever a vertex with the label EMPLOYEE is created, an edge to the vertex COMPANY must be automatically created." here,您可以查看TinkerPop的EventStrategy .

    编辑:

    如果链接发生变化,请从上面的链接添加基本部分:

    EventStrategy的目的是将事件引发到一个或多个MutationListener对象,因为在遍历中发生对底层Graph的更改 . 此类策略对于记录更改,根据更改触发某些操作或在遍历期间需要通知某些变异操作的任何应用程序非常有用 . 如果事务回滚,则重置事件队列 .

    将以下事件引发到MutationListener:

    • 新顶点

    • 新优势

    • 顶点属性已更改

    • Edge属性已更改

    • 已删除顶点属性

    • 已删除Edge属性

    • 顶点已删除

    • 边缘已删除

    要从Traversal开始处理事件,首先要实现MutationListener接口 . 此实现的一个示例是ConsoleMutationListener,它将输出写入控制台以用于每个事件 . 以下控制台会话显示基本用法:

    gremlin> import org.apache.tinkerpop.gremlin.process.traversal.step.util.event.*
    ==>org.apache.tinkerpop.gremlin.structure.*, org.apache.tinkerpop.gremlin.structure.util.*, org.apache.tinkerpop.gremlin.process.traversal.*, org.apache.tinkerpop.gremlin.process.traversal.step.*, org.apache.tinkerpop.gremlin.process.remote.*, org.apache.tinkerpop.gremlin.structure.util.empty.*, org.apache.tinkerpop.gremlin.structure.io.*, org.apache.tinkerpop.gremlin.structure.io.graphml.*, org.apache.tinkerpop.gremlin.structure.io.graphson.*, org.apache.tinkerpop.gremlin.structure.io.gryo.*, org.apache.commons.configuration.*, org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.*, org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.*, org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.*, org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.*, org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.*, org.apache.tinkerpop.gremlin.process.traversal.util.*, org.apache.tinkerpop.gremlin.process.computer.*, org.apache.tinkerpop.gremlin.process.computer.bulkdumping.*, org.apache.tinkerpop.gremlin.process.computer.bulkloading.*, org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.*, org.apache.tinkerpop.gremlin.process.computer.traversal.*, org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.*, org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.optimization.*, org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.*, org.apache.tinkerpop.gremlin.util.*, org.apache.tinkerpop.gremlin.util.iterator.*, static org.apache.tinkerpop.gremlin.structure.io.IoCore.*, static org.apache.tinkerpop.gremlin.process.traversal.P.*, static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*, static org.apache.tinkerpop.gremlin.process.computer.Computer.*, static org.apache.tinkerpop.gremlin.util.TimeUtil.*, static org.apache.tinkerpop.gremlin.process.traversal.SackFunctions.Barrier.*, static org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality.*, static org.apache.tinkerpop.gremlin.structure.Column.*, static org.apache.tinkerpop.gremlin.structure.Direction.*, static org.apache.tinkerpop.gremlin.process.traversal.Operator.*, static org.apache.tinkerpop.gremlin.process.traversal.Order.*, static org.apache.tinkerpop.gremlin.process.traversal.Pop.*, static org.apache.tinkerpop.gremlin.process.traversal.Scope.*, static org.apache.tinkerpop.gremlin.structure.T.*, static org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent.Pick.*, org.apache.tinkerpop.gremlin.driver.*, org.apache.tinkerpop.gremlin.driver.exception.*, org.apache.tinkerpop.gremlin.driver.message.*, org.apache.tinkerpop.gremlin.driver.ser.*, org.apache.tinkerpop.gremlin.driver.remote.*, groovyx.gbench.*, groovyx.gprof.*, static groovyx.gprof.ProfileStaticExtension.*, org.apache.tinkerpop.gremlin.giraph.process.computer.*, org.apache.hadoop.conf.*, org.apache.hadoop.hdfs.*, org.apache.hadoop.fs.*, org.apache.hadoop.util.*, org.apache.hadoop.io.*, org.apache.hadoop.io.compress.*, org.apache.hadoop.mapreduce.lib.input.*, org.apache.hadoop.mapreduce.lib.output.*, org.apache.tinkerpop.gremlin.hadoop.*, org.apache.tinkerpop.gremlin.hadoop.structure.*, org.apache.tinkerpop.gremlin.hadoop.structure.util.*, org.apache.tinkerpop.gremlin.hadoop.structure.io.*, org.apache.tinkerpop.gremlin.hadoop.structure.io.graphson.*, org.apache.tinkerpop.gremlin.hadoop.structure.io.gryo.*, org.apache.tinkerpop.gremlin.hadoop.structure.io.script.*, org.apache.tinkerpop.gremlin.hadoop.process.computer.mapreduce.*, org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.*, static org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph.*, org.apache.tinkerpop.gremlin.neo4j.structure.*, static org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP.*, org.apache.tinkerpop.gremlin.spark.process.computer.*, org.apache.tinkerpop.gremlin.spark.structure.*, org.apache.tinkerpop.gremlin.spark.structure.io.*, org.apache.tinkerpop.gremlin.tinkergraph.structure.*, org.apache.tinkerpop.gremlin.tinkergraph.process.computer.*, org.apache.tinkerpop.gremlin.process.traversal.step.util.event.*
    gremlin> graph = TinkerFactory.createModern()
    ==>tinkergraph[vertices:6 edges:6]
    gremlin> l = new ConsoleMutationListener(graph)
    ==>MutationListener[tinkergraph[vertices:6 edges:6]]
    gremlin> strategy = EventStrategy.build().addListener(l).create()
    ==>EventStrategy
    gremlin> g = graph.traversal().withStrategies(strategy)
    ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
    gremlin> g.addV().property('name','stephen')
    Vertex [v[13]] added to graph [tinkergraph[vertices:7 edges:6]]
    ==>v[13]
    gremlin> g.E().drop()
    Edge [e[7][1-knows->2]] removed from graph [tinkergraph[vertices:7 edges:6]]
    Edge [e[8][1-knows->4]] removed from graph [tinkergraph[vertices:7 edges:5]]
    Edge [e[9][1-created->3]] removed from graph [tinkergraph[vertices:7 edges:4]]
    Edge [e[10][4-created->5]] removed from graph [tinkergraph[vertices:7 edges:3]]
    Edge [e[11][4-created->3]] removed from graph [tinkergraph[vertices:7 edges:2]]
    Edge [e[12][6-created->3]] removed from graph [tinkergraph[vertices:7 edges:1]]
    By default, the EventStrategy is configured with an EventQueue that raises events as they occur within execution of a Step. As such, the final line of Gremlin execution that drops all edges shows a bit of an inconsistent count, where the removed edge count is accounted for after the event is raised. The strategy can also be configured with a TransactionalEventQueue that captures the changes within a transaction and does not allow them to fire until the transaction is committed.
    

    警告EventStrategy不适用于跟踪不同进程中的全局突变 . 换句话说,一个JVM进程中的突变不会作为不同JVM进程中的事件引发 . 此外,当突变发生在遍历上下文之外时,不会引发事件 .

相关问题