Main Content

apacheCassandra

Create Apache Cassandra database connection

Description

example

conn = apacheCassandra(datasource,username,password) creates a Cassandra® database connection using a data source name, user name, and password.

example

conn = apacheCassandra(username,password,Name,Value) specifies options using one or more name-value arguments. For example, 'PortNumber',9042 creates a Cassandra database connection using the port number 9042.

Examples

collapse all

Create a database connection to an Apache™ Cassandra® database using the Apache Cassandra database C++ interface. To create this connection, you must configure a Cassandra data source. For more information, see the databaseConnectionOptions function. Using a local host address, create the database connection and display the keyspaces in the database.

Create a Cassandra database connection using the configured data source CassandraDataSource and a blank user name and password.

datasource = "CassandraDataSource";
username = "";
password = "";
conn = apacheCassandra(datasource,username,password)
conn = 
  connection with properties:

            Cluster: "Test Cluster"
      HostAddresses: "127.0.0.1"
    LocalDataCenter: "datacenter1"
     RequestTimeout: 20
          Keyspaces: [6×1 string]

conn is a connection object that contains these properties:

  • Cassandra cluster name

  • Host address

  • Local data center name

  • Keyspaces

  • Request timeout

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

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

Close the Cassandra database connection.

close(conn)

Create a database connection to an Apache™ Cassandra® database with additional options using the Apache Cassandra database C++ interface. Using an additional option for request timeout, create the database connection and display the keyspaces in the database.

Create a Cassandra database connection using a blank user name and password. Specify an additional option for a request timeout of 20 seconds.

username = "";
password = "";
conn = apacheCassandra(username,password, ...
    'RequestTimeout',20)
conn = 
  connection with properties:

            Cluster: "Test Cluster"
      HostAddresses: "127.0.0.1"
    LocalDataCenter: "datacenter1"
     RequestTimeout: 20
          Keyspaces: [6×1 string]

conn is a connection object that contains these properties:

  • Cassandra cluster name

  • Host address

  • Local data center name

  • Keyspaces

  • Request timeout

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

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

Close the Cassandra database connection.

close(conn)

Input Arguments

collapse all

Data source name, specified as a character vector or string scalar. Specify the name of an existing data source.

Example: "myDataSource"

Data Types: 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 Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: conn = apacheCassandra(username,password,'SSLEnabled',true,'RequestTimeout',15) creates a Cassandra database connection with SSL encryption enabled and a request timeout of 15 seconds.

Contact points, specified as a character vector, string scalar, cell array of character vectors, or string array. Contact points are host addresses for one node or for multiple nodes in the Cassandra cluster. Specify a string scalar for one node. Or, specify a 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 apacheCassandra 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 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.

Data Types: char | string | cell

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

Data Types: double

SSL-enabled connection, specified as the value false or true. Setting this argument to true creates an SSL-enabled connection to the Cassandra database.

Data Types: logical

Login timeout, specified as a positive numeric scalar. The login timeout specifies the number of seconds that the C++ driver waits while trying to connect to the Cassandra database before throwing an error.

Data Types: double

This property is read-only.

Request timeout, specified as a positive numeric scalar. The request timeout indicates the number of seconds the database waits to return a CQL query before throwing an error.

Data Types: double

Output Arguments

collapse all

Apache Cassandra database connection, returned as a connection object.

Version History

Introduced in R2021a