简体   繁体   English

如何从Cassandra数据库中的两个表中检索数据

[英]How can i retrieve data from two tables in Cassandra Database

I have to retrive the data from two tables, 我必须从两个表中检索数据,

Here are my two tables in Cassandra DataBase. 这是我在Cassandra DataBase中的两个表。

employee is keyspace, 员工是关键空间,

Two tables: 两张桌子:

  1. emp:- "eno" is primay key,"username","password" emp: - “eno”是首要键,“用户名”,“密码”
  2. Dept:-"dno" is primary key ,"eno","dname" 部门: - “dno”是主键,“eno”,“dname”

Now i want to retrieve the data from two tables, eg eno,username,password,dno,dname. 现在我想从两个表中检索数据,例如eno,username,password,dno,dname。

How can i retrieve data from two tables? 如何从两个表中检索数据?

How can i retrieve data from two tables? 如何从两个表中检索数据?

You can't do it in one query if that is what you are asking. 如果这是您要求的,则无法在一个查询中执行此操作。 That means that you have to carry out two queries and let your application simulate a join, or the other option, denormalize your data so it is in one table. 这意味着您必须执行两个查询并让您的应用程序模拟连接,或者另一个选项,将数据非规范化,以便它在一个表中。

As for actually carrying out the query there are bundles of APIs that can retrieve data from Cassandra. 至于实际执行查询,有一些API可以从Cassandra检索数据。

Assuming your column families are emp and Dept you can do querying using the cli: 假设您的列族是empDept您可以使用cli进行查询:

$ ./cassandra-cli -host localhost -port 9160
$ [default@unknown] USE employee
# single row (collection of columns)
$ [default@employee] GET emp['eno']['username']['password'] as ascii;
# 10 rows for emp column family (aka table)
$ [default@employee] LIST  emp limit 10;

Check the documentation for Cassandra 0.7 for using the CLI . 使用CLI查看Cassandra 0.7的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM