adding backwards compatibility

this commit also adds support for ordering systemTables and implements the method
This commit is contained in:
David Kagan 2023-03-13 14:49:13 -04:00 committed by Travis Turner
parent c29c4b6706
commit 8dbd4a2fc8
No known key found for this signature in database
GPG key ID: 3FB5CF5C97A37B30
5 changed files with 41 additions and 7 deletions

View file

@ -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)

View file

@ -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")
}

View file

@ -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))
}

View file

@ -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{

View file

@ -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)
}