Skip to content

Commit

Permalink
Keywords must be unique and can't be reused (#12044)
Browse files Browse the repository at this point in the history
In #12009 I added aliases for
float4 / float8 but that was done wrongly. We can't alias these with the
same keyword, or we break functions like SQLTypeToQueryType because we
only have one version of it in the keywords list.

Signed-off-by: Dirkjan Bussink <[email protected]>

Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink authored Jan 9, 2023
1 parent d8f1788 commit a278e6b
Show file tree
Hide file tree
Showing 5 changed files with 7,786 additions and 7,709 deletions.
4 changes: 2 additions & 2 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ func SQLTypeToQueryType(typeName string, unsigned bool) querypb.Type {
return sqltypes.Timestamp
case YEAR:
return sqltypes.Year
case FLOAT_TYPE:
case FLOAT_TYPE, FLOAT4_TYPE:
return sqltypes.Float32
case DOUBLE:
case DOUBLE, FLOAT8_TYPE:
return sqltypes.Float64
case DECIMAL, DECIMAL_TYPE:
return sqltypes.Decimal
Expand Down
53 changes: 53 additions & 0 deletions go/vt/sqlparser/ast_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/sqltypes"
querypb "vitess.io/vitess/go/vt/proto/query"
)

func TestAddQueryHint(t *testing.T) {
Expand Down Expand Up @@ -81,3 +84,53 @@ func TestAddQueryHint(t *testing.T) {
})
}
}

func TestSQLTypeToQueryType(t *testing.T) {
tcs := []struct {
input string
unsigned bool
output querypb.Type
}{
{
input: "tinyint",
unsigned: true,
output: sqltypes.Uint8,
},
{
input: "tinyint",
unsigned: false,
output: sqltypes.Int8,
},
{
input: "double",
output: sqltypes.Float64,
},
{
input: "float8",
output: sqltypes.Float64,
},
{
input: "float",
output: sqltypes.Float32,
},
{
input: "float4",
output: sqltypes.Float32,
},
{
input: "decimal",
output: sqltypes.Decimal,
},
}

for _, tc := range tcs {
name := tc.input
if tc.unsigned {
name += " unsigned"
}
t.Run(name, func(t *testing.T) {
got := SQLTypeToQueryType(tc.input, tc.unsigned)
require.Equal(t, tc.output, got)
})
}
}
4 changes: 2 additions & 2 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ var keywords = []keyword{
{"first_value", FIRST_VALUE},
{"fixed", FIXED},
{"float", FLOAT_TYPE},
{"float4", FLOAT_TYPE},
{"float8", DOUBLE},
{"float4", FLOAT4_TYPE},
{"float8", FLOAT8_TYPE},
{"flush", FLUSH},
{"following", FOLLOWING},
{"for", FOR},
Expand Down
Loading

0 comments on commit a278e6b

Please sign in to comment.