Skip to content

Commit 0a3f608

Browse files
committed
Merge branch 'main' of https://github.com/dolthub/go-mysql-server into angela/joinfilterdrop
2 parents 609aab0 + e40c989 commit 0a3f608

File tree

11 files changed

+2368
-2409
lines changed

11 files changed

+2368
-2409
lines changed

enginetest/queries/queries.go

Lines changed: 60 additions & 288 deletions
Large diffs are not rendered by default.

enginetest/queries/script_queries.go

Lines changed: 2194 additions & 1622 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250916051405-78a38d478790
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250918181259-ed0e1c5cb192
9+
github.com/dolthub/vitess v0.0.0-20250924141028-c81f2df5db32
1010
github.com/go-sql-driver/mysql v1.9.3
1111
github.com/gocraft/dbr/v2 v2.7.2
1212
github.com/google/uuid v1.3.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9X
2020
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
2121
github.com/dolthub/vitess v0.0.0-20250918181259-ed0e1c5cb192 h1:s7Ghoy+x+C/spSjM5/w9MoMIIeXNcBY/fI2oHxWajLM=
2222
github.com/dolthub/vitess v0.0.0-20250918181259-ed0e1c5cb192/go.mod h1:8pvvk5OLaLN9LLxghyczUapn/97l+mBgIb10qC1LG84=
23+
github.com/dolthub/vitess v0.0.0-20250924141028-c81f2df5db32 h1:VvJIKIxqerl/12Z9zndDidUSWejER1/sBPZMaJp06Jo=
24+
github.com/dolthub/vitess v0.0.0-20250924141028-c81f2df5db32/go.mod h1:8pvvk5OLaLN9LLxghyczUapn/97l+mBgIb10qC1LG84=
2325
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
2426
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
2527
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=

sql/core.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ type Lockable interface {
281281
}
282282

