cassandra

Apache Cassandra database connection

Description

The cassandra function creates a cassandra object, which represents an Apache Cassandra® database connection using the Database Toolbox™ Interface for Apache Cassandra® Database.

First, you must install the Database Toolbox Interface for Apache Cassandra Database. For details, see Database Toolbox Interface for Apache Cassandra Database Installation.

After you create a cassandra object, you can use the object functions to import data from the Cassandra database into MATLAB®. Or, you can export data from MATLAB to the Cassandra database. You can also explore the database structure and execute Cassandra Query Language (CQL) queries.

For details about the Cassandra database, see the Apache Cassandra Documentation.

Creation

Description

example

c = cassandra(contactPoints) creates a Cassandra database connection using a host address.

example

c = cassandra(contactPoints,username,password) specifies a user name and password.

example

c = cassandra(___,Name,Value) specifies additional options using one or more name-value pair arguments in addition to any of the input argument combinations in previous syntaxes.

Input Arguments

expand all

Host address for one node or host addresses for multiple nodes in the Cassandra cluster, specified as a character vector, string scalar, cell array of character vectors, or string array. Specify a character vector or string scalar for one node. Or, specify a cell array of character vectors or string array for multiple nodes.

You can specify a local host or the IP address of a different machine in the Cassandra cluster.

When you specify multiple nodes, if the connection to one host fails, then the cassandra function connects to the other nodes in the cell array or string array until a connection succeeds. If a connection attempt fails for all specified nodes, the cassandra function displays an error message. If one or more nodes are not available, enter multiple nodes in the cell array or string array to increase the likelihood of a successful connection.

Example: 'localhost'

Data Types: cell | char | string

User name, specified as a character vector or string scalar. If the cluster requires authentication, use the username input argument for the user name.

Data Types: char | string

Password, specified as a character vector or string scalar. If the cluster requires authentication, use the password input argument for the password.

Data Types: char | string

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: c = cassandra(contactPoints,'PortNumber',3106,'SSLEnabled',true) creates an SSL-enabled connection to the Cassandra database using the port number 3106.

Port number for connection to the host, specified as the comma-separated pair consisting of 'PortNumber' and a numeric scalar.

Data Types: double

SSL-enabled connection, specified as the comma-separated pair consisting of 'SSLEnabled' and the value false or true. Setting this argument to true creates an SSL-enabled connection to the Cassandra database.

Data Types: logical

Properties

expand all

Cassandra cluster name, specified as a string scalar.

Example: "Test Cluster"

Data Types: string

Host address for one node or host addresses for multiple nodes in the Cassandra cluster, specified as a string scalar for one node or string array for multiple nodes. These addresses include the addresses specified in the contactPoints input argument.

Example: "localhost/127.0.0.1"

Data Types: string

Local data center name, specified as a string scalar. The name describes the data center that the cluster declares as local for the connection instance. The name matches the data center of the original contact point for the connection. When you set up the cluster, you define a data center for each node.

Example: "datacenter1"

Data Types: string

Keyspaces in the Cassandra database, specified as a string scalar or string array. A string scalar indicates the Cassandra database has one keyspace, and a string array indicates multiple keyspaces.

Example: ["employeedata" "system"]

Data Types: string

Object Functions

expand all

closeClose Apache Cassandra database connection
isopenDetermine if Apache Cassandra database connection is open
columninfoRetrieve column information from Apache Cassandra database table
partitionReadImport data from partitions of Apache Cassandra database table
tablenamesList names of database tables in Apache Cassandra database
upsertInsert or update data in Apache Cassandra database
executecqlExecute CQL query on Apache Cassandra database

Examples

collapse all

Using a local host address, create a Cassandra® database connection and display the keyspaces in the database.

Create a Cassandra database connection using the local host address.

contactPoints = "localhost";
conn = cassandra(contactPoints)
conn = 
  cassandra with properties:

                   Cluster: "Test Cluster"
             HostAddresses: "localhost/127.0.0.1"
           LocalDataCenter: "datacenter1"
                 Keyspaces: ["employeedata", "system", "system_auth" ... and 3 more]


conn is a cassandra object that contains these properties:

  • Cluster name

  • Host address

  • Local data center name

  • Keyspaces

Display the keyspaces in the Cassandra database by accessing the Keyspaces property of the cassandra object.

conn.Keyspaces
ans = 1×6 string array
    "employeedata"    "system"    "system_auth"    "system_distributed"    "system_schema"    "system_traces"

Close the Cassandra database connection.

close(conn)

Using a local host address and authentication, create a Cassandra® database connection and display the keyspaces in the database.

Create a Cassandra database connection using the local host address, user name, and password.

contactPoints = "localhost";
username = "username";
password = "password";
conn = cassandra(contactPoints,username,password)
conn = 
  cassandra with properties:

                   Cluster: "Test Cluster"
             HostAddresses: "localhost/127.0.0.1"
           LocalDataCenter: "datacenter1"
                 Keyspaces: ["employeedata", "system", "system_auth" ... and 3 more]


conn is a cassandra object that contains these properties:

  • Cluster name

  • Host address

  • Local data center name

  • Keyspaces

Display the keyspaces in the Cassandra database by accessing the Keyspaces property of the cassandra object.

conn.Keyspaces
ans = 1×6 string array
    "employeedata"    "system"    "system_auth"    "system_distributed"    "system_schema"    "system_traces"

Close the Cassandra database connection.

close(conn)

Using a local host address and port number, create a Cassandra® database connection and display the keyspaces in the database.

Create a Cassandra database connection using the local host address. Specify the port number 9042 by using the 'PortNumber' name-value pair argument.

contactPoints = "localhost";
portnumber = 9042;
conn = cassandra(contactPoints,'PortNumber',portnumber)
conn = 
  cassandra with properties:

                   Cluster: "Test Cluster"
             HostAddresses: "localhost/127.0.0.1"
           LocalDataCenter: "datacenter1"
                 Keyspaces: ["employeedata", "system", "system_auth" ... and 3 more]


conn is a cassandra object that contains these properties:

  • Cluster name

  • Host address

  • Local data center name

  • Keyspaces

Display the keyspaces in the Cassandra database by accessing the Keyspaces property of the cassandra object.

conn.Keyspaces
ans = 1×6 string array
    "employeedata"    "system"    "system_auth"    "system_distributed"    "system_schema"    "system_traces"

Close the Cassandra database connection.

close(conn)

Using a local host address and port number, create an SSL-enabled connection to a Cassandra database and display the keyspaces in the database.

Create a Cassandra database connection using the local host address. Specify the port number 9042 by using the 'PortNumber' name-value pair argument. Create an SSL-enabled connection by setting the 'SSLEnabled' name-value pair argument to true.

contactPoints = "localhost";
portnumber = 9042;
conn = cassandra(contactPoints,'PortNumber',portnumber, ...
    'SSLEnabled',true)
conn = 
  cassandra with properties:

                   Cluster: "Test Cluster"
             HostAddresses: "localhost/127.0.0.1"
           LocalDataCenter: "datacenter1"
                 Keyspaces: ["employeedata", "system", "system_auth" ... and 3 more]


conn is a cassandra object that contains these properties:

  • Cluster name

  • Host address

  • Local data center name

  • Keyspaces

Display the keyspaces in the Cassandra database by accessing the Keyspaces property of the cassandra object.

conn.Keyspaces
ans = 1×6 string array
    "employeedata"    "system"    "system_auth"    "system_distributed"    "system_schema"    "system_traces"

Close the Cassandra database connection.

close(conn)
Introduced in R2018b