Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable removing a selected field #5457

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 35 additions & 31 deletions pkg/query-service/app/clickhouseReader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3575,38 +3575,42 @@ func (r *ClickHouseReader) UpdateLogField(ctx context.Context, field *model.Upda
}

} else {
// Delete the index first
query := fmt.Sprintf("ALTER TABLE %s.%s ON CLUSTER %s DROP INDEX IF EXISTS %s_idx`", r.logsDB, r.logsLocalTable, r.cluster, strings.TrimSuffix(colname, "`"))
err := r.db.Exec(ctx, query)
if err != nil {
return &model.ApiError{Err: err, Typ: model.ErrorInternal}
}
// We are not allowing to delete a materialized column
// For more details please check https://github.com/SigNoz/signoz/issues/4566
return model.ForbiddenError(errors.New("Removing a selected field is not allowed, please reach out to support."))

for _, table := range []string{r.logsTable, r.logsLocalTable} {
// drop materialized column from logs table
query := "ALTER TABLE %s.%s ON CLUSTER %s DROP COLUMN IF EXISTS %s "
err := r.db.Exec(ctx, fmt.Sprintf(query,
r.logsDB, table,
r.cluster,
colname,
),
)
if err != nil {
return &model.ApiError{Err: err, Typ: model.ErrorInternal}
}

// drop exists column on logs table
query = "ALTER TABLE %s.%s ON CLUSTER %s DROP COLUMN IF EXISTS %s_exists` "
err = r.db.Exec(ctx, fmt.Sprintf(query,
r.logsDB, table,
r.cluster,
strings.TrimSuffix(colname, "`"),
),
)
if err != nil {
return &model.ApiError{Err: err, Typ: model.ErrorInternal}
}
}
// Delete the index first
// query := fmt.Sprintf("ALTER TABLE %s.%s ON CLUSTER %s DROP INDEX IF EXISTS %s_idx`", r.logsDB, r.logsLocalTable, r.cluster, strings.TrimSuffix(colname, "`"))
// err := r.db.Exec(ctx, query)
// if err != nil {
// return &model.ApiError{Err: err, Typ: model.ErrorInternal}
// }

// for _, table := range []string{r.logsTable, r.logsLocalTable} {
// // drop materialized column from logs table
// query := "ALTER TABLE %s.%s ON CLUSTER %s DROP COLUMN IF EXISTS %s "
// err := r.db.Exec(ctx, fmt.Sprintf(query,
// r.logsDB, table,
// r.cluster,
// colname,
// ),
// )
// if err != nil {
// return &model.ApiError{Err: err, Typ: model.ErrorInternal}
// }

// // drop exists column on logs table
// query = "ALTER TABLE %s.%s ON CLUSTER %s DROP COLUMN IF EXISTS %s_exists` "
// err = r.db.Exec(ctx, fmt.Sprintf(query,
// r.logsDB, table,
// r.cluster,
// strings.TrimSuffix(colname, "`"),
// ),
// )
// if err != nil {
// return &model.ApiError{Err: err, Typ: model.ErrorInternal}
// }
// }
}
return nil
}
Expand Down
Loading