283283
// ConvertToBool converts a value to a boolean. nil is considered false.
284+
// TODO: the logic here should be merged with types.Boolean.Convert()
284285
func ConvertToBool(ctx *Context, v interface{}) (bool, error) {
285286
switch b := v.(type) {
286287
case []uint8:
@@ -339,6 +340,7 @@ const (
339340
NumericCutSet = " \t\n\r"
340341
)
341342

343+
// TODO: type processing logic should all be in the types package
342344
func TrimStringToNumberPrefix(ctx *Context, s string, isInt bool) string {
343345
if isInt {
344346
s = strings.TrimLeft(s, IntCutSet)
@@ -353,7 +355,6 @@ func TrimStringToNumberPrefix(ctx *Context, s string, isInt bool) string {
353355

354356
for i := 0; i < len(s); i++ {
355357
char := rune(s[i])
356-
357358
if unicode.IsDigit(char) {
358359
seenDigit = true
359360
} else if char == '.' && !seenDot && !isInt {
@@ -362,7 +363,7 @@ func TrimStringToNumberPrefix(ctx *Context, s string, isInt bool) string {
362363
seenExp = true
363364
signIndex = i + 1
364365
} else if !((char == '-' || char == '+') && i == signIndex) {
365-
// TODO add different warning for DECIMAL conversion
366+
// TODO: this should not happen here, and it should use sql.ErrIncorrectTruncation
366367
if isInt {
367368
ctx.Warn(mysql.ERTruncatedWrongValue, "Truncated incorrect INTEGER value: '%s'", s)
368369
} else {

sql/expression/function/char.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,26 @@ func (c *Char) CollationCoercibility(ctx *sql.Context) (collation sql.CollationI
8585
return sql.Collation_binary, 5
8686
}
8787

88-
// char converts num into a byte array
89-
// This function is essentially converting the number to base 256
90-
func char(num uint32) []byte {
91-
if num == 0 {
92-
return []byte{}
88+
// encodeUint32 converts uint32 `num` into a []byte using the fewest number of bytes in big endian (no leading 0s)
89+
func encodeUint32(num uint32) []byte {
90+
res := []byte{
91+
byte(num >> 24),
92+
byte(num >> 16),
93+
byte(num >> 8),
94+
byte(num),
9395
}
94-
return append(char(num>>8), byte(num&255))
96+
var i int
97+
for i = 0; i < 3; i++ {
98+
if res[i] != 0 {
99+
break
100+
}
101+
}
102+
return res[i:]
95103
}
96104

97105
// Eval implements the sql.Expression interface
98106
func (c *Char) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
99-
res := []byte{}
107+
var res []byte
100108
for _, arg := range c.args {
101109
if arg == nil {
102110
continue
@@ -114,11 +122,14 @@ func (c *Char) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
114122
v, _, err := types.Uint32.Convert(ctx, val)
115123
if err != nil {
116124
ctx.Warn(1292, "Truncated incorrect INTEGER value: '%v'", val)
125+
}
126+
127+
if v == nil {
117128
res = append(res, 0)
118129
continue
119130
}
120131

121-
res = append(res, char(v.(uint32))...)
132+
res = append(res, encodeUint32(v.(uint32))...)
122133
}
123134

124135
result, _, err := c.Type().Convert(ctx, res)

sql/expression/tablefunction/table_function.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (t *TableFunctionWrapper) Expressions() []sql.Expression {
6868
if t.funcExpr == nil {
6969
return nil
7070
}
71-
return t.funcExpr.Children()
71+
return []sql.Expression{t.funcExpr}
7272
}
7373

7474
func (t *TableFunctionWrapper) IsReadOnly() bool {
@@ -130,15 +130,10 @@ func (t *TableFunctionWrapper) WithExpressions(exprs ...sql.Expression) (sql.Nod
130130
return nil, sql.ErrInvalidChildrenNumber.New(t, len(exprs), 0)
131131
}
132132
}
133-
l := len(t.funcExpr.Children())
134-
if len(exprs) != l {
135-
return nil, sql.ErrInvalidChildrenNumber.New(t, len(exprs), l)
133+
if len(exprs) != 1 {
134+
return nil, sql.ErrInvalidChildrenNumber.New(t, len(exprs), 1)
136135
}
137136
nt := *t
138-
nf, err := nt.funcExpr.WithChildren(exprs...)
139-
if err != nil {
140-
return nil, err
141-
}
142-
nt.funcExpr = nf
137+
nt.funcExpr = exprs[0]
143138
return &nt, nil
144139
}

sql/plan/values.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewValues(tuples [][]sql.Expression) *Values {
3636
return &Values{ExpressionTuples: tuples}
3737
}
3838

39-
// NewValuesWithAliasName creates a Values node with the given row and column aliases.
39+
// NewValuesWithAlias creates a Values node with the given row and column aliases.
4040
func NewValuesWithAlias(tableName string, columnNames map[string]string, tuples [][]sql.Expression) *Values {
4141
return &Values{ExpressionTuples: tuples, AliasName: tableName, ColumnNames: columnNames}
4242
}

sql/rows.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,47 @@ type sliceRowIter struct {
187187
idx int
188188
}
189189

190-
func (i *sliceRowIter) Next(*Context) (Row, error) {
190+
func (i *sliceRowIter) Next(ctx *Context) (Row, error) {
191191
if i.idx >= len(i.rows) {
192192
return nil, io.EOF
193193
}
194194

195-
r := i.rows[i.idx]
196-
i.idx++
197-
return r.Copy(), nil
195+
vals, hasRowIter, rowIterEnded, err := unwrapRowIterAsReturnedResult(ctx, i.rows[i.idx])
196+
if err != nil {
197+
return nil, err
198+
}
199+
200+
if !hasRowIter {
201+
i.idx++
202+
} else if rowIterEnded {
203+
return nil, io.EOF
204+
}
205+
206+
return NewRow(vals...), nil
207+
}
208+
209+
// unwrapRowIterAsReturnedResult unwraps the row if there is any RowIter in the given Row
210+
// creating multiple Rows from a single Row.
211+
func unwrapRowIterAsReturnedResult(ctx *Context, r Row) ([]any, bool, bool, error) {
212+
vals := make([]interface{}, len(r))
213+
var hasActiveRowIter = false
214+
var hasRowIter = false
215+
for i, v := range r {
216+
if ri, ok := v.(RowIter); ok {
217+
hasRowIter = true
218+
nv, err := ri.Next(ctx)
219+
if err == nil {
220+
hasActiveRowIter = true
221+
}
222+
if nv != nil && len(nv) > 0 {
223+
// TODO: can set returning iter return multiple values in the row?
224+
vals[i] = nv[0]
225+
}
226+
} else {
227+
vals[i] = v
228+
}
229+
}
230+
return vals, hasRowIter, !hasActiveRowIter && hasRowIter, nil
198231
}
199232

200233
func (i *sliceRowIter) Close(*Context) error {

sql/types/conversion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,11 @@ func TypeAwareConversion(ctx *sql.Context, val interface{}, originalType sql.Typ
763763
return convertedType.Convert(ctx, val)
764764
}
765765

766-
// TODO: Instead of truncating to zero, truncate strings to number prefix
767766
// ConvertOrTruncate converts the value |i| to type |t| and returns the converted value; if the value does not convert
768767
// cleanly and the type is automatically coerced (i.e. string and numeric types), then a warning is logged and the
769768
// value is truncated to the Zero value for type |t|. If the value does not convert and the type is not automatically
770769
// coerced, then return an error.
770+
// TODO: Should truncate to number prefix instead of Zero.
771771
func ConvertOrTruncate(ctx *sql.Context, i interface{}, t sql.Type) (interface{}, error) {
772772
converted, _, err := t.Convert(ctx, i)
773773
if err == nil {

0 commit comments

Comments
 (0)