【问题标题】:Stored procedures in gremlin CosmosDBgremlin CosmosDB 中的存储过程
【发布时间】:2017-11-30 10:57:59
【问题描述】:

我是 gremlincosmos DB 的新手,并试图在 cosmos DB gremlin API 中使用 Stored Procedure

我从Quick-start-nodejs doc 开始,用于创建与 CosmosDB gremlin API 连接的 node.js 应用程序。现在我想在该应用程序中使用存储过程。 我发现只有一个 doc 用于 cosmos DB 中的存储过程,而这仅适用于 Document DB(在 SQL 中)。我没有在 gremlin 中找到任何与存储过程相关的文档。

谁能指导我,怎么做?

提前致谢。

【问题讨论】:

    标签: stored-procedures azure-cosmosdb gremlin


    【解决方案1】:

    我和你有同样的问题。并且发现Gremlin或者Graph模式下的Cosmos DB不支持存储过程。您可以从 UI 创建它们,但因为您不能使用任何 Gremlin 查询或有触发器 - 它们是无用的。也没有关于它的文档。

    我发现了 2019 年 3 月的一篇帖子,其中存储过程在 Germlin 的路线图上 https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/20115355-gremlin-queries-from-stored-procedures

    就我个人而言,由于缺少存储过程,我正在考虑使用 Neo4j 而不是 Cosmos

    【讨论】:

      【解决方案2】:

      根据您对问题的第一个答案的评论:“实际上,我想在每次创建新顶点时添加一些边。例如,每当创建带有标签 EMPLOYEE 的顶点时,顶点 COMPANY 的边必须自动创建。” here,你可以看看 TinkerPop 的EventStrategy

      编辑:

      如果链接发生变化,请从上面的链接中添加重要部分:

      EventStrategy 的目的是在 Traversal 中发生对底层 Graph 的更改时,将事件引发到一个或多个 MutationListener 对象。这种策略对于记录更改、基于更改触发某些操作或任何需要在遍历期间通知某些变异操作的应用程序很有用。如果事务回滚,则重置事件队列。

      向 MutationListener 引发以下事件:

      • 新顶点
      • 新边缘
      • 顶点属性已更改
      • 边缘属性已更改
      • 顶点属性已移除
      • 边缘属性已移除
      • 顶点已移除
      • 边缘已移除

      要从 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 进程中的事件引发。此外,当突变发生在 Traversal 上下文之外时,不会引发事件。

      【讨论】:

      • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
      • 谢谢;我添加了相关的文本和代码示例。
      • 这些都不适用于 Cosmos,它不完全兼容 Tinkerpop,仅涵盖了实际 Gremlin 的一个子集,更不用说实际图形引擎提供的更高级的东西了
      【解决方案3】:

      你的用例是什么?

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

      但是,CosmosDB 是多模型的。您可以通过 gremlin 以及本机 DocumentDB API 与其交谈。

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

      【讨论】:

      • 实际上我想在每次创建新顶点时添加一些边。例如,每当创建带有标签EMPLOYEE 的顶点时,必须自动创建到顶点COMPANY 的边。
      猜你喜欢
      • 1970-01-01
      • 2019-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多