%% Import Data Using Consistency Level
% Using a Cassandra® database connection, import data from a Cassandra database table into MATLAB®. Use the value of the partition key in the database table to import data. Specify a consistency level for returning results. The Cassandra database contains a database table with employee data.
%
% Create a Cassandra database connection using the local host address. conn is a cassandra object.

contactPoints = "localhost";
conn = cassandra(contactPoints);

%
% Import employee data into MATLAB from the employeedata keyspace and the employees_by_job database table by using the Cassandra database connection. This database table has the job_id partition key. Specify the IT_PROG value of the partition key to import all data for only those employees who are programmers. Also, specify the consistency level as a quorum.

keyspace = "employeedata";
tablename = "employees_by_job";
keyValue = "IT_PROG";
level = "QUORUM";
results = partitionRead(conn,keyspace,tablename,keyValue, ...
    'ConsistencyLevel',level);

% Most of the replica nodes respond with the returned data.
%
% Display the returned employee data.

results

% results is a table that contains these variables:
% job_id — Job identifier
% hire_date — Hire date
% employee_id — Employee identifier
% commission_pct — Commission percentage
% department_id — Department identifier
% email — Email address
% first_name — First name
% last_name — Last name
% manager_id — Manager identifier
% office — Office location (table that contains two variables for the building and room)
% performance_ratings — Performance ratings
% phone_number — Phone number
% salary — Salary
%
% Close the Cassandra database connection.

close(conn)

% Copyright 2018 The MathWorks, Inc.