mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-06 08:50:04 -06:00
Merge pull request #8391 from dolthub/taylor/info-schema
Return information_schema schema for doltgres
This commit is contained in:
@@ -57,7 +57,7 @@ require (
|
||||
github.com/cespare/xxhash/v2 v2.2.0
|
||||
github.com/creasty/defaults v1.6.0
|
||||
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
|
||||
github.com/dolthub/go-mysql-server v0.18.2-0.20240923181307-5aacdb13e45a
|
||||
github.com/dolthub/go-mysql-server v0.18.2-0.20240926171723-77ed13c03196
|
||||
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63
|
||||
github.com/dolthub/swiss v0.1.0
|
||||
github.com/goccy/go-json v0.10.2
|
||||
|
||||
@@ -183,8 +183,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
|
||||
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
|
||||
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 h1:aC17hZD6iwzBwwfO5M+3oBT5E5gGRiQPdn+vzpDXqIA=
|
||||
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
|
||||
github.com/dolthub/go-mysql-server v0.18.2-0.20240923181307-5aacdb13e45a h1:rpCmZj332eiBbzsHsq3Sj5AWzl3Q7szDObwI49UqA8Y=
|
||||
github.com/dolthub/go-mysql-server v0.18.2-0.20240923181307-5aacdb13e45a/go.mod h1:lGbU2bK+QNnlETdUjOOaE+UnlEUu31VaQOFKAFGyZN4=
|
||||
github.com/dolthub/go-mysql-server v0.18.2-0.20240926171723-77ed13c03196 h1:H4bKFiOdjmhBrdjrNvYAuhfplpHM3aVFcbLXlGoD/Fc=
|
||||
github.com/dolthub/go-mysql-server v0.18.2-0.20240926171723-77ed13c03196/go.mod h1:lGbU2bK+QNnlETdUjOOaE+UnlEUu31VaQOFKAFGyZN4=
|
||||
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
|
||||
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
|
||||
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
|
||||
|
||||
@@ -1377,6 +1377,11 @@ func (db Database) CreateSchema(ctx *sql.Context, schemaName string) error {
|
||||
|
||||
// GetSchema implements sql.SchemaDatabase
|
||||
func (db Database) GetSchema(ctx *sql.Context, schemaName string) (sql.DatabaseSchema, bool, error) {
|
||||
// For doltgres, the information_schema database should be a schema.
|
||||
if schemaName == sql.InformationSchemaDatabaseName {
|
||||
return newInformationSchemaDatabase(db.Name()), true, nil
|
||||
}
|
||||
|
||||
ws, err := db.GetWorkingSet(ctx)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
@@ -1432,7 +1437,7 @@ func (db Database) AllSchemas(ctx *sql.Context) ([]sql.DatabaseSchema, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dbSchemas := make([]sql.DatabaseSchema, len(schemas))
|
||||
dbSchemas := make([]sql.DatabaseSchema, len(schemas)+1)
|
||||
for i, schema := range schemas {
|
||||
sdb := db
|
||||
sdb.schemaName = schema.Name
|
||||
@@ -1443,6 +1448,9 @@ func (db Database) AllSchemas(ctx *sql.Context) ([]sql.DatabaseSchema, error) {
|
||||
dbSchemas[i] = handledDb
|
||||
}
|
||||
|
||||
// For doltgres, the information_schema database should be a schema.
|
||||
dbSchemas[len(schemas)] = newInformationSchemaDatabase(db.Name())
|
||||
|
||||
return dbSchemas, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,11 @@ type CommitIndex struct {
|
||||
*doltIndex
|
||||
}
|
||||
|
||||
// CanSupportOrderBy implements the interface sql.Index.
|
||||
func (p *CommitIndex) CanSupportOrderBy(_ sql.Expression) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *CommitIndex) CanSupport(ranges ...sql.Range) bool {
|
||||
var selects []string
|
||||
for _, r := range ranges {
|
||||
@@ -612,6 +617,11 @@ func (di *doltIndex) CanSupport(...sql.Range) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// CanSupportOrderBy implements the interface sql.Index.
|
||||
func (di *doltIndex) CanSupportOrderBy(_ sql.Expression) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ColumnExpressionTypes implements the interface sql.Index.
|
||||
func (di *doltIndex) ColumnExpressionTypes() []sql.ColumnExpressionType {
|
||||
cets := make([]sql.ColumnExpressionType, len(di.columns))
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2019-2020 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package sqle
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
"github.com/dolthub/go-mysql-server/sql/information_schema"
|
||||
)
|
||||
|
||||
// informationSchemaDatabaseSchema is a DatabaseSchema implementation that provides access to the INFORMATION_SCHEMA tables. This is relevant only for Doltgres.
|
||||
type informationSchemaDatabaseSchema struct {
|
||||
name string
|
||||
schemaName string
|
||||
tables map[string]sql.Table
|
||||
}
|
||||
|
||||
var _ sql.DatabaseSchema = (*informationSchemaDatabaseSchema)(nil)
|
||||
|
||||
// newInformationSchemaDatabase creates a new INFORMATION_SCHEMA DatabaseSchema for doltgres databases.
|
||||
func newInformationSchemaDatabase(dbName string) sql.DatabaseSchema {
|
||||
isDb := &informationSchemaDatabaseSchema{
|
||||
name: dbName,
|
||||
schemaName: sql.InformationSchemaDatabaseName,
|
||||
tables: information_schema.GetInformationSchemaTables(),
|
||||
}
|
||||
|
||||
isDb.tables[information_schema.StatisticsTableName] = information_schema.NewDefaultStats()
|
||||
|
||||
return isDb
|
||||
}
|
||||
|
||||
// Name implements the sql.DatabaseSchema interface.
|
||||
func (db *informationSchemaDatabaseSchema) Name() string { return db.name }
|
||||
|
||||
// SchemaName implements the sql.DatabaseSchema interface.
|
||||
func (db *informationSchemaDatabaseSchema) SchemaName() string { return db.schemaName }
|
||||
|
||||
// GetTableInsensitive implements the sql.DatabaseSchema interface.
|
||||
func (db *informationSchemaDatabaseSchema) GetTableInsensitive(ctx *sql.Context, tblName string) (sql.Table, bool, error) {
|
||||
// The columns table has dynamic information that can't be cached across queries
|
||||
if strings.ToLower(tblName) == information_schema.ColumnsTableName {
|
||||
return information_schema.NewColumnsTable(), true, nil
|
||||
}
|
||||
|
||||
tbl, ok := sql.GetTableInsensitive(tblName, db.tables)
|
||||
return tbl, ok, nil
|
||||
}
|
||||
|
||||
// GetTableNames implements the sql.DatabaseSchema interface.
|
||||
func (db *informationSchemaDatabaseSchema) GetTableNames(ctx *sql.Context) ([]string, error) {
|
||||
tblNames := make([]string, 0, len(db.tables))
|
||||
for k := range db.tables {
|
||||
tblNames = append(tblNames, k)
|
||||
}
|
||||
|
||||
return tblNames, nil
|
||||
}
|
||||
Reference in New Issue
Block a user