apacheCassandra
Syntax
Description
creates a Cassandra® database connection using a data source name, user name, and password.conn
= apacheCassandra(datasource
,username
,password
)
specifies options using one or more name-value arguments. For example,
conn
= apacheCassandra(username
,password
,Name,Value
)'PortNumber',9042
creates a Cassandra database connection using the port number 9042
.
Examples
Create Apache Cassandra Database Connection
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 Apache Cassandra Database Connection Using Additional Options
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
datasource
— Data source name
character vector | string scalar
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
username
— User name
character vector | string scalar
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
— Password
character vector | string scalar
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.
ContactPoints
— Contact points
"localhost"
(default) | character vector | string scalar | cell array of character vectors | string array
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
PortNumber
— Port number
9042
(default) | positive numeric scalar
Port number for connection to the host, specified as a positive numeric scalar.
Data Types: double
SSLEnabled
— SSL-enabled connection
false
(default) | true
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
LoginTimeout
— Login timeout
5
(default) | positive numeric scalar
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
RequestTimeout
— Request timeout
12
(default) | positive numeric scalar
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
conn
— Apache Cassandra database connection
connection
object
Apache Cassandra database connection, returned as a connection
object.
Version History
Introduced in R2021a
See Also
Objects
Functions
isopen
|tablenames
|columninfo
|partitionRead
|upsert
|executecql
|close
External Websites
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)