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
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
37 changes: 37 additions & 0 deletions sql/types/system_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/dolthub/go-mysql-server/sql"
)

func TestSystemTypesImplementSqlTypeInterfaces(t *testing.T) {
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{}))
}
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