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

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

问题描述

我是cassandra的新人。这里我有两个表 EVENTS TOWER 。我需要加入这些为一些查询。但我不能够这样做。



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_lim_d文本,
tower_long_d文本,
tower_long_d文本,
tower_long_d文本,
tower_circle文本,
tower_circle文本,
tower_id_no文本,

现在,我想加入这些表格 EID

解决方案 c $ c> TID div>

Cassandra =没有加入。您的模型是100%关系。你需要重新思考Cassandra。我会建议你看看这些幻灯片。他们深入研究如何为cassandra建模数据。此外,这里还有一个网络研讨会,涵盖了主题。但是停止思考外键和加入表,因为如果你需要关系cassandra不是工作的工具。



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



我该怎么办?

DENORMALIZE!一个表中有大量的数据?但是表格中的列太多了! Cassandra可以处理表中非常多的列。



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



另一种方法是执行多个查询。选择所需的活动,然后选择匹配的塔。


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.

Structure of EVENTS table:

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

Structure of TOWER table:

 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,

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. 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.

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.

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