内部加入cassandra CQL [英] Inner Join in cassandra CQL

查看:159
本文介绍了内部加入cassandra CQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在cassandra中写入子查询/嵌套查询。这个工具是否在CQL中提供?

How do I write subqueries/nested queries in cassandra. Is this facility is provided in CQL?

示例:我尝试了:

cqlsh:testdb> select itemname from item where itemid = (select itemid from orders where customerid=1);

它只会引发以下错误 -

It just throws the following error -

Bad Request: line 1:87 no viable alternative at input ';'


推荐答案

由于其分布式特性,Cassandra不支持RDBMS样式连接。你有几个选项,当你想要像加入。

Because of its distributed nature, Cassandra has no support for RDBMS style joins. You have a few options for when you want something like a join.

一个选项执行单独的查询,然后让应用程序加入数据本身。这是有道理的,如果数据相对较小,你只需要执行少量的查询。根据你给出的例子,这可能是一个很好的解决方案。

One option perform separate queries and then have your application join the data itself. This makes sense if the data is relatively small and you only have to perform a small number of queries. Based on the example you gave above, this would probably be a good solution for you.

对于更复杂的连接,通常的策略是对数据进行反规范化,并存储连接的实体化视图 。这样做的优点是,获取这些数据将比在每次需要时在应用程序中构建它更快。成本现在是你有多个地方,你存储相同的数据,你需要保持它的所有同步。当新数据进入系统时,您可以更新所有视图,或者可以有一个定期的批处理作业来重建系统。

For more complicated joins, the usual strategy is to denormalize the data and store a materialized view of the join. The advantage to this is that fetching this data will be much faster than having to build it join in your application every time you need it. The cost is now you have multiple places where you are storing the same data and you will need to keep it all in sync. You can either update all your views when new data comes into the system or you can have a periodic batch job that rebuilds thems.

您可能会发现这篇文章很实用:

You might find this article useful: Do You Really Need SQL to Do It All in Cassandra? Its a bit old but its principles still apply.

这篇关于内部加入cassandra CQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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