From 8dbd4a2fc83006fad58ea2c1cbd98b9a9212fffc Mon Sep 17 00:00:00 2001 From: David Kagan Date: Mon, 13 Mar 2023 14:49:13 -0400 Subject: [PATCH] adding backwards compatibility this commit also adds support for ordering systemTables and implements the method --- sql3/planner/compileselect.go | 2 +- sql3/planner/compileshow.go | 2 +- sql3/planner/executionplannersystemtables.go | 6 ++-- sql3/planner/opsystemtable.go | 36 +++++++++++++++++++- sql3/planner/wireprotocol.go | 2 +- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/sql3/planner/compileselect.go b/sql3/planner/compileselect.go index ddecdfd20..168f9401c 100644 --- a/sql3/planner/compileselect.go +++ b/sql3/planner/compileselect.go @@ -406,7 +406,7 @@ func (p *ExecutionPlanner) compileSource(scope *PlanOpQuery, source parser.Sourc tableName := strings.ToLower(parser.IdentName(sourceExpr.Name)) // doing this check here because we don't have a 'system' flag that exists in the FB schema - st, ok := systemTables[tableName] + st, ok := systemTables.table(tableName) if ok { var op types.PlanOperator op = NewPlanOpSystemTable(p, st) diff --git a/sql3/planner/compileshow.go b/sql3/planner/compileshow.go index 5fd14bbd0..b70aa6129 100644 --- a/sql3/planner/compileshow.go +++ b/sql3/planner/compileshow.go @@ -235,7 +235,7 @@ func (p *ExecutionPlanner) compileShowCreateTableStatement(ctx context.Context, } // get the system table - systemTable, ok := systemTables[fbTableDDL] + systemTable, ok := systemTables.table(fbTableDDL) if !ok { return nil, sql3.NewErrInternalf("unable to find system table fb_table_ddl") } diff --git a/sql3/planner/executionplannersystemtables.go b/sql3/planner/executionplannersystemtables.go index db263ce57..da8338047 100644 --- a/sql3/planner/executionplannersystemtables.go +++ b/sql3/planner/executionplannersystemtables.go @@ -50,7 +50,7 @@ func (s *systemTableDefinitionsWrapper) TableByName(ctx context.Context, tname d tbl, err := s.schemaAPI.TableByName(ctx, tname) if err != nil { if isTableNotFoundError(err) { - st, ok := systemTables[string(tname)] + st, ok := systemTables.table(string(tname)) if !ok { return nil, dax.NewErrTableNameDoesNotExist(tname) } @@ -73,10 +73,10 @@ func (s *systemTableDefinitionsWrapper) Tables(ctx context.Context) ([]*dax.Tabl } // Append the system tables. - for tblName, st := range systemTables { + for _, st := range systemTables.ordered() { ii, err := indexInfoFromSystemTable(st) if err != nil { - return nil, errors.Wrapf(err, "converting system table to table: %s", tblName) + return nil, errors.Wrapf(err, "converting system table to table: %s", st.name) } tbls = append(tbls, pilosa.IndexInfoToTable(ii)) } diff --git a/sql3/planner/opsystemtable.go b/sql3/planner/opsystemtable.go index 3f940cef2..168c2716c 100644 --- a/sql3/planner/opsystemtable.go +++ b/sql3/planner/opsystemtable.go @@ -6,6 +6,7 @@ import ( "bytes" "context" "fmt" + "sort" pilosa "github.com/featurebasedb/featurebase/v3" "github.com/featurebasedb/featurebase/v3/pql" @@ -22,6 +23,9 @@ const ( fbExecRequests = "fb_exec_requests" fbPerformanceCounters = "fb_performance_counters" + fbClusterInfo = "fb_cluster_info" + fbClusterNodes = "fb_cluster_nodes" + fbTableDDL = "fb_table_ddl" ) @@ -31,7 +35,37 @@ type systemTable struct { requiresFanout bool } -var systemTables = map[string]*systemTable{ +type systemTableMap map[string]*systemTable + + +// table enables backwards compatibility with changing the system table names +// from fb_cluster_nodes and fb_cluster_info to fb_database_nodes and fb_database_info +// respectively. +func (s systemTableMap) table(name string) (*systemTable, bool) { + switch name { + case fbClusterInfo: + name = fbDatabaseInfo + case fbClusterNodes: + name = fbDatabaseNodes + } + + t, ok := s[name] + return t, ok +} + +// ordered returns the map as an ordered slice of systemTable. +func (s systemTableMap) ordered() []*systemTable { + out := make([]*systemTable, 0, len(s)) + for _, v := range s { + out = append(out, v) + } + sort.Slice(out, func(i, j int) bool { + return out[i].name < out[j].name + }) + return out +} + +var systemTables = systemTableMap{ fbDatabaseInfo: { name: fbDatabaseInfo, schema: types.Schema{ diff --git a/sql3/planner/wireprotocol.go b/sql3/planner/wireprotocol.go index b43a90fb2..888342996 100644 --- a/sql3/planner/wireprotocol.go +++ b/sql3/planner/wireprotocol.go @@ -105,7 +105,7 @@ func newMessagePlanOp(p *ExecutionPlanner, reader io.Reader) (*messagePlanOp, er } name := string(bname) - st, ok := systemTables[name] + st, ok := systemTables.table(name) if !ok { return nil, sql3.NewErrInternalf("unexpected system table name %s", name) }