This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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®. 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

Syntax

c = cassandra(contactPoints)
c = cassandra(contactPoints,username,password)
c = cassandra(___,'PortNumber',portnumber)

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(___,'PortNumber',portnumber) specifies a port number for connection to the host using the input argument combinations in any of the 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

Port number for connection to the host, specified as a numeric scalar.

Data Types: double

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
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.

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)

Introduced in R2018b