func (t setType) SQL(v interface{}) (sqltypes.Value, error) {
	if v == nil {
		return sqltypes.NULL, nil
	}
	value, err := t.Convert(v)
	if err != nil {
		return sqltypes.Value{}, err
	}
	return sqltypes.MakeTrusted(sqltypes.Set, []byte(value.(string))), nil
}
SQL implements Type interface.
package sql
import (
	"fmt"
	"math"
	"math/bits"
	"strconv"
	"strings"
	"github.com/dolthub/vitess/go/sqltypes"
	"github.com/dolthub/vitess/go/vt/proto/query"
	"gopkg.in/src-d/go-errors.v1"
)
const (
	SetTypeMaxElements = 64
)
var (
	ErrConvertingToSet   = errors.NewKind("value %v is not valid for this set")
	ErrDuplicateEntrySet = errors.NewKind("duplicate entry: %v")
	ErrInvalidSetValue   = errors.NewKind("value %v was not found in the set")
	ErrTooLargeForSet    = errors.NewKind(`value "%v" is too large for this set`)
)
type SetType interface {
	Type
	CharacterSet() CharacterSet
	Collation() Collation
	Marshal(v interface{}) (uint64, error)
	NumberOfElements() uint16
	Unmarshal(bits uint64) (string, error)
	Values() []string
}
type setType struct {
	collation         Collation
	compareToOriginal map[string]string
	valToBit          map[string]uint64
	bitToVal          map[uint64]string
}
func CreateSetType(values []string, collation Collation) (SetType, error) {
	if len(values) == 0 {
		return nil, fmt.Errorf("number of values may not be zero")
	}
	if len(values) > SetTypeMaxElements {
		return nil, fmt.Errorf("number of values is too large")
	}
	compareToOriginal := make(map[string]string)
	valToBit := make(map[string]uint64)
	bitToVal := make(map[uint64]string)
	for i, value := range values {
		if strings.Contains(value, ",") {
			return nil, fmt.Errorf("values cannot contain a comma")
		}
		switch collation.Name {
		case Collation_binary.Name:
			if _, ok := compareToOriginal[value]; ok {
				return nil, ErrDuplicateEntrySet.New(value)
			}
			compareToOriginal[value] = value
		default:
			value = strings.TrimRight(value, " ")
			lowercaseValue := strings.ToLower(value)
			if _, ok := compareToOriginal[lowercaseValue]; ok {
				return nil, ErrDuplicateEntrySet.New(value)
			}
			compareToOriginal[lowercaseValue] = value
		}
		bit := uint64(1 << uint64(i))
		valToBit[value] = bit
		bitToVal[bit] = value
	}
	return setType{
		collation:         collation,
		compareToOriginal: compareToOriginal,
		valToBit:          valToBit,
		bitToVal:          bitToVal,
	}, nil
}
func MustCreateSetType(values []string, collation Collation) SetType {
	et, err := CreateSetType(values, collation)
	if err != nil {
		panic(err)
	}
	return et
}
func (t setType) Compare(a interface{}, b interface{}) (int, error) {
	if hasNulls, res := compareNulls(a, b); hasNulls {
		return res, nil
	}
	ai, err := t.Marshal(a)
	if err != nil {
		return 0, err
	}
	bi, err := t.Marshal(b)
	if err != nil {
		return 0, err
	}
	if ai < bi {
		return -1, nil
	} else if ai > bi {
		return 1, nil
	}
	return 0, nil
}
func (t setType) Convert(v interface{}) (interface{}, error) {
	if v == nil {
		return nil, nil
	}
	switch value := v.(type) {
	case int:
		return t.Convert(uint64(value))
	case uint:
		return t.Convert(uint64(value))
	case int8:
		return t.Convert(uint64(value))
	case uint8:
		return t.Convert(uint64(value))
	case int16:
		return t.Convert(uint64(value))
	case uint16:
		return t.Convert(uint64(value))
	case int32:
		return t.Convert(uint64(value))
	case uint32:
		return t.Convert(uint64(value))
	case int64:
		return t.Convert(uint64(value))
	case uint64:
		if value <= t.allValuesBitField() {
			return t.convertBitFieldToString(value)
		}
		return nil, ErrConvertingToSet.New(v)
	case float32:
		return t.Convert(uint64(value))
	case float64:
		return t.Convert(uint64(value))
	case string:
		bitField, err := t.convertStringToBitField(value)
		if err != nil {
			return nil, err
		}
		setStr, _ := t.convertBitFieldToString(bitField)
		return setStr, nil
	case []byte:
		return t.Convert(string(value))
	}
	return nil, ErrConvertingToSet.New(v)
}
func (t setType) MustConvert(v interface{}) interface{} {
	value, err := t.Convert(v)
	if err != nil {
		panic(err)
	}
	return value
}
func (t setType) Promote() Type {
	return t
}