Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions sql/expression/tablefunction/table_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (t *TableFunctionWrapper) Expressions() []sql.Expression {
if t.funcExpr == nil {
return nil
}
return t.funcExpr.Children()
return []sql.Expression{t.funcExpr}
}

func (t *TableFunctionWrapper) IsReadOnly() bool {
Expand Down Expand Up @@ -130,15 +130,10 @@ func (t *TableFunctionWrapper) WithExpressions(exprs ...sql.Expression) (sql.Nod
return nil, sql.ErrInvalidChildrenNumber.New(t, len(exprs), 0)
}
}
l := len(t.funcExpr.Children())
if len(exprs) != l {
return nil, sql.ErrInvalidChildrenNumber.New(t, len(exprs), l)
if len(exprs) != 1 {
return nil, sql.ErrInvalidChildrenNumber.New(t, len(exprs), 1)
}
nt := *t
nf, err := nt.funcExpr.WithChildren(exprs...)
if err != nil {
return nil, err
}
nt.funcExpr = nf
nt.funcExpr = exprs[0]
return &nt, nil
}
2 changes: 1 addition & 1 deletion sql/plan/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewValues(tuples [][]sql.Expression) *Values {
return &Values{ExpressionTuples: tuples}
}

// NewValuesWithAliasName creates a Values node with the given row and column aliases.
// NewValuesWithAlias creates a Values node with the given row and column aliases.
func NewValuesWithAlias(tableName string, columnNames map[string]string, tuples [][]sql.Expression) *Values {
return &Values{ExpressionTuples: tuples, AliasName: tableName, ColumnNames: columnNames}
}
Expand Down
41 changes: 37 additions & 4 deletions sql/rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,47 @@ type sliceRowIter struct {
idx int
}

func (i *sliceRowIter) Next(*Context) (Row, error) {
func (i *sliceRowIter) Next(ctx *Context) (Row, error) {
if i.idx >= len(i.rows) {
return nil, io.EOF
}

r := i.rows[i.idx]
i.idx++
return r.Copy(), nil
vals, hasRowIter, rowIterEnded, err := unwrapRowIterAsReturnedResult(ctx, i.rows[i.idx])
if err != nil {
return nil, err
}

if !hasRowIter {
i.idx++
} else if rowIterEnded {
return nil, io.EOF
}

return NewRow(vals...), nil
}

// unwrapRowIterAsReturnedResult unwraps the row if there is any RowIter in the given Row
// creating multiple Rows from a single Row.
func unwrapRowIterAsReturnedResult(ctx *Context, r Row) ([]any, bool, bool, error) {
vals := make([]interface{}, len(r))
var hasActiveRowIter = false
var hasRowIter = false
for i, v := range r {
if ri, ok := v.(RowIter); ok {
hasRowIter = true
nv, err := ri.Next(ctx)
if err == nil {
hasActiveRowIter = true
}
if nv != nil && len(nv) > 0 {
// TODO: can set returning iter return multiple values in the row?
vals[i] = nv[0]
}
} else {
vals[i] = v
}
}
return vals, hasRowIter, !hasActiveRowIter && hasRowIter, nil
}

func (i *sliceRowIter) Close(*Context) error {
Expand Down
Loading