%% Execute CQL Query Using Consistency Level
% Using the Apache Cassandra® database C++ interface, create a Cassandra® database connection and 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 configured data source CassandraDataSource and a blank user name and password. The apacheCassandra function returns conn as a connection object.

datasource = "CassandraDataSource";
username = "";
password = "";
conn = apacheCassandra(datasource,username,password);

%
% 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 one node and display the results.

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

% In this case, only one replica node responds 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 2020 The MathWorks, Inc.