diff --git a/internal/chstorage/schema.go b/internal/chstorage/schema.go index 4f9a0fff..cb0f7b1d 100644 --- a/internal/chstorage/schema.go +++ b/internal/chstorage/schema.go @@ -17,6 +17,32 @@ type Tables struct { Labels string } +// Validate checks table names +func (t Tables) Validate() error { + validateTableName := func(name string) error { + if name == "" { + return errors.New("table name must be non-empty") + } + return nil + } + + for _, table := range []struct { + name string + fieldName string + }{ + {t.Spans, "Spans"}, + {t.Tags, "Tags"}, + + {t.Points, "Points"}, + {t.Labels, "Labels"}, + } { + if err := validateTableName(table.name); err != nil { + return errors.Wrapf(err, "table %s", table.fieldName) + } + } + return nil +} + var defaultTables = Tables{ Spans: "traces_spans", Tags: "traces_tags", @@ -31,6 +57,10 @@ type chClient interface { // Create creates tables. func (t Tables) Create(ctx context.Context, c chClient) error { + if err := t.Validate(); err != nil { + return errors.Wrap(err, "validate") + } + type schema struct { name string query string