func (ub UUIDToBin) Children() []sql.Expression {
	if ub.swapFlag == nil {
		return []sql.Expression{ub.inputUUID}
	}
	return []sql.Expression{ub.inputUUID, ub.swapFlag}
}
Children returns the children expressions of this expression.
package function
import (
	"fmt"
	"github.com/dolthub/vitess/go/sqltypes"
	"github.com/dolthub/vitess/go/vt/proto/query"
	"github.com/google/uuid"
	"github.com/dolthub/go-mysql-server/sql"
)
type UUIDFunc struct{}
var _ sql.FunctionExpression = &UUIDFunc{}
func NewUUIDFunc() sql.Expression {
	return UUIDFunc{}
}
func (u UUIDFunc) String() string {
	return "UUID()"
}
func (u UUIDFunc) Type() sql.Type {
	return sql.MustCreateStringWithDefaults(sqltypes.VarChar, 36)
}
func (u UUIDFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
	nUUID, err := uuid.NewUUID()
	if err != nil {
		return nil, err
	}
	return nUUID.String(), nil
}
func (u UUIDFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) {
	if len(children) != 0 {
		return nil, sql.ErrInvalidChildrenNumber.New(u, len(children), 0)
	}
	return UUIDFunc{}, nil
}
func (u UUIDFunc) FunctionName() string {
	return "uuid"
}
func (u UUIDFunc) Resolved() bool {
	return true
}
func (u UUIDFunc) Children() []sql.Expression {
	return nil
}
func (u UUIDFunc) IsNullable() bool {
	return false
}
type IsUUID struct {
	child sql.Expression
}
var _ sql.FunctionExpression = &IsUUID{}
func NewIsUUID(arg sql.Expression) sql.Expression {
	return IsUUID{child: arg}
}
func (u IsUUID) String() string {
	return fmt.Sprintf("IS_UUID(%s)", u.child)
}
func (u IsUUID) Type() sql.Type {
	return sql.Int8
}
func (u IsUUID) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
	str, err := u.child.Eval(ctx, row)
	if err != nil {
		return 0, err
	}
	if str == nil {
		return nil, nil
	}
	switch str := str.(type) {
	case string:
		_, err := uuid.Parse(str)
		if err != nil {
			return int8(0), nil
		}
		return int8(1), nil
	case []byte:
		_, err := uuid.ParseBytes(str)
		if err != nil {
			return int8(0), nil
		}
		return int8(1), nil
	default:
		return int8(0), nil
	}
}
func (u IsUUID) WithChildren(children ...sql.Expression) (sql.Expression, error) {
	if len(children) != 1 {
		return nil, sql.ErrInvalidChildrenNumber.New(u, len(children), 1)
	}
	return IsUUID{child: children[0]}, nil
}
func (u IsUUID) FunctionName() string {
	return "is_uuid"
}
func (u IsUUID) Resolved() bool {
	return u.child.Resolved()
}
func (u IsUUID) Children() []sql.Expression {
	return []sql.Expression{u.child}
}
func (u IsUUID) IsNullable() bool {
	return false
}
type UUIDToBin struct {
	inputUUID sql.Expression
	swapFlag  sql.Expression
}
var _ sql.FunctionExpression = (*UUIDToBin)(nil)
func NewUUIDToBin(args ...sql.Expression) (sql.Expression, error) {
	switch len(args) {
	case 1:
		return UUIDToBin{inputUUID: args[0]}, nil
	case 2:
		return UUIDToBin{inputUUID: args[0], swapFlag: args[1]}, nil
	default:
		return nil, sql.ErrInvalidArgumentNumber.New("UUID_TO_BIN", "1 or 2", len(args))
	}
}
func (ub UUIDToBin) String() string {
	if ub.swapFlag != nil {
		return fmt.Sprintf("UUID_TO_BIN(%s, %s)", ub.inputUUID, ub.swapFlag)
	} else {
		return fmt.Sprintf("UUID_TO_BIN(%s)", ub.inputUUID)
	}
}
func (ub UUIDToBin) Type() sql.Type {
	return sql.MustCreateBinary(query.Type_VARBINARY, int64(16))
}
func (ub UUIDToBin) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
	str, err := ub.inputUUID.Eval(ctx, row)
	if err != nil {
		return 0, err
	}
	converted, err := sql.LongText.Convert(str)
	if err != nil {
		return nil, err
	}
	if converted == nil {
		return nil, nil
	}
	uuidAsStr, ok := converted.(string)
	if !ok {
		return nil, fmt.Errorf("invalid data format passed to UUID_TO_BIN")
	}
	parsed, err := uuid.Parse(uuidAsStr)
	if err != nil {
		return nil, sql.ErrUuidUnableToParse.New(uuidAsStr, err.Error())
	}
	if ub.swapFlag == nil {
		bt, err := parsed.MarshalBinary()
		if err != nil {
			return nil, err
		}
		return string(bt), nil
	}
	sf, err := ub.swapFlag.Eval(ctx, row)
	if err != nil {
		return nil, err
	}
	sf, err = sql.Int8.Convert(sf)
	if err != nil {
		return nil, err
	}
	if sf == nil || sf.(int8) == 0 {
		bt, err := parsed.MarshalBinary()
		if err != nil {
			return nil, err
		}
		return string(bt), nil
	} else if sf.(int8) == 1 {
		encoding := swapUUIDBytes(parsed)
		return string(encoding), nil
	} else {
		return nil, fmt.Errorf("UUID_TO_BIN received invalid swap flag")
	}
}
func swapUUIDBytes(cur uuid.UUID) []byte {
	ret := make([]byte, 16)
	copy(ret[0:2], cur[6:8])
	copy(ret[2:4], cur[4:6])
	copy(ret[4:8], cur[0:4])
	copy(ret[8:], cur[8:])
	return ret
}
func (ub UUIDToBin) WithChildren(children ...sql.Expression) (sql.Expression, error) {
	return NewUUIDToBin(children...)
}
func (ub UUIDToBin) FunctionName() string {
	return "uuid_to_bin"
}
func (ub UUIDToBin) Resolved() bool {
	return ub.inputUUID.Resolved()
}