Skip to content

Commit af77007

Browse files
committed
Merge branch 'main' of github.com:dolthub/doltgresql into codeaucafe/1648-values-clause-type-inference
# Conflicts: # server/expression/explicit_cast.go
2 parents f324664 + 1eded64 commit af77007

89 files changed

Lines changed: 4935 additions & 310 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/context.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func GetSqlTableFromContext(ctx *sql.Context, databaseName string, tableName dol
199199
var searchPath []string
200200
if len(tableName.Schema) == 0 {
201201
// If a schema was not provided, then we'll use the search path
202-
searchPath, err = resolve.SearchPath(ctx)
202+
searchPath, err = SearchPath(ctx)
203203
if err != nil {
204204
return nil, err
205205
}
@@ -228,6 +228,30 @@ func GetSqlTableFromContext(ctx *sql.Context, databaseName string, tableName dol
228228
return nil, nil
229229
}
230230

231+
// SearchPath returns the effective schema search path for the current session
232+
func SearchPath(ctx *sql.Context) ([]string, error) {
233+
path, err := resolve.SearchPath(ctx)
234+
if err != nil {
235+
return nil, err
236+
}
237+
238+
// pg_catalog is *always* implicitly part of the search path as the first element, unless it's specifically
239+
// included later. This allows users to override built-in names with user-defined names, but they have to
240+
// opt in to that behavior.
241+
hasPgCatalog := false
242+
for _, schema := range path {
243+
if schema == "pg_catalog" {
244+
hasPgCatalog = true
245+
break
246+
}
247+
}
248+
249+
if !hasPgCatalog {
250+
path = append([]string{"pg_catalog"}, path...)
251+
}
252+
return path, nil
253+
}
254+
231255
// GetExtensionsCollectionFromContext returns the extensions collection from the given context. Will always return a
232256
// collection if no error is returned.
233257
func GetExtensionsCollectionFromContext(ctx *sql.Context, database string) (*extensions.Collection, error) {

core/rootvalue.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package core
1717
import (
1818
"bytes"
1919
"context"
20+
"fmt"
2021
"slices"
2122
"sort"
2223
"strconv"
@@ -87,6 +88,62 @@ func (root *RootValue) CreateDatabaseSchema(ctx context.Context, dbSchema schema
8788
return root.withStorage(r), nil
8889
}
8990

91+
// DropDatabaseSchema implements the interface doltdb.RootValue.
92+
func (root *RootValue) DropDatabaseSchema(ctx context.Context, dbSchema schema.DatabaseSchema) (doltdb.RootValue, error) {
93+
schemas, err := root.st.GetSchemas(ctx)
94+
if err != nil {
95+
return nil, err
96+
}
97+
98+
found := false
99+
schemaName := dbSchema.Name
100+
for i, s := range schemas {
101+
if strings.EqualFold(s.Name, dbSchema.Name) {
102+
found = true
103+
schemaName = s.Name
104+
// remove this element in the slice
105+
schemas = append(schemas[:i], schemas[i+1:]...)
106+
break
107+
}
108+
}
109+
110+
if !found {
111+
return nil, fmt.Errorf("No schema with the name %s exists", dbSchema.Name)
112+
}
113+
114+
// Check for dangling objects in the schema and reject the drop if there are any
115+
danglingObjects := false
116+
root.IterRootObjects(ctx, func(name doltdb.TableName, table doltdb.RootObject) (stop bool, err error) {
117+
if strings.EqualFold(name.Schema, dbSchema.Name) {
118+
danglingObjects = true
119+
}
120+
return false, nil
121+
})
122+
123+
// check the tables specifically in addition to root objects. This is just an extra paranoid step to avoid
124+
// removing a schema that still has tables.
125+
tableMap, err := root.getTableMap(ctx, schemaName)
126+
if err != nil {
127+
return nil, err
128+
}
129+
130+
tableMap.Iter(ctx, func(name string, addr hash.Hash) (bool, error) {
131+
danglingObjects = true
132+
return true, nil
133+
})
134+
135+
if danglingObjects {
136+
return nil, fmt.Errorf("cannot drop schema %s because other objects depend on it", dbSchema.Name)
137+
}
138+
139+
r, err := root.st.SetSchemas(ctx, schemas)
140+
if err != nil {
141+
return nil, err
142+
}
143+
144+
return root.withStorage(r), nil
145+
}
146+
90147
// validateSchemaForCreate returns an error if a schema with the name given cannot be created
91148
func validateSchemaForCreate(existingSchemas []schema.DatabaseSchema, dbSchema schema.DatabaseSchema) error {
92149
if dbSchema.Name == "" {

core/typecollection/typecollection.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ import (
3232
pgtypes "github.com/dolthub/doltgresql/server/types"
3333
)
3434

35+
// anonymousCompositePrefix is the prefix for anonymous composite type names. These types are not stored on
36+
// disk, but instead are created dynamically as needed.
37+
const anonymousCompositePrefix = "table("
38+
39+
// anonymousCompositeSuffix is the suffix for anonymous composite type names.
40+
const anonymousCompositeSuffix = ")"
41+
3542
// TypeCollection is a collection of all types (both built-in and user defined).
3643
type TypeCollection struct {
3744
accessedMap map[id.Type]*pgtypes.DoltgresType
@@ -165,6 +172,11 @@ func (pgs *TypeCollection) GetType(ctx context.Context, name id.Type) (*pgtypes.
165172
return nil, err
166173
}
167174
if h.IsEmpty() {
175+
// If this is an anonymous composite type, create it dynamically
176+
if isAnonymousCompositeType(name) {
177+
return createAnonymousCompositeType(ctx, name)
178+
}
179+
168180
// If it's not a built-in type or created type, then check if it's a composite table row type
169181
sqlCtx, ok := ctx.(*sql.Context)
170182
if !ok {
@@ -189,6 +201,34 @@ func (pgs *TypeCollection) GetType(ctx context.Context, name id.Type) (*pgtypes.
189201
return pgt, nil
190202
}
191203

204+
// isAnonymousCompositeType return true if |returnType| represents an anonymous composite return type
205+
// for a function (i.e. the function was declared as "RETURNS TABLE(...)").
206+
func isAnonymousCompositeType(returnType id.Type) bool {
207+
typeName := returnType.TypeName()
208+
return strings.HasPrefix(typeName, anonymousCompositePrefix) &&
209+
strings.HasSuffix(typeName, anonymousCompositeSuffix)
210+
}
211+
212+
// createAnonymousCompositeType creates a new DoltgresType for the anonymous composite return type for a function,
213+
// as represented by |returnType|.
214+
func createAnonymousCompositeType(ctx context.Context, returnType id.Type) (*pgtypes.DoltgresType, error) {
215+
typeName := returnType.TypeName()
216+
attributeTypes := typeName[len(anonymousCompositePrefix) : len(typeName)-len(anonymousCompositeSuffix)]
217+
attributeTypesSlice := strings.Split(attributeTypes, ",")
218+
219+
attrs := make([]pgtypes.CompositeAttribute, len(attributeTypesSlice))
220+
for i, attributeNameAndType := range attributeTypesSlice {
221+
split := strings.Split(attributeNameAndType, ":")
222+
if len(split) != 2 {
223+
return nil, fmt.Errorf("unexpected anonymous composite type attribute syntax: %s", attributeNameAndType)
224+
}
225+
226+
typeId := id.NewType("", split[1])
227+
attrs[i] = pgtypes.NewCompositeAttribute(nil, id.Null, split[0], typeId, int16(i), "")
228+
}
229+
return pgtypes.NewCompositeType(ctx, id.Null, id.NullType, returnType, attrs), nil
230+
}
231+
192232
// HasType checks if a type exists with given schema and type name.
193233
func (pgs *TypeCollection) HasType(ctx context.Context, name id.Type) bool {
194234
// We can check the built-in types first

go.mod

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
module github.com/dolthub/doltgresql
22

3-
go 1.25.3
3+
go 1.25.6
44

55
require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
88
github.com/cockroachdb/errors v1.7.5
9-
github.com/dolthub/dolt/go v0.40.5-0.20251218212126-9571842973ec
9+
github.com/dolthub/dolt/go v0.40.5-0.20260205201004-79fc4cd2a852
1010
github.com/dolthub/eventsapi_schema v0.0.0-20250915094920-eadfd39051ca
1111
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
12-
github.com/dolthub/go-mysql-server v0.20.1-0.20251218001312-084240aa6481
12+
github.com/dolthub/go-mysql-server v0.20.1-0.20260205181409-94138bb5f115
1313
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1
1414
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
15-
github.com/dolthub/vitess v0.0.0-20251210200925-1d33d416d162
15+
github.com/dolthub/vitess v0.0.0-20260202234501-b14ed9b1632b
1616
github.com/fatih/color v1.13.0
1717
github.com/goccy/go-json v0.10.2
1818
github.com/gogo/protobuf v1.3.2
@@ -31,16 +31,16 @@ require (
3131
github.com/pkg/profile v1.5.0
3232
github.com/sergi/go-diff v1.1.0
3333
github.com/shopspring/decimal v1.4.0
34-
github.com/sirupsen/logrus v1.8.1
34+
github.com/sirupsen/logrus v1.8.3
3535
github.com/stretchr/testify v1.11.1
3636
github.com/twpayne/go-geom v1.3.6
3737
github.com/xdg-go/stringprep v1.0.4
38-
golang.org/x/crypto v0.41.0
38+
golang.org/x/crypto v0.45.0
3939
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
40-
golang.org/x/net v0.43.0
41-
golang.org/x/sync v0.16.0
42-
golang.org/x/sys v0.35.0
43-
golang.org/x/text v0.28.0
40+
golang.org/x/net v0.47.0
41+
golang.org/x/sync v0.18.0
42+
golang.org/x/sys v0.38.0
43+
golang.org/x/text v0.31.0
4444
gopkg.in/src-d/go-errors.v1 v1.0.0
4545
gopkg.in/yaml.v2 v2.4.0
4646
)
@@ -103,6 +103,7 @@ require (
103103
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 // indirect
104104
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 // indirect
105105
github.com/dustin/go-humanize v1.0.1 // indirect
106+
github.com/ebitengine/purego v0.9.1 // indirect
106107
github.com/edsrzf/mmap-go v1.2.0 // indirect
107108
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
108109
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
@@ -112,6 +113,7 @@ require (
112113
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
113114
github.com/go-logr/logr v1.4.3 // indirect
114115
github.com/go-logr/stdr v1.2.2 // indirect
116+
github.com/go-ole/go-ole v1.2.6 // indirect
115117
github.com/go-sql-driver/mysql v1.9.3 // indirect
116118
github.com/gocraft/dbr/v2 v2.7.2 // indirect
117119
github.com/gofrs/flock v0.8.1 // indirect
@@ -141,6 +143,7 @@ require (
141143
github.com/kr/text v0.2.0 // indirect
142144
github.com/kylelemons/godebug v1.1.0 // indirect
143145
github.com/lestrrat-go/strftime v1.0.4 // indirect
146+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
144147
github.com/mark3labs/mcp-go v0.34.0 // indirect
145148
github.com/mattn/go-colorable v0.1.13 // indirect
146149
github.com/mattn/go-isatty v0.0.17 // indirect
@@ -152,12 +155,14 @@ require (
152155
github.com/pkg/errors v0.9.1 // indirect
153156
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
154157
github.com/pmezard/go-difflib v1.0.0 // indirect
158+
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
155159
github.com/prometheus/client_golang v1.23.2 // indirect
156160
github.com/prometheus/client_model v0.6.2 // indirect
157161
github.com/prometheus/common v0.66.1 // indirect
158162
github.com/prometheus/procfs v0.16.1 // indirect
159163
github.com/rivo/uniseg v0.2.0 // indirect
160164
github.com/rogpeppe/go-internal v1.13.1 // indirect
165+
github.com/shirou/gopsutil/v4 v4.25.12 // indirect
161166
github.com/silvasur/buzhash v0.0.0-20160816060738-9bdec3dec7c6 // indirect
162167
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
163168
github.com/sony/gobreaker v0.5.0 // indirect
@@ -168,11 +173,14 @@ require (
168173
github.com/tidwall/match v1.1.1 // indirect
169174
github.com/tidwall/pretty v1.2.1 // indirect
170175
github.com/tidwall/sjson v1.2.5 // indirect
176+
github.com/tklauser/go-sysconf v0.3.16 // indirect
177+
github.com/tklauser/numcpus v0.11.0 // indirect
171178
github.com/twpayne/go-kml v1.5.2-0.20200728095708-9f2fd4dfcbfe // indirect
172179
github.com/vbauerster/mpb/v8 v8.0.2 // indirect
173180
github.com/xitongsys/parquet-go v1.6.1 // indirect
174181
github.com/xitongsys/parquet-go-source v0.0.0-20211010230925-397910c5e371 // indirect
175182
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
183+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
176184
github.com/zeebo/errs v1.4.0 // indirect
177185
github.com/zeebo/xxh3 v1.0.2 // indirect
178186
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
@@ -187,11 +195,12 @@ require (
187195
go.uber.org/multierr v1.10.0 // indirect
188196
go.uber.org/zap v1.27.0 // indirect
189197
go.yaml.in/yaml/v2 v2.4.2 // indirect
190-
golang.org/x/mod v0.26.0 // indirect
198+
golang.org/x/mod v0.29.0 // indirect
191199
golang.org/x/oauth2 v0.30.0 // indirect
192-
golang.org/x/term v0.34.0 // indirect
200+
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 // indirect
201+
golang.org/x/term v0.37.0 // indirect
193202
golang.org/x/time v0.12.0 // indirect
194-
golang.org/x/tools v0.35.0 // indirect
203+
golang.org/x/tools v0.38.0 // indirect
195204
google.golang.org/api v0.241.0 // indirect
196205
google.golang.org/genproto v0.0.0-20250505200425-f936aa4a68b2 // indirect
197206
google.golang.org/genproto/googleapis/api v0.0.0-20250528174236-200df99c418a // indirect

0 commit comments

Comments
 (0)