从Cassandra数据库表中探索和导入数据
本示例展示了如何探索Apache™Cassandra®数据库的结构,以及如何使用Cassandra数据库连接将数据从Cassandra数据库表导入到MATLAB®。Cassandra数据库根据分区键存储数据库表。分区键影响如何在数据库中筛选数据。
在本例中,Cassandra数据库包含employees_by_job
数据库表中包含员工数据和job_id
分区键。
要运行此示例,必须首先安装Apache Cassandra数据库的数据库工具箱™接口。详细信息请参见数据库工具箱接口Apache Cassandra数据库安装.
创建Cassandra数据库连接
使用本地主机地址创建Cassandra数据库连接。康涅狄格州
是一个卡珊德拉
对象。
联络点=“localhost”;conn = cassandra(contactPoints);
探索Cassandra数据库结构
使用Cassandra数据库连接查看Cassandra数据库中的键空间。返回的字符串数组包含键空间。键空间包含一个或多个数据库表,并定义数据库如何复制表中的数据。
conn.Keyspaces
ans =1×6字符串数组"employeedata" "system" "system_auth" "system_distributed" "system_schema" "system_traces"
方法中返回Cassandra数据库表的名称employeedata
用于。t
中包含数据库表名称的字符串数组employeedata
用于。
用于=“employeedata”;T = tablenames(conn,keyspace)
t =3×1字符串数组"employees_by_job" "employees_by_id" "employees_by_name"
属性中的Cassandra数据库列的名称employees_by_job
数据库表中。
表名=“employees_by_job”;Cols = columninfo(conn,keyspace,tablename);
中显示Cassandra数据库列的前几个名称employees_by_job
数据库表中。
头(峡路)
ans =8×4表数据类型名称PartitionKey ClusteringColumn ________________ ________ ____________ ________________ " job_id”“文本”真正的“”“hire_date”“日期“false”DESC”“employee_id”“int“false”ASC”“commission_pct”“双“false”“department_id”“int“false”“电子邮件”、“文本“false”“first_name”“文本“false”“last_name文本“false””
关口
是一个包含以下变量的表:
的名字
- Cassandra数据库列名称数据类型
—Cassandra数据库列的CQL (Cassandra Query Language)数据类型PartitionKey
—分区键指示灯ClusteringColumn
—集群列指示器
的值。PartitionKey
变量指示数据库列是否为分区键。列job_id
(作业标识符)是此数据库表中的分区键。
从Cassandra数据库导入数据
从employees_by_job
数据库表导入MATLAB使用分区键值为店员,SH_CLERK
.
keyValue =“SH_CLERK”;结果= partitionRead(conn,keyspace,tablename,...keyValue);
显示返回的员工数据的前几行。
(结果)
ans =表8×13job_id hire_date employee_id commission_pct department_id邮件first_name last_name manager_id办公室performance_ratings phone_number工资建筑房间 __________ ___________ ___________ ______________ _____________ __________ __________ __________ __________ ________________ ___________________ ______________ ______ " SH_CLERK“03 - 183年2月- 2008年南50”GGEONI”“吉拉德”“Geoni西方国家“120”“121”[2]650.507.9879“2800”SH_CLERK“13 - 199年1月- 2008年南50”DGRANT”“道格拉斯”“格兰特西方国家“124”“139[3×1 int32] "650.507.9844" 2600 "SH_CLERK" 2007年12月19日191 NaN 50 "RPERKINS" "Randall" "Perkins" 122 "West" 255 [2] "650.505.4876" 2500 "SH_CLERK" 2007年6月21日182 NaN 50 "MSULLIVA" "Martha" "Sullivan" 120 "East" 112 [2×1 int32] "650.507.9878" 2500 "SH_CLERK" 2007年6月21日198 NaN 50 "DOCONNEL" "Donald" "OConnell" 124 "East" 125 [3×1 int32] "650.507.9833" 2600 "SH_CLERK" 17- 3月195 NaN 50 "VJONES" "Vance" "Jones" 123 "West" 236 [5×1 int32] "650.501.4876" 2800 "SH_CLERK" 07- 2月187 NaN 50"ACABRIO" "Anthony" "Cabrio" 121 "West" 345 [3×1 int32] "650.509.4876" 3000 "SH_CLERK" 11-Jul-2006 190 NaN 50 "TGATES" "Timothy" "Gates" 122 "East" 297 [3×1 int32] "650.505.3876" 2900
结果
是一个包含以下变量的表:
job_id
-作业标识符hire_date
-租用日期employee_id
-员工编号commission_pct
-佣金百分比department_id
-部门编号电子邮件
-电邮地址first_name
-名字last_name
-姓氏manager_id
—管理员标识符办公室
-办公地点(包含建筑和房间两个变量的表格)performance_ratings
-性能评级phone_number
-电话号码工资
- - - - - -工资
关闭Cassandra数据库连接
关上(康涅狄格州)
另请参阅
partitionRead
|卡珊德拉
|columninfo
|表名
|关闭
相关的话题
- 数据库工具箱接口Apache Cassandra数据库安装
- 使用CQL从Cassandra数据库表导入数据
- 填充Apache Cassandra数据库中缺失数据的值
- 数据库工具箱接口Apache Cassandra数据库错误消息