Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions sql/stats/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,26 @@ func TestJoin(t *testing.T) {
}
}

func TestAlignBucketsAcceptsSystemNumberType(t *testing.T) {
Comment thread
angelamayxie marked this conversation as resolved.
Outdated
ctx := sql.NewEmptyContext()
sysIntType := types.NewSystemIntType("test_var", 0, 100, false)
h1 := sql.Histogram{
&Bucket{RowCnt: 5, DistinctCnt: 5, BoundVal: sql.Row{int64(10)}, BoundCnt: 1},
}
h2 := sql.Histogram{
&Bucket{RowCnt: 3, DistinctCnt: 3, BoundVal: sql.Row{int64(10)}, BoundCnt: 1},
}

cmp := func(i, j sql.Row) (int, error) {
return sysIntType.Compare(ctx, i[0], j[0])
}

leftAligned, rightAligned, err := AlignBuckets(h1, h2, nil, nil, []sql.Type{sysIntType}, []sql.Type{sysIntType}, cmp)
require.NoError(t, err)
require.Len(t, leftAligned, 1)
require.Len(t, rightAligned, 1)
}

func compareHist(t *testing.T, exp, cmp sql.Histogram) {
if len(exp) != len(cmp) {
t.Errorf("histograms not same length: %d != %d\n%s\n%s\n", len(exp), len(cmp), exp.DebugString(), cmp.DebugString())
Expand Down
16 changes: 16 additions & 0 deletions sql/types/system_bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type SystemBoolType struct {

var _ sql.SystemVariableType = SystemBoolType{}
var _ sql.CollationCoercible = SystemBoolType{}
var _ sql.NumberType = SystemBoolType{}

// NewSystemBoolType returns a new systemBoolType.
func NewSystemBoolType(varName string) sql.SystemVariableType {
Expand Down Expand Up @@ -184,6 +185,21 @@ func (t SystemBoolType) Zero() interface{} {
return int8(0)
}

// IsNumericType implements the sql.NumberType interface.
func (t SystemBoolType) IsNumericType() bool {
return true
}

// IsFloat implements the sql.NumberType interface.
func (t SystemBoolType) IsFloat() bool {
return false
}

// DisplayWidth implements the sql.NumberType interface.
func (t SystemBoolType) DisplayWidth() int {
return t.UnderlyingType().(sql.NumberType).DisplayWidth()
}

// EncodeValue implements SystemVariableType interface.
func (t SystemBoolType) EncodeValue(val interface{}) (string, error) {
expectedVal, ok := val.(int8)
Expand Down
16 changes: 16 additions & 0 deletions sql/types/system_double.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type systemDoubleType struct {

var _ sql.SystemVariableType = systemDoubleType{}
var _ sql.CollationCoercible = systemDoubleType{}
var _ sql.NumberType = systemDoubleType{}

// NewSystemDoubleType returns a new systemDoubleType.
func NewSystemDoubleType(varName string, lowerbound, upperbound float64) sql.SystemVariableType {
Expand Down Expand Up @@ -169,6 +170,21 @@ func (t systemDoubleType) Zero() interface{} {
return float64(0)
}

// IsNumericType implements the sql.NumberType interface.
func (t systemDoubleType) IsNumericType() bool {
return true
}

// IsFloat implements the sql.NumberType interface.
func (t systemDoubleType) IsFloat() bool {
return true
}

// DisplayWidth implements the sql.NumberType interface.
func (t systemDoubleType) DisplayWidth() int {
return t.UnderlyingType().(sql.NumberType).DisplayWidth()
}

// CollationCoercibility implements sql.CollationCoercible interface.
func (systemDoubleType) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down
16 changes: 16 additions & 0 deletions sql/types/system_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type systemIntType struct {

var _ sql.SystemVariableType = systemIntType{}
var _ sql.CollationCoercible = systemIntType{}
var _ sql.NumberType = systemIntType{}

// NewSystemIntType returns a new systemIntType.
func NewSystemIntType(varName string, lowerbound, upperbound int64, negativeOne bool) sql.SystemVariableType {
Expand Down Expand Up @@ -179,6 +180,21 @@ func (t systemIntType) Zero() interface{} {
return int64(0)
}

// IsNumericType implements the sql.NumberType interface.
func (t systemIntType) IsNumericType() bool {
return true
}

// IsFloat implements the sql.NumberType interface.
func (t systemIntType) IsFloat() bool {
return false
}

// DisplayWidth implements the sql.NumberType interface.
func (t systemIntType) DisplayWidth() int {
return t.UnderlyingType().(sql.NumberType).DisplayWidth()
}

// CollationCoercibility implements sql.CollationCoercible interface.
func (systemIntType) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down
16 changes: 16 additions & 0 deletions sql/types/system_uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type systemUintType struct {

var _ sql.SystemVariableType = systemUintType{}
var _ sql.CollationCoercible = systemUintType{}
var _ sql.NumberType = systemUintType{}

// NewSystemUintType returns a new systemUintType.
func NewSystemUintType(varName string, lowerbound, upperbound uint64) sql.SystemVariableType {
Expand Down Expand Up @@ -168,6 +169,21 @@ func (t systemUintType) Zero() interface{} {
return uint64(0)
}

// IsNumericType implements the sql.NumberType interface.
func (t systemUintType) IsNumericType() bool {
return true
}

// IsFloat implements the sql.NumberType interface.
func (t systemUintType) IsFloat() bool {
return false
}

// DisplayWidth implements the sql.NumberType interface.
func (t systemUintType) DisplayWidth() int {
return t.UnderlyingType().(sql.NumberType).DisplayWidth()
}

// CollationCoercibility implements sql.CollationCoercible interface.
func (systemUintType) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
Expand Down
14 changes: 14 additions & 0 deletions sql/types/typecheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,17 @@ func TestSystemTypesIsSet(t *testing.T) {
assert.True(t, IsSet(NewSystemSetType("", sql.Collation_Default, "")))
assert.False(t, IsSet(systemStringType{}))
}

func TestSystemTypesImplementSqlTypeInterfaces(t *testing.T) {
Comment thread
angelamayxie marked this conversation as resolved.
Outdated
assert.True(t, sql.IsNumberType(SystemBoolType{}))
assert.True(t, sql.IsNumberType(systemIntType{}))
assert.True(t, sql.IsNumberType(systemUintType{}))
assert.True(t, sql.IsNumberType(systemDoubleType{}))

assert.False(t, sql.IsNumberType(systemEnumType{}))
assert.False(t, sql.IsNumberType(systemSetType{}))
assert.False(t, sql.IsNumberType(systemStringType{}))

assert.True(t, sql.IsStringType(systemStringType{}))
assert.False(t, sql.IsStringType(SystemBoolType{}))
}