cassandra CQL 中的内部连接 [英] Inner Join in cassandra CQL

查看:23
本文介绍了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.

您可能会发现这篇文章很有用:您真的需要 SQL 来在 Cassandra 中完成所有工作吗? 它有点旧,但它的原则仍然适用.

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天全站免登陆