Cassandra
Query Language (CQL)
The Cassandra Query Language “CQL” is
language to communicate with the Cassandra database. It interact with Cassandra
is using the CQL shell, cqlsh. Using cqlsh, you can create keyspaces and
tables, insert and query tables etc.
I am going to share the basic rules,
keywords, identifiers, constraints etc.
Identifiers
and keywords
The CQL language uses identifiers to
identify tables, columns and other objects. There is number of identifiers (like
SELECT or ASC) are keywords. They have a fixed meaning for the language and
most are reserved keyword for Cassandra database.
Identifiers and (unquoted) keywords are
case insensitive. There is two type of identifiers i.e.
- unquoted_identifier :- re('[a-zA-Z][a-zA-Z0-9_]*')
- quoted_identifier :- '"' (any character where " can appear if doubled)+ '"'
CQL
Terms
CQL has the notion of a term that denotes
the kind of values that CQL support. A term can be one of these
- Constant
- Literal
- function call
- type hint
- bind marker
Term
|
Values that CQL support
|
literal
|
collection_literal | udt_literal |
tuple_literal
|
function_call
|
identifier '(' [ term (',' term)* ]
')'
|
type_hint
|
'(' cql_type `)` term
|
bind_marker
|
'?' | ':' identifier
|
CQL Constants
Following are the kind of constants in CQL
Constants
|
Defining Value
|
string
|
\'' (any character where ' can appear
if doubled)+ '\'' '$$' (any character
other than '$$') '$$'
|
integer
|
re('-?[0-9]+')
|
float
|
re('-?[0-9]+(\.[0-9]*)?([eE][+-]?[0-9+])?')
| NAN | INFINITY
|
boolean
|
TRUE | FALSE
|
uuid
|
hex{8}-hex{4}-hex{4}-hex{4}-hex{12}
|
hex
|
re("[0-9a-fA-F]")
|
blob
|
'0' ('x' | 'X') hex+
|
Remark Point:-
- A string constant is an arbitrary sequence of characters enclosed by single-quote ('). Single-quote can be used without escaping ($$It's raining today$$).
- Integer, float and boolean constant are defined as expected. Note that the float allows NaN and Infinity constants.
- CQL supports UUID constants.
- Blobs content are provided in hexadecimal and prefixed by 0x.
- The special NULL constant denotes the absence of value.
CQL
Comments
There is two type of comment in CQL that is
below
1) Single-line
comments:-
A comment in CQL is a line beginning by either
double dashes (--) or double slash (//).
Example:-
-- This is a comment
// This is a comment too
2) Multi-line
comments:-
Multi-line comments are also supported through
enclosure within /* and */.
Example:-
/* this is a multi-line comment */
CQL
Statements
CQL statements can be divided in the
following categories:
- Data Definition statements
- Data Manipulation statements
- Secondary Indexes statements.
- Materialized Views statements.
- Database Roles and Permissions statements
- User-Defined Functions statements.
- User-Defined Types statements.
- Triggers statements.
CQL Statements categories
|
statement purpose
|
Data Definition statements
|
use_statement
create_keyspace_statement alter_keyspace_statement drop_keyspace_statement create_table_statement alter_table_statement drop_table_statement truncate_statement |
Data Manipulation statements
|
select_statement
insert_statement update_statement delete_statement batch_statement |
Secondary Indexes statements
|
create_index_statement
drop_index_statement |
Materialized Views statements
|
create_materialized_view_statement
drop_materialized_view_statement |
Database Roles and Permissions
statements
|
create_role_statement
alter_role_statement drop_role_statement grant_role_statement revoke_role_statement list_roles_statement grant_permission_statement revoke_permission_statement list_permissions_statement create_user_statement alter_user_statement drop_user_statement list_users_statement |
User-Defined Functions statements
|
create_function_statement
drop_function_statement create_aggregate_statement drop_aggregate_statement |
User-Defined Types statements
|
create_type_statement
alter_type_statement drop_type_statement |
Triggers statements
|
create_trigger_statement
drop_trigger_statement |
No comments:
Post a comment