Skip to content

Commit

Permalink
Merge branch 'main' into max/move-join-indexing-after-all
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman committed Sep 13, 2023
2 parents f0842a2 + 0324aff commit 6c43865
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e
github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
github.com/dolthub/vitess v0.0.0-20230912171821-e75546482eaf
github.com/dolthub/vitess v0.0.0-20230913054107-012908e18312
github.com/go-kit/kit v0.10.0
github.com/go-sql-driver/mysql v1.6.0
github.com/gocraft/dbr/v2 v2.7.2
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ github.com/dolthub/vitess v0.0.0-20230823204737-4a21a94e90c3 h1:lY3oQbYNMSVjT02n
github.com/dolthub/vitess v0.0.0-20230823204737-4a21a94e90c3/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20230912171821-e75546482eaf h1:nCfUfJMtx/07TSCqVlBxUEtYoF9TaBc/SYiYrq6pIak=
github.com/dolthub/vitess v0.0.0-20230912171821-e75546482eaf/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20230912231930-45d600cef638 h1:b8AQsuMLfp/CyuqOUfAevfMnGzrFMktTLGGWvfrkBz4=
github.com/dolthub/vitess v0.0.0-20230912231930-45d600cef638/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20230913054107-012908e18312 h1:fpioxxt684JPVpmFH2b3Y520AdnFUKNX12CkyrqU+OY=
github.com/dolthub/vitess v0.0.0-20230913054107-012908e18312/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
Expand Down
4 changes: 2 additions & 2 deletions sql/types/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func ColumnTypeToType(ct *sqlparser.ColumnType) (sql.Type, error) {
}
}
return CreateString(sqltypes.Char, length, sql.Collation_utf8mb3_general_ci)
case "varchar", "character varying":
case "varchar", "char varying", "character varying":
collation, err := sql.ParseCollation(&ct.Charset, &ct.Collate, ct.BinaryCollate)
if err != nil {
return nil, err
Expand All @@ -281,7 +281,7 @@ func ColumnTypeToType(ct *sqlparser.ColumnType) (sql.Type, error) {
}
}
return CreateString(sqltypes.VarChar, length, collation)
case "nvarchar", "national varchar", "national character varying":
case "nchar varchar", "nchar varying", "nvarchar", "national varchar", "national char varying", "national character varying":
if ct.Length == nil {
return nil, fmt.Errorf("VARCHAR requires a length")
}
Expand Down
42 changes: 42 additions & 0 deletions sql/types/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"testing"

"github.com/dolthub/vitess/go/sqltypes"
"github.com/dolthub/vitess/go/vt/sqlparser"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -116,3 +117,44 @@ func TestColumnTypeToType_Time(t *testing.T) {
})
}
}

func TestColumnCharTypes(t *testing.T) {
test := []struct {
typ string
len int64
exp sql.Type
}{
{
typ: "nchar varchar",
len: 10,
exp: StringType{baseType: sqltypes.VarChar, maxCharLength: 10, maxByteLength: 30, collation: 33},
},
{
typ: "char varying",
len: 10,
exp: StringType{baseType: sqltypes.VarChar, maxCharLength: 10, maxByteLength: 40},
},
{
typ: "nchar varying",
len: 10,
exp: StringType{baseType: sqltypes.VarChar, maxCharLength: 10, maxByteLength: 30, collation: 33},
},
{
typ: "national char varying",
len: 10,
exp: StringType{baseType: sqltypes.VarChar, maxCharLength: 10, maxByteLength: 30, collation: 33},
},
}

for _, test := range test {
t.Run(fmt.Sprintf("%v %v", test.typ, test.exp), func(t *testing.T) {
ct := &sqlparser.ColumnType{
Type: test.typ,
Length: &sqlparser.SQLVal{Type: sqlparser.IntVal, Val: []byte(fmt.Sprintf("%v", test.len))},
}
res, err := ColumnTypeToType(ct)
assert.NoError(t, err)
assert.Equal(t, test.exp, res)
})
}
}

0 comments on commit 6c43865

Please sign in to comment.