如何在 cassandra cql 中对 2 个或更多表进行连接查询 [英] How to do a join queries with 2 or more tables in cassandra cql

查看:42
本文介绍了如何在 cassandra cql 中对 2 个或更多表进行连接查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 cassandra 的新手.这里我有两个表 EVENTSTOWER.我需要加入那些查询.但我不能这样做.

I am new to cassandra. Here I have two tables EVENTS and TOWER. I need to join those for some queries. But I'm not enable to do it.

EVENTS 表的结构:

eid int PRIMARY KEY,
a_end_tow_id text,
a_home_circle text,
a_home_operator text,
a_imei text,
a_imsi text,

TOWER表的结构:

 tid int PRIMARY KEY,
 tower_address_1 text,
 tower_address_2 text,
 tower_azimuth text,
 tower_cgi text,
 tower_circle text,
 tower_id_no text,
 tower_lat_d text,
 tower_long_d text,
 tower_name text,

现在,我想根据 EIDTID 连接这些表,以便我可以获取两个表的数据.

Now, I want to join these table with respect to EID and TID so that I can fetch the data of both tables.

推荐答案

Cassandra = No Joins.您的模型是 100% 相关的.您需要为 Cassandra 重新考虑它.我建议你看看 这些幻灯片.他们深入研究了如何为 cassandra 建模数据.这里还有一个网络研讨会,涵盖了该主题.但是不要再考虑外键和连接表了,因为如果你需要关系,cassandra 不是这项工作的工具.

Cassandra = No Joins. Your model is 100% relational. You need to rethink it for Cassandra. I would advice you take a look at these slides. They dig deep into how to model data for cassandra. Also here is a webinar covering the topic. But stop thinking foreign keys and joining tables, because if you need relations cassandra isn't the tool for the job.

为什么?
因为那样你就需要检查一致性并做很多关系数据库要做的其他事情,所以你失去了 cassandra 提供的性能和可扩展性.

But Why?
Because then you need to check consistency and do many other things that relational databases do and so you loose the performance and scalability that cassandra offers.

我能做什么?
去正规化!一张表有很多数据?但是这个表会有太多的列!
所以?Cassandra 可以处理一个表中非常多的列.

What can I do?
DENORMALIZE! Lots of data in one table? But the table will have too many columns!
So? Cassandra can handle a very large number of columns in a table.

您可以做的另一件事是在您的客户端应用程序中模拟连接.匹配代码中的两个数据集,但这会非常慢,因为您必须遍历所有信息.

The other thing you can do is to simulate the join in your client application. Match the two datasets in your code, but this will be very slow because you'll have to iterate over all your information.

另一种方式是进行多次查询.选择您想要的活动,然后选择匹配的塔.

Another way is to carry out multiple queries. Select the event you want, then the matching tower.

这篇关于如何在 cassandra cql 中对 2 个或更多表进行连接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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