Skip to content

Commit 1f80ab0

Browse files
vsai12claude
andauthored
chore: Improve cassandra grammar compatibility (#16)
* chore: add cql grammar * ci: add cql parser to test workflow * feat: improve Cassandra CQL grammar compatibility for version 5.0 - Add VECTOR data type support for AI/ML workloads (VECTOR<type, dimensions>) - Add Storage-Attached Index (SAI) syntax (CREATE INDEX USING 'sai'/'StorageAttachedIndex') - Add vector search with ORDER BY ANN OF syntax for similarity searches - Add enhanced JSON support with DEFAULT UNSET clause - Add modern CQL functions (now(), currentTimestamp(), fromJson(), toJson(), etc.) - Add DURATION data type support - Fix typo: kwDescibe -> kwDescribe - Add comprehensive test examples for all new features - Rename test files for clarity (e.g., vectorTable.cql -> createTableVector.cql) These changes enable Bytebase to parse modern Cassandra 5.0 features including vector search capabilities, SAI indexes, and enhanced JSON operations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent ee121fb commit 1f80ab0

15 files changed

+6037
-4059
lines changed

cql/CqlLexer.g4

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,25 @@ K_TIMEUUID : 'TIMEUUID';
174174
K_TIME : 'TIME';
175175
K_TINYINT : 'TINYINT';
176176
K_TUPLE : 'TUPLE';
177+
K_VECTOR : 'VECTOR';
178+
K_DURATION : 'DURATION';
179+
K_DEFAULT : 'DEFAULT';
180+
K_UNSET : 'UNSET';
181+
K_SAI : 'SAI';
182+
K_STORAGEATTACHEDINDEX : 'STORAGEATTACHEDINDEX';
183+
K_ANN : 'ANN';
177184
K_VARCHAR : 'VARCHAR';
178185
K_VARINT : 'VARINT';
186+
K_NOW : 'NOW';
187+
K_FROMJSON : 'FROMJSON';
188+
K_TOJSON : 'TOJSON';
189+
K_MINTIMEUUID : 'MINTIMEUUID';
190+
K_MAXTIMEUUID : 'MAXTIMEUUID';
191+
K_DATETIMENOW : 'DATETIMENOW';
192+
K_CURRENTTIMESTAMP : 'CURRENTTIMESTAMP';
193+
K_CURRENTDATE : 'CURRENTDATE';
194+
K_CURRENTTIME : 'CURRENTTIME';
195+
K_CURRENTTIMEUUID : 'CURRENTTIMEUUID';
179196

180197
// Literals
181198

cql/CqlParser.g4

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ priviledge
110110
: (kwAll | kwAllPermissions)
111111
| kwAlter
112112
| kwAuthorize
113-
| kwDescibe
113+
| kwDescribe
114114
| kwExecute
115115
| kwCreate
116116
| kwDrop
@@ -528,7 +528,17 @@ truncate
528528
;
529529

530530
createIndex
531-
: kwCreate kwIndex ifNotExist? indexName? kwOn (keyspace DOT)? table syntaxBracketLr indexColumnSpec syntaxBracketRr
531+
: kwCreate kwCustom? kwIndex ifNotExist? indexName? kwOn (keyspace DOT)? table syntaxBracketLr indexColumnSpec syntaxBracketRr (kwUsing indexClass)? (kwWith indexOptions)?
532+
;
533+
534+
indexClass
535+
: stringLiteral
536+
| K_SAI
537+
| K_STORAGEATTACHEDINDEX
538+
;
539+
540+
indexOptions
541+
: optionHash // Use optionHash for index options
532542
;
533543

534544
indexName
@@ -538,19 +548,9 @@ indexName
538548

539549
indexColumnSpec
540550
: column
541-
| indexKeysSpec
542-
| indexEntriesSSpec
543551
| indexFullSpec
544552
;
545553

546-
indexKeysSpec
547-
: kwKeys syntaxBracketLr OBJECT_NAME syntaxBracketRr
548-
;
549-
550-
indexEntriesSSpec
551-
: kwEntries syntaxBracketLr OBJECT_NAME syntaxBracketRr
552-
;
553-
554554
indexFullSpec
555555
: kwFull syntaxBracketLr OBJECT_NAME syntaxBracketRr
556556
;
@@ -655,7 +655,11 @@ ifExist
655655

656656
insertValuesSpec
657657
: kwValues '(' expressionList ')'
658-
| kwJson constant
658+
| kwJson constant jsonDefaultUnset?
659+
;
660+
661+
jsonDefaultUnset
662+
: kwDefault kwUnset
659663
;
660664

661665
insertColumnSpec
@@ -706,6 +710,15 @@ orderSpec
706710

707711
orderSpecElement
708712
: OBJECT_NAME (kwAsc | kwDesc)?
713+
| OBJECT_NAME kwAnn kwOf vectorLiteral (kwLimit DECIMAL_LITERAL)?
714+
;
715+
716+
vectorLiteral
717+
: '[' constantList ']'
718+
;
719+
720+
constantList
721+
: constant (syntaxComma constant)*
709722
;
710723

711724
whereSpec
@@ -768,6 +781,16 @@ functionCall
768781
: OBJECT_NAME '(' STAR ')'
769782
| OBJECT_NAME '(' functionArgs? ')'
770783
| K_UUID '(' ')'
784+
| K_NOW '(' ')'
785+
| K_FROMJSON '(' functionArgs ')'
786+
| K_TOJSON '(' functionArgs ')'
787+
| K_MINTIMEUUID '(' functionArgs ')'
788+
| K_MAXTIMEUUID '(' functionArgs ')'
789+
| K_DATETIMENOW '(' ')'
790+
| K_CURRENTTIMESTAMP '(' ')'
791+
| K_CURRENTDATE '(' ')'
792+
| K_CURRENTTIME '(' ')'
793+
| K_CURRENTTIMEUUID '(' ')'
771794
;
772795

773796
functionArgs
@@ -854,10 +877,13 @@ dataTypeName
854877
| K_VARINT
855878
| K_TIMESTAMP
856879
| K_UUID
880+
| K_VECTOR
881+
| K_DURATION
857882
;
858883

859884
dataTypeDefinition
860885
: syntaxBracketLa dataTypeName (syntaxComma dataTypeName)* syntaxBracketRa
886+
| syntaxBracketLa dataTypeName syntaxComma DECIMAL_LITERAL syntaxBracketRa // For VECTOR<type, dimension>
861887
;
862888

863889
orderDirection
@@ -994,6 +1020,22 @@ kwCreate
9941020
: K_CREATE
9951021
;
9961022

1023+
kwCustom
1024+
: K_CUSTOM
1025+
;
1026+
1027+
kwDefault
1028+
: K_DEFAULT
1029+
;
1030+
1031+
kwUnset
1032+
: K_UNSET
1033+
;
1034+
1035+
kwAnn
1036+
: K_ANN
1037+
;
1038+
9971039
kwDelete
9981040
: K_DELETE
9991041
;
@@ -1002,7 +1044,7 @@ kwDesc
10021044
: K_DESC
10031045
;
10041046

1005-
kwDescibe
1047+
kwDescribe
10061048
: K_DESCRIBE
10071049
;
10081050

cql/cql_lexer.go

Lines changed: 984 additions & 862 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cql/cql_parser.go

Lines changed: 4705 additions & 3138 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cql/cqlparser_base_listener.go

Lines changed: 58 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cql/cqlparser_base_visitor.go

Lines changed: 33 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)