Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: add cassandra data masking (#17250)

Vincent Huange3fdbecbd5b6
diff --git a/backend/common/engine.go b/backend/common/engine.go
index c3d81481a7..abe1775795 100644
--- a/backend/common/engine.go
+++ b/backend/common/engine.go
@@ -98,11 +98,11 @@ func EngineSupportMasking(e storepb.Engine) bool {
storepb.Engine_BIGQUERY,
storepb.Engine_SPANNER,
storepb.Engine_REDSHIFT,
+ storepb.Engine_CASSANDRA,
storepb.Engine_TRINO:
return true
case
storepb.Engine_ENGINE_UNSPECIFIED,
- storepb.Engine_CASSANDRA,
storepb.Engine_SQLITE,
storepb.Engine_MONGODB,
storepb.Engine_REDIS,
diff --git a/backend/plugin/db/cassandra/sync.go b/backend/plugin/db/cassandra/sync.go
index 6574deb937..f9b6e7a607 100644
--- a/backend/plugin/db/cassandra/sync.go
+++ b/backend/plugin/db/cassandra/sync.go
@@ -68,13 +68,19 @@ type primaryKey struct {
position int
}
+type columnOrderInfo struct {
+ column *storepb.ColumnMetadata
+ kind string // "partition_key", "clustering", or "regular"
+ position int // Position within partition/clustering keys
+}
+
func (d *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchemaMetadata, error) {
schemaMetadata := &storepb.SchemaMetadata{
Name: "",
}
tablePKMap := map[string][]primaryKey{}
- columnMap := map[string][]*storepb.ColumnMetadata{}
+ columnOrderMap := map[string][]columnOrderInfo{}
columnScanner := d.session.Query(`
SELECT
table_name,
@@ -85,7 +91,6 @@ func (d *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchemaMetad
type
FROM system_schema.columns
WHERE keyspace_name = ?
- ORDER BY table_name, column_name
`, d.config.ConnectionContext.DatabaseName).WithContext(ctx).Iter().Scanner()
for columnScanner.Next() {
var tableName, columnName, kind, clusteringOrder, columnType string
@@ -100,10 +105,14 @@ func (d *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchemaMetad
); err != nil {
return nil, errors.Wrapf(err, "failed to scan column")
}
- columnMap[tableName] = append(columnMap[tableName], &storepb.ColumnMetadata{
- Name: columnName,
- Type: columnType,
- Nullable: true,
+ columnOrderMap[tableName] = append(columnOrderMap[tableName], columnOrderInfo{
+ column: &storepb.ColumnMetadata{
+ Name: columnName,
+ Type: columnType,
+ Nullable: true,
+ },
+ kind: kind,
+ position: position,
})
if kind != "regular" {
tablePKMap[tableName] = append(tablePKMap[tableName], primaryKey{
@@ -118,6 +127,52 @@ func (d *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchemaMetad
return nil, errors.Wrapf(err, "column scanner err")
}
+ // Sort columns to match Cassandra's SELECT * order:
+ // 1. Partition keys (by position)
+ // 2. Clustering keys (by position)
+ // 3. Regular columns (alphabetically)
+ // This ensures masking is applied to the correct columns.
+ for tableName, columns := range columnOrderMap {
+ slices.SortFunc(columns, func(a, b columnOrderInfo) int {
+ // Primary key columns come before regular columns
+ aPrimary := (a.kind == "partition_key" || a.kind == "clustering")
+ bPrimary := (b.kind == "partition_key" || b.kind == "clustering")
+
+ if aPrimary && !bPrimary {
+ return -1
+ }
+ if !aPrimary && bPrimary {
+ return 1
+ }
+
+ // Within primary key columns, sort by type then position
+ if aPrimary && bPrimary {
+ // Partition keys before clustering keys
+ if a.kind == "partition_key" && b.kind == "clustering" {
+ return -1
+ }
+ if a.kind == "clustering" && b.kind == "partition_key" {
+ return 1
+ }
+ // Within same type, sort by position
+ if a.position < b.position {
+ return -1
+ }
+ if a.position > b.position {
+ return 1
+ }
+ }
+
+ // Regular columns are sorted alphabetically
+ if !aPrimary && !bPrimary {
+ return strings.Compare(a.column.Name, b.column.Name)
+ }
+
+ return 0
+ })
+ columnOrderMap[tableName] = columns
+ }
+
indexMap := map[string][]*storepb.IndexMetadata{}
indexScanner := d.session.Query(`
SELECT
@@ -189,10 +244,16 @@ func (d *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchemaMetad
Definition: getPKDefinition(pks),
}
+ // Extract the sorted column metadata
+ var sortedColumns []*storepb.ColumnMetadata
+ for _, colInfo := range columnOrderMap[tableName] {
+ sortedColumns = append(sortedColumns, colInfo.column)
+ }
+
table := &storepb.TableMetadata{
Name: tableName,
Comment: comment,
- Columns: columnMap[tableName],
+ Columns: sortedColumns,
}
table.Indexes = append(table.Indexes, pk)
table.Indexes = append(table.Indexes, indexMap[tableName]...)
diff --git a/backend/plugin/parser/cassandra/query_span.go b/backend/plugin/parser/cassandra/query_span.go
new file mode 100644
index 0000000000..224a5cbca3
--- /dev/null
+++ b/backend/plugin/parser/cassandra/query_span.go
@@ -0,0 +1,54 @@
+package cassandra
+
+import (
+ "context"
+
+ "github.com/antlr4-go/antlr/v4"
+ "github.com/bytebase/parser/cql"
+
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
+ "github.com/bytebase/bytebase/backend/plugin/parser/base"
+)
+
+func init() {
+ base.RegisterGetQuerySpan(storepb.Engine_CASSANDRA, GetQuerySpan)
+}
+
+// GetQuerySpan extracts the query span from a CQL statement.
+func GetQuerySpan(_ context.Context, gCtx base.GetQuerySpanContext, statement, database, _ string, _ bool) (*base.QuerySpan, error) {
+ lexer := cql.NewCqlLexer(antlr.NewInputStream(statement))
+ stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
+ p := cql.NewCqlParser(stream)
+
+ lexerErrorListener := &base.ParseErrorListener{
+ Statement: statement,
+ }
+ lexer.RemoveErrorListeners()
+ lexer.AddErrorListener(lexerErrorListener)
+
+ parserErrorListener := &base.ParseErrorListener{
+ Statement: statement,
+ }
+ p.RemoveErrorListeners()
+ p.AddErrorListener(parserErrorListener)
+
+ p.BuildParseTrees = true
+ tree := p.Root()
+
+ if lexerErrorListener.Err != nil {
+ return nil, lexerErrorListener.Err
+ }
+ if parserErrorListener.Err != nil {
+ return nil, parserErrorListener.Err
+ }
+
+ // Create extractor and walk the tree
+ extractor := newQuerySpanExtractor(database, gCtx)
+ antlr.ParseTreeWalkerDefault.Walk(extractor, tree)
+
+ if extractor.err != nil {
+ return nil, extractor.err
+ }
+
+ return extractor.querySpan, nil
+}
diff --git a/backend/plugin/parser/cassandra/query_span_extractor.go b/backend/plugin/parser/cassandra/query_span_extractor.go
new file mode 100644
index 0000000000..b50ed2264f
--- /dev/null
+++ b/backend/plugin/parser/cassandra/query_span_extractor.go
@@ -0,0 +1,231 @@
+package cassandra
+
+import (
+ "context"
+ "strings"
+
+ "github.com/antlr4-go/antlr/v4"
+ "github.com/bytebase/parser/cql"
+
+ "github.com/bytebase/bytebase/backend/plugin/parser/base"
+)
+
+// querySpanExtractor walks the CQL parse tree to extract query span information
+type querySpanExtractor struct {
+ *cql.BaseCqlParserListener
+
+ // Context
+ defaultKeyspace string
+ gCtx base.GetQuerySpanContext
+
+ // Results we're building
+ querySpan *base.QuerySpan
+
+ // Error handling
+ err error
+}
+
+// unquoteIdentifier removes double quotes from Cassandra identifiers if present.
+func unquoteIdentifier(identifier string) string {
+ if len(identifier) >= 2 && identifier[0] == '"' && identifier[len(identifier)-1] == '"' {
+ return identifier[1 : len(identifier)-1]
+ }
+ return identifier
+}
+
+func newQuerySpanExtractor(defaultKeyspace string, gCtx base.GetQuerySpanContext) *querySpanExtractor {
+ return &querySpanExtractor{
+ BaseCqlParserListener: &cql.BaseCqlParserListener{},
+ defaultKeyspace: defaultKeyspace,
+ gCtx: gCtx,
+ querySpan: &base.QuerySpan{
+ Results: []base.QuerySpanResult{},
+ SourceColumns: base.SourceColumnSet{},
+ PredicateColumns: base.SourceColumnSet{},
+ },
+ }
+}
+
+// EnterSelect_ is called when we enter a SELECT statement
+func (e *querySpanExtractor) EnterSelect_(ctx *cql.Select_Context) {
+ if e.err != nil {
+ return
+ }
+
+ keyspace, table := e.extractTableFromFromSpec(ctx.FromSpec())
+ if keyspace == "" {
+ keyspace = e.defaultKeyspace
+ }
+
+ results := e.extractSelectElements(ctx.SelectElements(), keyspace, table)
+ e.querySpan.Results = results
+
+ if whereSpec := ctx.WhereSpec(); whereSpec != nil {
+ e.extractWhereColumns(whereSpec, keyspace, table)
+ }
+}
+
+// extractTableFromFromSpec extracts keyspace and table name from FROM clause
+func (*querySpanExtractor) extractTableFromFromSpec(fromSpec cql.IFromSpecContext) (keyspace, table string) {
+ if fromSpec == nil {
+ return "", ""
+ }
+
+ if fromElem := fromSpec.FromSpecElement(); fromElem != nil {
+ text := fromElem.GetText()
+ // CQL supports keyspace.table in FROM clause
+ if idx := strings.LastIndex(text, "."); idx > 0 {
+ keyspacePart := text[:idx]
+ tablePart := text[idx+1:]
+ return unquoteIdentifier(keyspacePart), unquoteIdentifier(tablePart)
+ }
+ return "", unquoteIdentifier(text)
+ }
+ return "", ""
+}
+
+// extractSelectElements extracts column information from SELECT clause
+func (e *querySpanExtractor) extractSelectElements(selectElements cql.ISelectElementsContext, keyspace, table string) []base.QuerySpanResult {
+ if selectElements == nil {
+ return nil
+ }
+
+ if selectElements.GetStar() != nil {
+ return e.expandSelectAsterisk(keyspace, table)
+ }
+
+ var results []base.QuerySpanResult
+ for _, elem := range selectElements.AllSelectElement() {
+ aliasName, sourceName := e.extractColumnNameAndAlias(elem)
+ if aliasName != "" || sourceName != "" {
+ resultName := aliasName
+ if resultName == "" {
+ resultName = sourceName
+ }
+
+ sourceColumn := base.SourceColumnSet{}
+ sourceColumn[base.ColumnResource{
+ Database: keyspace,
+ Table: table,
+ Column: sourceName,
+ }] = true
+
+ results = append(results, base.QuerySpanResult{
+ Name: resultName,
+ SourceColumns: sourceColumn,
+ IsPlainField: true,
+ })
+ }
+ }
+ return results
+}
+
+// extractColumnNameAndAlias extracts both the alias (if present) and the source column name
+func (*querySpanExtractor) extractColumnNameAndAlias(elem cql.ISelectElementContext) (alias string, sourceColumn string) {
+ if elem == nil {
+ return "", ""
+ }
+
+ // Extract the source column name from the first child
+ if elem.GetChildCount() > 0 {
+ columnRef := elem.GetChild(0).(antlr.ParseTree).GetText()
+ sourceColumn = unquoteIdentifier(columnRef)
+ }
+
+ // Check for AS alias
+ for i := 0; i < elem.GetChildCount(); i++ {
+ if child := elem.GetChild(i); child != nil {
+ childText := child.(antlr.ParseTree).GetText()
+ if strings.ToUpper(childText) == "AS" && i+1 < elem.GetChildCount() {
+ aliasText := elem.GetChild(i + 1).(antlr.ParseTree).GetText()
+ alias = unquoteIdentifier(aliasText)
+ break
+ }
+ }
+ }
+
+ return alias, sourceColumn
+}
+
+// expandSelectAsterisk expands SELECT * into individual column results
+func (e *querySpanExtractor) expandSelectAsterisk(keyspace, table string) []base.QuerySpanResult {
+ if e.gCtx.GetDatabaseMetadataFunc == nil {
+ // Test environment - fallback to SelectAsterisk flag
+ return []base.QuerySpanResult{{
+ Name: "",
+ SourceColumns: base.SourceColumnSet{},
+ SelectAsterisk: true,
+ }}
+ }
+
+ if table == "" {
+ // Cannot expand SELECT * without a table name
+ return []base.QuerySpanResult{{
+ Name: "",
+ SourceColumns: base.SourceColumnSet{},
+ SelectAsterisk: true,
+ }}
+ }
+
+ ctx := context.Background()
+ _, metadata, err := e.gCtx.GetDatabaseMetadataFunc(ctx, e.gCtx.InstanceID, keyspace)
+ if err != nil || metadata == nil {
+ // If we can't get metadata, fall back to SelectAsterisk flag
+ // This matches behavior of other engines like TSQL
+ return []base.QuerySpanResult{{
+ Name: "",
+ SourceColumns: base.SourceColumnSet{},
+ SelectAsterisk: true,
+ }}
+ }
+
+ // Find table and expand columns
+ var results []base.QuerySpanResult
+ schemaNames := metadata.ListSchemaNames()
+ for _, schemaName := range schemaNames {
+ schema := metadata.GetSchema(schemaName)
+ if schema == nil {
+ continue
+ }
+
+ tbl := schema.GetTable(table)
+ if tbl != nil {
+ for _, col := range tbl.GetColumns() {
+ sourceColumn := base.SourceColumnSet{}
+ sourceColumn[base.ColumnResource{
+ Database: keyspace,
+ Table: table,
+ Column: col.GetName(),
+ }] = true
+
+ results = append(results, base.QuerySpanResult{
+ Name: col.GetName(),
+ SourceColumns: sourceColumn,
+ IsPlainField: true,
+ })
+ }
+ return results
+ }
+ }
+
+ // Table not found - fall back to SelectAsterisk flag
+ return []base.QuerySpanResult{{
+ Name: "",
+ SourceColumns: base.SourceColumnSet{},
+ SelectAsterisk: true,
+ }}
+}
+
+// extractWhereColumns extracts column references from WHERE clause
+func (*querySpanExtractor) extractWhereColumns(whereSpec cql.IWhereSpecContext, _, _ string) {
+ if whereSpec == nil {
+ return
+ }
+
+ // For now, we'll mark that we found columns in WHERE clause
+ // A full implementation would parse the relation elements
+ // to extract all column references
+
+ // This is a simplified implementation - a complete one would
+ // walk through all relation elements and extract column names
+}
diff --git a/backend/plugin/parser/cassandra/query_span_test.go b/backend/plugin/parser/cassandra/query_span_test.go
new file mode 100644
index 0000000000..b9161e0d67
--- /dev/null
+++ b/backend/plugin/parser/cassandra/query_span_test.go
@@ -0,0 +1,328 @@
+package cassandra
+
+import (
+ "context"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/bytebase/bytebase/backend/plugin/parser/base"
+)
+
+func TestGetQuerySpan(t *testing.T) {
+ tests := []struct {
+ name string
+ statement string
+ want base.QuerySpan
+ }{
+ {
+ name: "SELECT with specific columns",
+ statement: "SELECT name, email FROM users WHERE id = 123",
+ want: base.QuerySpan{
+ Results: []base.QuerySpanResult{
+ {
+ Name: "name",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "users",
+ Column: "name",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ {
+ Name: "email",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "users",
+ Column: "email",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ },
+ },
+ },
+ {
+ name: "SELECT * (asterisk) - falls back without metadata",
+ statement: "SELECT * FROM products",
+ want: base.QuerySpan{
+ Results: []base.QuerySpanResult{
+ {
+ Name: "",
+ SourceColumns: base.SourceColumnSet{},
+ SelectAsterisk: true,
+ },
+ },
+ },
+ },
+ {
+ name: "SELECT with keyspace.table notation",
+ statement: "SELECT id, name FROM myapp.customers",
+ want: base.QuerySpan{
+ Results: []base.QuerySpanResult{
+ {
+ Name: "id",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "myapp",
+ Table: "customers",
+ Column: "id",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ {
+ Name: "name",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "myapp",
+ Table: "customers",
+ Column: "name",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ },
+ },
+ },
+ {
+ name: "SELECT with double-quoted table name",
+ statement: `SELECT id FROM "MyTable"`,
+ want: base.QuerySpan{
+ Results: []base.QuerySpanResult{
+ {
+ Name: "id",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "MyTable",
+ Column: "id",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ },
+ },
+ },
+ {
+ name: "SELECT with double-quoted column names",
+ statement: `SELECT "FirstName", "LastName" FROM users`,
+ want: base.QuerySpan{
+ Results: []base.QuerySpanResult{
+ {
+ Name: "FirstName",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "users",
+ Column: "FirstName",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ {
+ Name: "LastName",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "users",
+ Column: "LastName",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ },
+ },
+ },
+ {
+ name: "SELECT with double-quoted keyspace and table",
+ statement: `SELECT id FROM "MyKeyspace"."MyTable"`,
+ want: base.QuerySpan{
+ Results: []base.QuerySpanResult{
+ {
+ Name: "id",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "MyKeyspace",
+ Table: "MyTable",
+ Column: "id",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ },
+ },
+ },
+ {
+ name: "SELECT with alias using AS",
+ statement: `SELECT name AS user_name, email AS user_email FROM users`,
+ want: base.QuerySpan{
+ Results: []base.QuerySpanResult{
+ {
+ Name: "user_name",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "users",
+ Column: "name",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ {
+ Name: "user_email",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "users",
+ Column: "email",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ },
+ },
+ },
+ {
+ name: "SELECT with double-quoted alias",
+ statement: `SELECT name AS "User Name", email AS "User Email" FROM users`,
+ want: base.QuerySpan{
+ Results: []base.QuerySpanResult{
+ {
+ Name: "User Name",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "users",
+ Column: "name",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ {
+ Name: "User Email",
+ SourceColumns: base.SourceColumnSet{
+ base.ColumnResource{
+ Database: "test_keyspace",
+ Table: "users",
+ Column: "email",
+ }: true,
+ },
+ IsPlainField: true,
+ },
+ },
+ },
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ctx := context.Background()
+ gCtx := base.GetQuerySpanContext{}
+
+ got, err := GetQuerySpan(ctx, gCtx, tt.statement, "test_keyspace", "", false)
+ require.NoError(t, err)
+ require.NotNil(t, got)
+
+ // Check Results length
+ require.Equal(t, len(tt.want.Results), len(got.Results), "Result count mismatch")
+
+ // Check each result
+ for i, wantResult := range tt.want.Results {
+ gotResult := got.Results[i]
+
+ require.Equal(t, wantResult.Name, gotResult.Name, "Column name mismatch at index %d", i)
+ require.Equal(t, wantResult.SelectAsterisk, gotResult.SelectAsterisk, "SelectAsterisk mismatch at index %d", i)
+ require.Equal(t, wantResult.IsPlainField, gotResult.IsPlainField, "IsPlainField mismatch at index %d", i)
+
+ // Check source columns if not SELECT *
+ if !wantResult.SelectAsterisk {
+ for col := range wantResult.SourceColumns {
+ require.Contains(t, gotResult.SourceColumns, col, "Missing source column %+v", col)
+ }
+ }
+ }
+ })
+ }
+}
+
+func TestGetQuerySpanWithErrors(t *testing.T) {
+ tests := []struct {
+ name string
+ statement string
+ wantErr bool
+ }{
+ {
+ name: "Invalid CQL syntax",
+ statement: "SELECT FROM WHERE",
+ wantErr: true,
+ },
+ {
+ name: "Empty statement",
+ statement: "",
+ wantErr: false, // Empty statement doesn't error, just returns empty span
+ },
+ {
+ name: "Unclosed quoted identifier",
+ statement: `SELECT "unclosed FROM users`,
+ wantErr: true,
+ },
+ {
+ name: "Invalid SELECT syntax",
+ statement: "SELECT , , FROM users",
+ wantErr: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ctx := context.Background()
+ gCtx := base.GetQuerySpanContext{}
+
+ _, err := GetQuerySpan(ctx, gCtx, tt.statement, "test_keyspace", "", false)
+ if tt.wantErr {
+ require.Error(t, err)
+ } else {
+ require.NoError(t, err)
+ }
+ })
+ }
+}
+
+func TestSelectAsteriskWithMetadata(t *testing.T) {
+ tests := []struct {
+ name string
+ statement string
+ hasMetadata bool
+ expectExpand bool
+ }{
+ {
+ name: "SELECT * without metadata function",
+ statement: "SELECT * FROM users",
+ hasMetadata: false,
+ expectExpand: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ctx := context.Background()
+ gCtx := base.GetQuerySpanContext{}
+ // Note: tt.hasMetadata would be used to set up mock metadata function
+ // For now, we're testing the fallback behavior without metadata
+
+ got, err := GetQuerySpan(ctx, gCtx, tt.statement, "test_keyspace", "", false)
+ require.NoError(t, err)
+ require.NotNil(t, got)
+
+ if !tt.expectExpand && len(got.Results) > 0 {
+ // Should have SelectAsterisk flag set
+ require.True(t, got.Results[0].SelectAsterisk, "Expected SelectAsterisk flag to be true")
+ require.Empty(t, got.Results[0].Name, "Expected empty name for SELECT *")
+ }
+ })
+ }
+}
diff --git a/backend/plugin/parser/cassandra/split.go b/backend/plugin/parser/cassandra/split.go
new file mode 100644
index 0000000000..28ba612625
--- /dev/null
+++ b/backend/plugin/parser/cassandra/split.go
@@ -0,0 +1,39 @@
+package cassandra
+
+import (
+ "github.com/antlr4-go/antlr/v4"
+ "github.com/bytebase/parser/cql"
+
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
+ "github.com/bytebase/bytebase/backend/plugin/parser/base"
+)
+
+func init() {
+ base.RegisterSplitterFunc(storepb.Engine_CASSANDRA, SplitSQL)
+}
+
+// SplitSQL splits CQL statements into multiple single statements.
+func SplitSQL(statement string) ([]base.SingleSQL, error) {
+ lexer := cql.NewCqlLexer(antlr.NewInputStream(statement))
+ stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
+ p := cql.NewCqlParser(stream)
+
+ p.BuildParseTrees = true
+ p.RemoveErrorListeners()
+
+ tree := p.Root()
+ if tree == nil {
+ return nil, nil
+ }
+
+ // For now, return the entire statement as a single SQL
+ // CQL typically doesn't support multiple statements in one query
+ // unlike SQL databases
+ return []base.SingleSQL{
+ {
+ Text: statement,
+ ByteOffsetStart: 0,
+ ByteOffsetEnd: len(statement),
+ },
+ }, nil
+}
diff --git a/backend/server/ultimate.go b/backend/server/ultimate.go
index ffed25df98..bd1fbae2a4 100644
--- a/backend/server/ultimate.go
+++ b/backend/server/ultimate.go
@@ -28,6 +28,7 @@ import (
// Parsers.
_ "github.com/bytebase/bytebase/backend/plugin/parser/bigquery"
+ _ "github.com/bytebase/bytebase/backend/plugin/parser/cassandra"
_ "github.com/bytebase/bytebase/backend/plugin/parser/cosmosdb"
_ "github.com/bytebase/bytebase/backend/plugin/parser/doris"
_ "github.com/bytebase/bytebase/backend/plugin/parser/elasticsearch"
diff --git a/frontend/src/components/ColumnDataTable/index.vue b/frontend/src/components/ColumnDataTable/index.vue
index 9df7dbddc8..ca5c067d14 100644
--- a/frontend/src/components/ColumnDataTable/index.vue
+++ b/frontend/src/components/ColumnDataTable/index.vue
@@ -80,6 +80,7 @@ const showSensitiveColumn = computed(() => {
engine.value === Engine.MSSQL ||
engine.value === Engine.BIGQUERY ||
engine.value === Engine.SPANNER ||
+ engine.value === Engine.CASSANDRA ||
engine.value === Engine.TRINO)
);
});