【发布时间】:2019-10-26 07:58:39
【问题描述】:
我正在研究 Azure Cosmos DB 的 Gremlin API,并试图将一些 SQL 语句转换为 Gremlin 遍历。
以下命令:
//add product vertex
g.addV('product').property('id', 'product1')
g.addV('product').property('id', 'product2')
g.addV('product').property('id', 'product3')
g.addV('product').property('id', 'product4')
g.addV('product').property('id', 'product5')
//add product_category vertex
g.addV('product_category').property('id', 'category1')
g.addV('product_category').property('id', 'category2')
//connect product and product_categories
g.V('product1').addE('belongs_to').to(g.V('category1'))
g.V('product2').addE('belongs_to').to(g.V('category1'))
g.V('product3').addE('belongs_to').to(g.V('category2'))
g.V('product4').addE('belongs_to').to(g.V('category2'))
g.V('product5').addE('belongs_to').to(g.V('category2'))
//add image vertex
g.addV('image').property('public_url', 'url_1').property('id', 'image1')
g.addV('image').property('public_url', 'url_2').property('id', 'image2')
//link products to images
g.V('product1').addE('belongs_to').property('primary', true).to(g.V('image1'))
g.V('product2').addE('belongs_to').property('primary', true).to(g.V('image2'))
现在您可以看到,并非所有产品都有图片。
我希望能够选择所有具有类别和图像属性的产品。 如果产品没有图像,则仍应选择具有空图像属性的产品。
我正在尝试通过以下链接执行类似于左连接的操作: http://sql2gremlin.com/#_left_join
但遗憾的是 Azure Cosmos 的 Gremlin API 尚不支持 match() 步骤。
我当前的查询只选择具有图像输出边缘的产品:
g.V()
.has('label', 'product')
.as('product')
.outE('has_image')
.has('primary', true)
.inV()
.as('primary_image')
.in('has_image')
.out('belongs_to')
.as('category')
.select('product','primary_image','category')
.by(__.valueMap()).by(__.values('public_url')).by(__.values('name'))
【问题讨论】:
-
一个例子对于提高问题的质量非常有用。向我们展示您拥有的数据类型、您拥有的边和顶点以及您尝试运行的遍历的样本。
-
感谢您的指正,请看修改后的版本。
标签: azure-cosmosdb graph-databases azure-cosmosdb-gremlinapi