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
40 changes: 4 additions & 36 deletions enginetest/memory_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package enginetest_test
import (
"fmt"
"testing"
"time"

"github.com/dolthub/go-mysql-server/memory"
"github.com/dolthub/go-mysql-server/sql/expression"
Expand Down Expand Up @@ -112,45 +111,14 @@ func TestSingleScript(t *testing.T) {

var scripts = []enginetest.ScriptTest{
{
Name: "show create triggers",
Name: "UUIDs used in the wild.",
SetUpScript: []string{
"create table a (x int primary key)",
"create trigger a1 before insert on a for each row set new.x = new.x + 1",
"create table b (y int primary key)",
"create trigger b1 before insert on b for each row set new.x = new.x + 2",
"SET @uuid = '6ccd780c-baba-1026-9564-5b8c656024db'",
},
Assertions: []enginetest.ScriptTestAssertion{
{
Query: "show create trigger a1",
Expected: []sql.Row{
{
"a1", // Trigger
"", // sql_mode
"create trigger a1 before insert on a for each row set new.x = new.x + 1", // SQL Original Statement
sql.Collation_Default.CharacterSet().String(), // character_set_client
sql.Collation_Default.String(), // collation_connection
sql.Collation_Default.String(), // Database Collation
time.Unix(0, 0).UTC(), // Created
},
},
},
{
Query: "show create trigger b1",
Expected: []sql.Row{
{
"b1", // Trigger
"", // sql_mode
"create trigger b1 before insert on b for each row set new.x = new.x + 2", // SQL Original Statement
sql.Collation_Default.CharacterSet().String(), // character_set_client
sql.Collation_Default.String(), // collation_connection
sql.Collation_Default.String(), // Database Collation
time.Unix(0, 0).UTC(), // Created
},
},
},
{
Query: "show create trigger b2",
ExpectedErr: sql.ErrTriggerDoesNotExist,
Query: `SELECT IS_UUID(@uuid)`,
Expected: []sql.Row{{int8(1)}},
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions enginetest/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ var QueryTests = []QueryTest{
{1, 50.0},
},
},
{
Query: "select max(pk),c2 from one_pk group by c1 order by 1",
Expected: []sql.Row{{0, 1}, {1, 11}, {2, 21}, {3, 31}},
},
{
Query: "SELECT pk1, SUM(c1) FROM two_pk WHERE pk1 = 0",
Expected: []sql.Row{{0, 10.0}},
Expand Down
53 changes: 53 additions & 0 deletions enginetest/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,59 @@ var ScriptTests = []ScriptTest{
},
},
},
{
Name: "UUIDs used in the wild.",
SetUpScript: []string{
"SET @uuid = '6ccd780c-baba-1026-9564-5b8c656024db'",
"SET @binuuid = '0011223344556677'",
},
Assertions: []ScriptTestAssertion{
{
Query: `SELECT IS_UUID(UUID())`,
Expected: []sql.Row{{int8(1)}},
},
{
Query: `SELECT IS_UUID(@uuid)`,
Expected: []sql.Row{{int8(1)}},
},
{
Query: `SELECT BIN_TO_UUID(UUID_TO_BIN(@uuid))`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a test for accepting byte arrays as well. In MySQL this is valid:
SELECT BIN_TO_UUID(X'00112233445566778899aabbccddeeff');
But we don't have a way to represent those directly, so a byte array would work as a substitution.

Also, we need raw string input.
SELECT BIN_TO_UUID('0011223344556677'); is also valid, which we would just take the string bytes as a byte array.

Expected: []sql.Row{{"6ccd780c-baba-1026-9564-5b8c656024db"}},
},
{
Query: `SELECT BIN_TO_UUID(UUID_TO_BIN(@uuid, 1), 1)`,
Expected: []sql.Row{{"6ccd780c-baba-1026-9564-5b8c656024db"}},
},
{
Query: `SELECT UUID_TO_BIN(NULL)`,
Expected: []sql.Row{{nil}},
},
{
Query: `SELECT HEX(UUID_TO_BIN(@uuid))`,
Expected: []sql.Row{{"6CCD780CBABA102695645B8C656024DB"}},
},
{
Query: `SELECT UUID_TO_BIN(123)`,
RequiredErr: true,
},
{
Query: `SELECT BIN_TO_UUID(123)`,
RequiredErr: true,
},
{
Query: `SELECT BIN_TO_UUID(X'00112233445566778899aabbccddeeff')`,
Expected: []sql.Row{{"00112233-4455-6677-8899-aabbccddeeff"}},
},
{
Query: `SELECT BIN_TO_UUID('0011223344556677')`,
Expected: []sql.Row{{"30303131-3232-3333-3434-353536363737"}},
},
{
Query: `SELECT BIN_TO_UUID(@binuuid)`,
Expected: []sql.Row{{"30303131-3232-3333-3434-353536363737"}},
},
},
},
{
Name: "CrossDB Queries",
SetUpScript: []string{
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/go-sql-driver/mysql v1.4.1
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/google/go-cmp v0.3.0 // indirect
github.com/google/uuid v1.2.0
github.com/hashicorp/golang-lru v0.5.3
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk=
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
Expand Down
8 changes: 6 additions & 2 deletions sql/expression/function/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var Defaults = []sql.Function{
sql.Function1{Name: "atan", Fn: NewAtan},
sql.Function1{Name: "avg", Fn: func(e sql.Expression) sql.Expression { return aggregation.NewAvg(e) }},
sql.Function1{Name: "bin", Fn: NewBin},
sql.FunctionN{Name: "bin_to_uuid", Fn: NewBinToUUID},
sql.Function1{Name: "bit_length", Fn: NewBitlength},
sql.Function1{Name: "ceil", Fn: NewCeil},
sql.Function1{Name: "ceiling", Fn: NewCeil},
Expand Down Expand Up @@ -74,6 +75,7 @@ var Defaults = []sql.Function{
sql.Function2{Name: "ifnull", Fn: NewIfNull},
sql.Function2{Name: "instr", Fn: NewInstr},
sql.Function1{Name: "is_binary", Fn: NewIsBinary},
sql.Function1{Name: "is_uuid", Fn: NewIsUUID},
sql.FunctionN{Name: "json_array", Fn: NewJSONArray},
sql.Function1{Name: "json_arrayagg", Fn: func(e sql.Expression) sql.Expression { return aggregation.NewJSONArrayAgg(e) }},
sql.FunctionN{Name: "json_array_append", Fn: NewJSONArrayAppend},
Expand Down Expand Up @@ -154,16 +156,18 @@ var Defaults = []sql.Function{
sql.Function1{Name: "sum", Fn: func(e sql.Expression) sql.Expression { return aggregation.NewSum(e) }},
sql.Function1{Name: "tan", Fn: NewTan},
sql.Function1{Name: "time_to_sec", Fn: NewTimeToSec},
sql.Function2{Name: "timediff", Fn: NewTimeDiff},
sql.FunctionN{Name: "timestamp", Fn: NewTimestamp},
sql.Function1{Name: "to_base64", Fn: NewToBase64},
sql.Function1{Name: "trim", Fn: NewTrimFunc(bTrimType)},
sql.Function1{Name: "ucase", Fn: NewUpper},
sql.Function1{Name: "unhex", Fn: NewUnhex},
sql.FunctionN{Name: "unix_timestamp", Fn: NewUnixTimestamp},
sql.FunctionN{Name: "utc_timestamp", Fn: NewUTCTimestamp},
sql.Function2{Name: "timediff", Fn: NewTimeDiff},
sql.Function1{Name: "upper", Fn: NewUpper},
sql.NewFunction0("user", NewUser),
sql.FunctionN{Name: "utc_timestamp", Fn: NewUTCTimestamp},
sql.Function0{Name: "uuid", Fn: NewUUIDFunc},
sql.FunctionN{Name: "uuid_to_bin", Fn: NewUUIDToBin},
sql.FunctionN{Name: "week", Fn: NewWeek},
sql.Function1{Name: "values", Fn: NewValues},
sql.Function1{Name: "weekday", Fn: NewWeekday},
Expand Down
Loading