// Create a source schema from given named source // we will find Source for that name and introspect func createSchema(sourceName string) (*schema.Schema, bool) { sourceName = strings.ToLower(sourceName) ss := schema.NewSchemaSource(sourceName, sourceName) ds := registry.Get(sourceName) if ds == nil { parts := strings.SplitN(sourceName, "://", 2) //u.Infof("parts: %d %v", len(parts), parts) if len(parts) == 2 { ds = registry.Get(parts[0]) if ds == nil { //return &qlbConn{schema: s, connInfo: parts[1]}, nil u.Warnf("not able to find schema %q", sourceName) return nil, false } } else { //u.WarnT(7) u.Warnf("not able to find schema %q", sourceName) return nil, false } } u.Infof("reg p:%p source=%q ds %#v tables:%v", registry, sourceName, ds, ds.Tables()) ss.DS = ds schema := schema.NewSchema(sourceName) ss.Schema = schema u.Debugf("schema:%p ss:%p createSchema(%q) NEW ", schema, ss, sourceName) loadSchema(ss) return schema, true }
// We are going to Create an 'information_schema' for given schema func loadSystemSchema(ss *schema.SchemaSource) error { s := ss.Schema if s == nil { return fmt.Errorf("Must have schema but was nil") } infoSchema := s.InfoSchema var infoSchemaSource *schema.SchemaSource if infoSchema == nil { infoSchemaSource = schema.NewSchemaSource("schema", "schema") //u.Infof("reg p:%p ds %#v tables:%v", registry, ds, ds.Tables()) schemaDb := NewSchemaDb(s) infoSchemaSource.DS = schemaDb infoSchema = schema.NewSchema("schema") schemaDb.is = infoSchema //u.Debugf("schema:%p ss:%p loadSystemSchema: NEW infoschema:%p s:%s ss:%s", s, ss, infoSchema, s.Name, ss.Name) infoSchemaSource.Schema = infoSchema infoSchemaSource.AddTableName("tables") infoSchema.SchemaSources["schema"] = infoSchemaSource infoSchema.InfoSchema = infoSchema } else { infoSchemaSource = infoSchema.SchemaSources["schema"] } // For each table in source schema for _, tableName := range ss.Tables() { //u.Debugf("adding table: %q to infoSchema %p", tableName, infoSchema) _, err := ss.Table(tableName) if err != nil { u.Warnf("Missing table?? %q", tableName) continue } infoSchemaSource.AddTableName(tableName) } s.InfoSchema = infoSchema s.RefreshSchema() //u.Debugf("s:%p ss:%p infoschema:%p name:%s", s, ss, infoSchema, s.Name) return nil }
// NewMemDb creates a MemDb with given indexes, columns func NewMemDb(name string, cols []string) (*MemDb, error) { ss := schema.NewSchemaSource(name, sourceType) return NewMemDbForSchema(name, ss, cols) }