Main Content

columninfo

Retrieve column information from Apache Cassandra database table

Since R2021a

Description

cols = columninfo(conn,keyspace,tablename) returns column information from a specified Cassandra® database table in a specified keyspace using the Cassandra database connection.

example

[cols,keyValues] = columninfo(conn,keyspace,tablename) also returns the key values for each partition in the Cassandra database table.

example

Examples

collapse all

Using an Apache™ Cassandra® database connection and the Apache Cassandra database C++ interface, return column information for a Cassandra database table. Specify the keyspace and the name of the table. In this case, the Cassandra database has the employeedata keyspace, which contains the employees_by_job database table.

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);

Return column information for the employees_by_job database table in the employeedata keyspace.

keyspace = "employeedata";
tablename = "employees_by_job";
cols = columninfo(conn,keyspace,tablename);

Display the first few rows of column information.

head(cols)
ans=8×4 table
          Name          DataType    PartitionKey    ClusteringColumn
    ________________    ________    ____________    ________________

    "job_id"            "text"         true              ""         
    "hire_date"         "date"         false             "DESC"     
    "employee_id"       "int"          false             "ASC"      
    "commission_pct"    "double"       false             ""         
    "department_id"     "int"          false             ""         
    "email"             "text"         false             ""         
    "first_name"        "text"         false             ""         
    "last_name"         "text"         false             ""         

cols is a table with these variables:

  • Name — Cassandra database column name

  • DataType — Cassandra Query Language (CQL) data type of the Cassandra database column

  • PartitionKey — Partition key indicator

  • ClusteringColumn — Clustering column indicator

Close the Cassandra database connection.

close(conn)

Using an Apache™ Cassandra® database connection and the Apache Cassandra database C++ interface, return partition key values for a Cassandra database table. Specify the keyspace and name of the table. In this case, the Cassandra database has the employeedata keyspace, which contains the employees_by_job database table.

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);

Return column information for the employees_by_job database table in the employeedata keyspace.

keyspace = "employeedata";
tablename = "employees_by_job";
[cols,keyValues] = columninfo(conn,keyspace,tablename);

keyValues is a table that contains a variable for each partition key. The rows are partition key values.

Display the first few partition key values of the Cassandra database table.

head(keyValues)
ans=8×1 table
      job_id  
    __________

    "ST_CLERK"
    "SA_MAN"  
    "HR_REP"  
    "IT_PROG" 
    "FI_MGR"  
    "PR_REP"  
    "PU_MAN"  
    "AD_PRES" 

job_id is the only partition key in the employees_by_job database table. Each row is a partition key value that is a unique partition in employees_by_job.

Use the partition key values with the partitionRead function to import data from a Cassandra database table.

Close the Cassandra database connection.

close(conn)

Input Arguments

collapse all

Apache Cassandra database connection, specified as a connection object.

Keyspace, specified as a character vector or string scalar. If you do not know the keyspace, then access the Keyspaces property of the connection object using dot notation to view the keyspaces in the Cassandra database.

Example: "employeedata"

Data Types: char | string

Cassandra database table name, specified as a character vector or string scalar. If you do not know the name of the table, then use the tablenames function to find it.

Example: "employees_by_job"

Data Types: char | string

Output Arguments

collapse all

Column information from a Cassandra database table, returned as a MATLAB® table containing these variables.

Variable NameVariable DescriptionVariable Data Type

Name

Cassandra database column name

string

DataType

CQL data type of the Cassandra database column

string

PartitionKey

Whether the Cassandra database table column is a partition key (true indicates a partition key)

logical

ClusteringColumn

Whether the Cassandra database table column is a clustering column ("ASC" indicates ascending order, "DESC" indicates descending order, and "" indicates that the column is not a clustering column)

string

If the data type of a column in a Cassandra database table is a collection (for example, a list, map, and so on), then the value of the DataType variable contains angle brackets (<>). These angle brackets surround the data type of the items in the collection. The value for user-defined types (UDTs) contains the type name. For example, if the UDT is person, then the value of the DataType variable is person in the MATLAB table. For details about valid CQL data types, see CQL Data Types.

Partition key values, returned as a table. The MATLAB table contains one variable for each partition key in the Cassandra database table. Each row in the MATLAB table represents a unique partition in the Cassandra database table.

You can use the partition key values with the partitionRead function to import data from a Cassandra database table.

For details about the MATLAB data types of the partition key values, see Convert CQL Data Types to MATLAB Data Types Using Apache Cassandra Database C++ Interface.

Version History

Introduced in R2021a