Skip to content

Commit

Permalink
Changes withElement definition to be closer to CQL3 specification (#4296
Browse files Browse the repository at this point in the history
)

* Changes withElement definition to be closer to CQL3 specification.

This PR adds support for two things:

1. Specifying order of more than one clustering keys, and
2. Allowing for additional table options after `WITH CLUSTERING ORDER`.

Both are allowed in CQL3, see the relevant section of the spec:
https://cassandra.apache.org/doc/stable/cassandra/cql/ddl.html#create-table-statement

This does not add support for `COMPACT STORAGE`, which is also allowed by the spec.
Adding it as part of this PR would greatly complicate the grammar and break backwards
compatibility. Someone would have to think more carefully about how to roll out such
a change.

* Added support for the COMPACT STORAGE table option.

* Renamed test table
  • Loading branch information
TonyRippy authored Nov 4, 2024
1 parent 04721ce commit e688a18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cql3/CqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,17 @@ createTable
;

withElement
: kwWith tableOptions? clusteringOrder?
: kwWith tableOptions
;

clusteringOrder
: kwClustering kwOrder kwBy syntaxBracketLr column orderDirection? syntaxBracketRr
tableOptions
: kwCompact kwStorage (kwAnd tableOptions)?
| clusteringOrder (kwAnd tableOptions)?
| tableOptionItem (kwAnd tableOptionItem)*
;

tableOptions
: tableOptionItem (kwAnd tableOptionItem)*
clusteringOrder
: kwClustering kwOrder kwBy syntaxBracketLr (column orderDirection?) (syntaxComma column orderDirection?)* syntaxBracketRr
;

tableOptionItem
Expand Down Expand Up @@ -1340,4 +1342,4 @@ syntaxComma

syntaxColon
: COLON
;
;
9 changes: 9 additions & 0 deletions cql3/examples/tableOptions.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE alphabet (
a int,
b int,
c int,
PRIMARY KEY ((a), b, c)
)
WITH COMPACT STORAGE
AND CLUSTERING ORDER BY (b ASC, c DESC)
AND default_time_to_live = 300;

0 comments on commit e688a18

Please sign in to comment.