%% Execute CQL Query Using Consistency Level
% Using a Cassandra® database connection, execute a CQL query to import data from a Cassandra database table into MATLAB®. Specify a consistency level for returning query results. In this case, the Cassandra database contains the employees_by_job database table with employee data in the employeedata keyspace.
%
% Create a Cassandra database connection using the local host address. conn is a cassandra object.

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

%
% Write a CQL query that selects all employees who are programmers, and retrieves their hire dates and email addresses. job_id is the partition key of the employees_by_job database table. Limit the returned data to three rows.

query = strcat("SELECT hire_date,email ", ... 
    "FROM employeedata.employees_by_job ", ...
    "WHERE job_id = 'IT_PROG'", ...
    "LIMIT 3;");

%
% Execute the CQL query with the consistency level set to a quorum and display the results.

level = "QUORUM";
results = executecql(conn,query,'ConsistencyLevel',level)

% Most of the replica nodes respond with returned data. results is a table with the hire_date and email variables. The hire_date variable is a datetime array and the email variable is a string array.
%
% Close the Cassandra database connection.

close(conn)

% Copyright 2018 The MathWorks, Inc.