func (r *RegexpMatches) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
	span, ctx := ctx.Span("function.RegexpMatches")
	defer span.Finish()
	var re *regexp.Regexp
	var err error
	if r.cacheable {
		if r.re == nil {
			r.re, err = r.compileRegex(ctx, nil)
			if err != nil {
				return nil, err
			}
			if r.re == nil {
				return nil, nil
			}
		}
		re = r.re
	} else {
		re, err = r.compileRegex(ctx, row)
		if err != nil {
			return nil, err
		}
		if re == nil {
			return nil, nil
		}
	}
	text, err := r.Text.Eval(ctx, row)
	if err != nil {
		return nil, err
	}
	if text == nil {
		return nil, nil
	}
	text, err = sql.Text.Convert(text)
	if err != nil {
		return nil, err
	}
	matches := re.FindAllStringSubmatch(text.(string), -1)
	if len(matches) == 0 {
		return nil, nil
	}
	var result []interface{}
	for _, m := range matches {
		for _, sm := range m {
			result = append(result, sm)
		}
	}
	return result, nil
}
Eval implements the sql.Expression interface.
package function
import (
	"fmt"
	"regexp"
	"strings"
	"github.com/src-d/go-mysql-server/sql"
	"github.com/src-d/go-mysql-server/sql/expression"
	errors "gopkg.in/src-d/go-errors.v1"
)
type RegexpMatches struct {
	Text    sql.Expression
	Pattern sql.Expression
	Flags   sql.Expression
	cacheable bool
	re        *regexp.Regexp
}
func NewRegexpMatches(args ...sql.Expression) (sql.Expression, error) {
	var r RegexpMatches
	switch len(args) {
	case 3:
		r.Flags = args[2]
		fallthrough
	case 2:
		r.Text = args[0]
		r.Pattern = args[1]
	default:
		return nil, sql.ErrInvalidArgumentNumber.New("regexp_matches", "2 or 3", len(args))
	}
	if canBeCached(r.Pattern) && (r.Flags == nil || canBeCached(r.Flags)) {
		r.cacheable = true
	}
	return &r, nil
}
func (r *RegexpMatches) Type() sql.Type { return sql.Array(sql.Text) }
func (r *RegexpMatches) IsNullable() bool { return true }
func (r *RegexpMatches) Children() []sql.Expression {
	var result = []sql.Expression{r.Text, r.Pattern}
	if r.Flags != nil {
		result = append(result, r.Flags)
	}
	return result
}
func (r *RegexpMatches) Resolved() bool {
	return r.Text.Resolved() && r.Pattern.Resolved() && (r.Flags == nil || r.Flags.Resolved())
}
func (r *RegexpMatches) WithChildren(children ...sql.Expression) (sql.Expression, error) {
	required := 2
	if r.Flags != nil {
		required = 3
	}
	if len(children) != required {
		return nil, sql.ErrInvalidChildrenNumber.New(r, len(children), required)
	}
	return NewRegexpMatches(children...)
}
func (r *RegexpMatches) String() string {
	var args []string
	for _, e := range r.Children() {
		args = append(args, e.String())
	}
	return fmt.Sprintf("regexp_matches(%s)", strings.Join(args, ", "))
}