From 4e5033ac52b44124a88425164c45053e542ab72e Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Wed, 29 Nov 2023 11:25:40 -0800 Subject: [PATCH 01/14] Bug fix for ALL keyword on function calls --- server/ast/func_expr.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/ast/func_expr.go b/server/ast/func_expr.go index 5064cb1d7e..beb171c99a 100644 --- a/server/ast/func_expr.go +++ b/server/ast/func_expr.go @@ -54,12 +54,12 @@ func nodeFuncExpr(node *tree.FuncExpr) (*vitess.FuncExpr, error) { } var distinct bool switch node.Type { - case 0: + case 0, tree.AllFuncType: distinct = false case tree.DistinctFuncType: distinct = true - case tree.AllFuncType: - return nil, fmt.Errorf("function spec is not yet supported") + default: + return nil, fmt.Errorf("unknown function spec type %d", node.Type) } windowDef, err := nodeWindowDef(node.WindowDef) if err != nil { From e5d343550ad4550a53502aa04298c031555a895c Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Wed, 29 Nov 2023 11:40:04 -0800 Subject: [PATCH 02/14] Implemented NULLIF --- server/ast/expr.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/server/ast/expr.go b/server/ast/expr.go index 220ea2b468..3f196cbb36 100644 --- a/server/ast/expr.go +++ b/server/ast/expr.go @@ -405,8 +405,37 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) { Expr: expr, }, nil case *tree.NullIfExpr: - //TODO: probably should be the IF function: IF(Expr1 == Expr2, NULL, Expr1) - return nil, fmt.Errorf("NULLIF is not yet supported") + expr1, err := nodeExpr(node.Expr1) + if err != nil { + return nil, err + } + + expr2, err := nodeExpr(node.Expr2) + if err != nil { + return nil, err + } + + selectExpr1, err := nodeExprToSelectExpr(node.Expr1) + if err != nil { + return nil, err + } + + return &vitess.FuncExpr{ + Name: vitess.NewColIdent("IF"), + Exprs: vitess.SelectExprs{ + &vitess.AliasedExpr{ + Expr: &vitess.ComparisonExpr{ + Operator: vitess.EqualStr, + Left: expr1, + Right: expr2, + }, + }, + &vitess.AliasedExpr{ + Expr: &vitess.NullVal{}, + }, + selectExpr1, + }, + }, nil case tree.NullLiteral: return &vitess.NullVal{}, nil case *tree.NumVal: From 4b08b8d9cd45ce30d04c54b655f8915ee973cb0e Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Wed, 29 Nov 2023 11:49:20 -0800 Subject: [PATCH 03/14] Implemented COALESCE --- server/ast/expr.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/ast/expr.go b/server/ast/expr.go index 3f196cbb36..3b7fa884fb 100644 --- a/server/ast/expr.go +++ b/server/ast/expr.go @@ -215,7 +215,15 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) { }, }, nil case *tree.CoalesceExpr: - return nil, fmt.Errorf("COALESCE is not yet supported") + exprs, err := nodeExprsToSelectExprs(node.Exprs) + if err != nil { + return nil, err + } + + return &vitess.FuncExpr{ + Name: vitess.NewColIdent("COALESCE"), + Exprs: exprs, + }, nil case *tree.CollateExpr: return nil, fmt.Errorf("collations are not yet supported") case *tree.ColumnAccessExpr: From b1048c3b10b6ae99db451bd4bfa173539a9263a0 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Wed, 29 Nov 2023 12:00:29 -0800 Subject: [PATCH 04/14] Support for cross joins --- server/ast/table_expr.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/ast/table_expr.go b/server/ast/table_expr.go index b8ef6c4a75..450c3b8b5d 100644 --- a/server/ast/table_expr.go +++ b/server/ast/table_expr.go @@ -51,6 +51,8 @@ func nodeTableExpr(node tree.TableExpr) (vitess.TableExpr, error) { for i := range treeCondition.Cols { condition.Using[i] = vitess.NewColIdent(string(treeCondition.Cols[i])) } + case nil: + // cross join (no join condition) default: return nil, fmt.Errorf("unknown JOIN condition: `%T`", treeCondition) } @@ -70,10 +72,7 @@ func nodeTableExpr(node tree.TableExpr) (vitess.TableExpr, error) { } else { joinType = vitess.RightJoinStr } - case tree.AstCross: - // GMS doesn't have any support for CROSS joins, as MySQL doesn't actually implement them - return nil, fmt.Errorf("CROSS joins are not yet supported") - case tree.AstInner: + case tree.AstCross, tree.AstInner: joinType = vitess.JoinStr case "": if condition.On == nil && len(condition.Using) == 0 { From dd3acf5eb1a918526afb8e1febba618808c8a2c9 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Wed, 29 Nov 2023 12:16:36 -0800 Subject: [PATCH 05/14] Better error message for describe problems --- postgres/messages/row_description.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/postgres/messages/row_description.go b/postgres/messages/row_description.go index ee8b1b981d..27ff07d36e 100644 --- a/postgres/messages/row_description.go +++ b/postgres/messages/row_description.go @@ -175,7 +175,7 @@ func VitessFieldToDataTypeObjectID(field *query.Field) (int32, error) { case query.Type_DATE: return 1082, nil default: - return 0, fmt.Errorf("unsupported type returned from engine") + return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) } } @@ -211,8 +211,8 @@ func VitessFieldToDataTypeSize(field *query.Field) (int16, error) { case query.Type_DATE: return 4, nil default: - return 0, fmt.Errorf("unsupported type returned from engine") - } + return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) + } } // VitessFieldToDataTypeModifier returns the field's data type modifier as defined by Postgres. @@ -256,6 +256,6 @@ func VitessFieldToDataTypeModifier(field *query.Field) (int32, error) { case query.Type_DATE: return -1, nil default: - return 0, fmt.Errorf("unsupported type returned from engine") + return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) } } From 982e28360e3b3738ebb2dbed5d5cd1d154e2ead1 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Wed, 29 Nov 2023 15:57:12 -0800 Subject: [PATCH 06/14] Handling for NULL return values, simpler NULLIF implementation --- postgres/messages/row_description.go | 6 +++++ server/ast/expr.go | 25 +++---------------- testing/logictest/harness/doltgres_harness.go | 4 +++ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/postgres/messages/row_description.go b/postgres/messages/row_description.go index 27ff07d36e..8bb40a8af4 100644 --- a/postgres/messages/row_description.go +++ b/postgres/messages/row_description.go @@ -174,6 +174,8 @@ func VitessFieldToDataTypeObjectID(field *query.Field) (int32, error) { return 1114, nil case query.Type_DATE: return 1082, nil + case query.Type_NULL_TYPE: + return 705, nil // unknown type default: return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) } @@ -210,6 +212,8 @@ func VitessFieldToDataTypeSize(field *query.Field) (int16, error) { return 8, nil case query.Type_DATE: return 4, nil + case query.Type_NULL_TYPE: + return -2, nil // unknown type default: return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) } @@ -255,6 +259,8 @@ func VitessFieldToDataTypeModifier(field *query.Field) (int32, error) { return -1, nil case query.Type_DATE: return -1, nil + case query.Type_NULL_TYPE: + return -1, nil // unknown type default: return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) } diff --git a/server/ast/expr.go b/server/ast/expr.go index 3b7fa884fb..826ec6af2a 100644 --- a/server/ast/expr.go +++ b/server/ast/expr.go @@ -413,36 +413,19 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) { Expr: expr, }, nil case *tree.NullIfExpr: - expr1, err := nodeExpr(node.Expr1) + expr1, err := nodeExprToSelectExpr(node.Expr1) if err != nil { return nil, err } - expr2, err := nodeExpr(node.Expr2) + expr2, err := nodeExprToSelectExpr(node.Expr2) if err != nil { return nil, err } - selectExpr1, err := nodeExprToSelectExpr(node.Expr1) - if err != nil { - return nil, err - } - return &vitess.FuncExpr{ - Name: vitess.NewColIdent("IF"), - Exprs: vitess.SelectExprs{ - &vitess.AliasedExpr{ - Expr: &vitess.ComparisonExpr{ - Operator: vitess.EqualStr, - Left: expr1, - Right: expr2, - }, - }, - &vitess.AliasedExpr{ - Expr: &vitess.NullVal{}, - }, - selectExpr1, - }, + Name: vitess.NewColIdent("NULLIF"), + Exprs: vitess.SelectExprs{expr1, expr2}, }, nil case tree.NullLiteral: return &vitess.NullVal{}, nil diff --git a/testing/logictest/harness/doltgres_harness.go b/testing/logictest/harness/doltgres_harness.go index 9f0fcc1646..f2ce6ea6d6 100755 --- a/testing/logictest/harness/doltgres_harness.go +++ b/testing/logictest/harness/doltgres_harness.go @@ -238,6 +238,10 @@ func columns(rows *sql.Rows) (string, []interface{}, error) { colVal := sql.NullInt64{} columns = append(columns, &colVal) sb.WriteString("I") + case "UNKNOWN": // used for NULL values + colVal := sql.NullString{} + columns = append(columns, &colVal) + sb.WriteString("I") // is this right? default: return "", nil, fmt.Errorf("Unhandled type %s", columnType.DatabaseTypeName()) } From b3b27e28cd1b42b969aa4b6338566316814df25a Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Thu, 30 Nov 2023 14:53:35 -0800 Subject: [PATCH 07/14] Fixed the type of NULL to match postgres wire results --- postgres/messages/row_description.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/postgres/messages/row_description.go b/postgres/messages/row_description.go index 8bb40a8af4..9429fddeae 100644 --- a/postgres/messages/row_description.go +++ b/postgres/messages/row_description.go @@ -175,7 +175,7 @@ func VitessFieldToDataTypeObjectID(field *query.Field) (int32, error) { case query.Type_DATE: return 1082, nil case query.Type_NULL_TYPE: - return 705, nil // unknown type + return 25, nil // NULL is treated as TEXT on the wire default: return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) } @@ -213,7 +213,7 @@ func VitessFieldToDataTypeSize(field *query.Field) (int16, error) { case query.Type_DATE: return 4, nil case query.Type_NULL_TYPE: - return -2, nil // unknown type + return -1, nil // NULL is treated as TEXT on the wire default: return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) } @@ -260,7 +260,7 @@ func VitessFieldToDataTypeModifier(field *query.Field) (int32, error) { case query.Type_DATE: return -1, nil case query.Type_NULL_TYPE: - return -1, nil // unknown type + return -1, nil // NULL is treated as TEXT on the wire default: return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) } From f3a7ebcc46dadf7e84284ea2eb0873774f973741 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Thu, 30 Nov 2023 14:54:59 -0800 Subject: [PATCH 08/14] Formatting --- postgres/messages/row_description.go | 2 +- server/ast/expr.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/postgres/messages/row_description.go b/postgres/messages/row_description.go index 9429fddeae..e862c9f711 100644 --- a/postgres/messages/row_description.go +++ b/postgres/messages/row_description.go @@ -216,7 +216,7 @@ func VitessFieldToDataTypeSize(field *query.Field) (int16, error) { return -1, nil // NULL is treated as TEXT on the wire default: return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type) - } + } } // VitessFieldToDataTypeModifier returns the field's data type modifier as defined by Postgres. diff --git a/server/ast/expr.go b/server/ast/expr.go index 826ec6af2a..26cc818bd3 100644 --- a/server/ast/expr.go +++ b/server/ast/expr.go @@ -219,7 +219,7 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) { if err != nil { return nil, err } - + return &vitess.FuncExpr{ Name: vitess.NewColIdent("COALESCE"), Exprs: exprs, @@ -424,8 +424,8 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) { } return &vitess.FuncExpr{ - Name: vitess.NewColIdent("NULLIF"), - Exprs: vitess.SelectExprs{expr1, expr2}, + Name: vitess.NewColIdent("NULLIF"), + Exprs: vitess.SelectExprs{expr1, expr2}, }, nil case tree.NullLiteral: return &vitess.NullVal{}, nil From 2948b52988943449f6852f74e753f61e06575c52 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Thu, 30 Nov 2023 14:56:09 -0800 Subject: [PATCH 09/14] Latest dolt and gms --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 0bad8cc603..6b854279ce 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.21 require ( github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a github.com/cockroachdb/errors v1.7.5 - github.com/dolthub/dolt/go v0.40.5-0.20231114163244-0cc42b844045 - github.com/dolthub/go-mysql-server v0.17.1-0.20231113191556-2da061871eb8 + github.com/dolthub/dolt/go v0.40.5-0.20231130221002-0d5eeb513092 + github.com/dolthub/go-mysql-server v0.17.1-0.20231130181846-c0a0060c4fe7 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20231109003730-c0fa018b5ef6 + github.com/dolthub/vitess v0.0.0-20231127171856-2466012fb61f github.com/fatih/color v1.13.0 github.com/gogo/protobuf v1.3.2 github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35 @@ -19,6 +19,7 @@ require ( github.com/lib/pq v1.10.2 github.com/madflojo/testcerts v1.1.1 github.com/pierrre/geohash v1.0.0 + github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.8.2 github.com/tidwall/gjson v1.14.4 github.com/twpayne/go-geom v1.3.6 @@ -109,7 +110,6 @@ require ( github.com/sergi/go-diff v1.1.0 // indirect github.com/shopspring/decimal v1.2.0 // indirect github.com/silvasur/buzhash v0.0.0-20160816060738-9bdec3dec7c6 // indirect - github.com/sirupsen/logrus v1.8.1 // indirect github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect github.com/tealeg/xlsx v1.0.5 // indirect github.com/tetratelabs/wazero v1.1.0 // indirect diff --git a/go.sum b/go.sum index e8e0d647e5..6725746adf 100644 --- a/go.sum +++ b/go.sum @@ -212,8 +212,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dolthub/dolt/go v0.40.5-0.20231114163244-0cc42b844045 h1:3XcJEPd9hydNGegfDC95b+PJWvzJrqU0serxh5Bo9Qw= -github.com/dolthub/dolt/go v0.40.5-0.20231114163244-0cc42b844045/go.mod h1:CAA/kBFxZdT8s3aLtLUw3gEsuxSOVeChlQucDlZCTBU= +github.com/dolthub/dolt/go v0.40.5-0.20231130221002-0d5eeb513092 h1:DvCGM7uxHtNe8b6C2vpX71oFhhHf1KoXeb+/y8wBkt8= +github.com/dolthub/dolt/go v0.40.5-0.20231130221002-0d5eeb513092/go.mod h1:PVPL+qOhr6+DPUW0QyHTvoTd0AbYBIRd7Y4ITrhi97s= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20231018220650-48f565111c6a h1:WYBHmrFuKPqPfLB8ab1WqL5MgR8PQICkfUs5RTjHZM8= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20231018220650-48f565111c6a/go.mod h1:Fi7KchJVfwMuPJkX4vJeAlNZkxCiVyhvVYfCgaSDlTU= github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww= @@ -222,8 +222,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U= github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0= github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y= github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168= -github.com/dolthub/go-mysql-server v0.17.1-0.20231113191556-2da061871eb8 h1:hOOUs5dptLxn8hsNV/lm7GNgUcqmms3d9N86o2INALM= -github.com/dolthub/go-mysql-server v0.17.1-0.20231113191556-2da061871eb8/go.mod h1:Z3EbOzC1yoK9MoYBxl6LDksV8GRRyjjHDZTu2lWpT/E= +github.com/dolthub/go-mysql-server v0.17.1-0.20231130181846-c0a0060c4fe7 h1:aNrWLEmWLvD3vJR14XJ8PhRzRteOOg6/1coHqU5sOR8= +github.com/dolthub/go-mysql-server v0.17.1-0.20231130181846-c0a0060c4fe7/go.mod h1:vXlRKS39WHav9N51VsfYphKhmSA2t5FkhHmW3BtwH5I= github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 h1:0HHu0GWJH0N6a6keStrHhUAK5/o9LVfkh44pvsV4514= github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488/go.mod h1:ehexgi1mPxRTk0Mok/pADALuHbvATulTh6gzr7NzZto= github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72 h1:NfWmngMi1CYUWU4Ix8wM+USEhjc+mhPlT9JUR/anvbQ= @@ -234,8 +234,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9X github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc= github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ= -github.com/dolthub/vitess v0.0.0-20231109003730-c0fa018b5ef6 h1:/GOBV8ceNCMuyS9/sdjqfmgti6OSibUKDTop9YbowzM= -github.com/dolthub/vitess v0.0.0-20231109003730-c0fa018b5ef6/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw= +github.com/dolthub/vitess v0.0.0-20231127171856-2466012fb61f h1:I480LKHhb4usnF3dYhp6J4ORKMrncNKaWYZvIZwlK+U= +github.com/dolthub/vitess v0.0.0-20231127171856-2466012fb61f/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -978,8 +978,8 @@ golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnL golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI= -golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4= +golang.org/x/image v0.10.0 h1:gXjUUtwtx5yOE0VKWq1CH4IJAClq4UGgUA3i+rpON9M= +golang.org/x/image v0.10.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= From 5ad8ce24c00948f0e0e1a8408a2af9efe4973ac6 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Thu, 30 Nov 2023 17:55:52 -0800 Subject: [PATCH 10/14] Tests for recent parser changes --- testing/go/regression_test.go | 125 ++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100755 testing/go/regression_test.go diff --git a/testing/go/regression_test.go b/testing/go/regression_test.go new file mode 100755 index 0000000000..7165dc657f --- /dev/null +++ b/testing/go/regression_test.go @@ -0,0 +1,125 @@ +// Copyright 2023 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 _go + +import ( + "testing" + + "github.com/dolthub/go-mysql-server/sql" +) + +func TestRegressions(t *testing.T) { + RunScripts(t, []ScriptTest{ + { + Name: "nullif", + SetUpScript: []string{}, + Assertions: []ScriptTestAssertion{ + { + Query: "select nullif(1, 1);", + Expected: []sql.Row{{nil}}, + }, + { + Query: "select nullif('', null);", + Expected: []sql.Row{{""}}, + }, + { + Query: "select nullif(10, 'a');", + Expected: []sql.Row{{10}}, + }, + }, + }, + { + Name: "coalesce", + SetUpScript: []string{}, + Assertions: []ScriptTestAssertion{ + { + Query: "select coalesce(null + 5, 100);", + Expected: []sql.Row{{100.0}}, // TODO: this should be an integer + }, + { + Query: "select coalesce(null, null, 'abc');", + Expected: []sql.Row{{"abc"}}, + }, + { + Query: "select coalesce(null, null);", + Expected: []sql.Row{{nil}}, + }, + }, + }, + { + Name: "case / when", + SetUpScript: []string{}, + Assertions: []ScriptTestAssertion{ + { + Query: "SELECT\n" + + " CASE\n" + + " WHEN 1 = 1 THEN 'One is equal to One'\n" + + " ELSE 'One is not equal to One'\n" + + " END AS result;", + Expected: []sql.Row{{"One is equal to One"}}, + }, + { + Query: "SELECT\n" + + " CASE\n" + + " WHEN NULL IS NULL THEN 'NULL is NULL'\n" + + " ELSE 'NULL is not NULL'\n" + + " END AS result;", + Expected: []sql.Row{{"NULL is NULL"}}, + }, + }, + }, + { + Name: "ALL / DISTINCT in functions", + SetUpScript: []string{ + "create table t1 (pk int);", + "insert into t1 values (1), (2), (3), (1);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select all count(*) from t1;", + Expected: []sql.Row{{4}}, + }, + { + Query: "select all count(distinct pk) from t1;", + Expected: []sql.Row{{3}}, + }, + { + Query: "select all count(all pk) from t1;", + Expected: []sql.Row{{4}}, + }, + }, + }, + { + Name: "cross joins", + SetUpScript: []string{ + "create table t1 (pk int);", + "create table t2 (pk int);", + "insert into t1 values (1), (2);", + "insert into t2 values (3), (4);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select count(*) from t1 cross join t2;", + Expected: []sql.Row{{4}}, + }, + { + Query: "select count(*) from t1, t2;", + Expected: []sql.Row{{4}}, + }, + }, + }, + }) +} + From aba72008028eb10269abeb51e431e2121c2dba28 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Thu, 30 Nov 2023 17:56:24 -0800 Subject: [PATCH 11/14] Formatting --- testing/go/regression_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/testing/go/regression_test.go b/testing/go/regression_test.go index 7165dc657f..73273a5b0d 100755 --- a/testing/go/regression_test.go +++ b/testing/go/regression_test.go @@ -63,7 +63,7 @@ func TestRegressions(t *testing.T) { SetUpScript: []string{}, Assertions: []ScriptTestAssertion{ { - Query: "SELECT\n" + + Query: "SELECT\n" + " CASE\n" + " WHEN 1 = 1 THEN 'One is equal to One'\n" + " ELSE 'One is not equal to One'\n" + @@ -71,7 +71,7 @@ func TestRegressions(t *testing.T) { Expected: []sql.Row{{"One is equal to One"}}, }, { - Query: "SELECT\n" + + Query: "SELECT\n" + " CASE\n" + " WHEN NULL IS NULL THEN 'NULL is NULL'\n" + " ELSE 'NULL is not NULL'\n" + @@ -81,7 +81,7 @@ func TestRegressions(t *testing.T) { }, }, { - Name: "ALL / DISTINCT in functions", + Name: "ALL / DISTINCT in functions", SetUpScript: []string{ "create table t1 (pk int);", "insert into t1 values (1), (2), (3), (1);", @@ -102,7 +102,7 @@ func TestRegressions(t *testing.T) { }, }, { - Name: "cross joins", + Name: "cross joins", SetUpScript: []string{ "create table t1 (pk int);", "create table t2 (pk int);", @@ -122,4 +122,3 @@ func TestRegressions(t *testing.T) { }, }) } - From b7d7adeb679746b267a32f22b1c49f4870b4b6c6 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Fri, 1 Dec 2023 10:22:43 -0800 Subject: [PATCH 12/14] Better test --- testing/go/regression_test.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/testing/go/regression_test.go b/testing/go/regression_test.go index 73273a5b0d..37471acf4f 100755 --- a/testing/go/regression_test.go +++ b/testing/go/regression_test.go @@ -104,19 +104,29 @@ func TestRegressions(t *testing.T) { { Name: "cross joins", SetUpScript: []string{ - "create table t1 (pk int);", - "create table t2 (pk int);", + "create table t1 (pk1 int);", + "create table t2 (pk2 int);", "insert into t1 values (1), (2);", "insert into t2 values (3), (4);", }, Assertions: []ScriptTestAssertion{ { - Query: "select count(*) from t1 cross join t2;", - Expected: []sql.Row{{4}}, + Query: "select * from t1 cross join t2 order by pk1, pk2;", + Expected: []sql.Row{ + {1, 3}, + {1, 4}, + {2, 3}, + {2, 4}, + }, }, { - Query: "select count(*) from t1, t2;", - Expected: []sql.Row{{4}}, + Query: "select * from t1, t2 order by pk1, pk2;", + Expected: []sql.Row{ + {1, 3}, + {1, 4}, + {2, 3}, + {2, 4}, + }, }, }, }, From 47367f8c716b03f103ee0024a82bbd9f77854aac Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Fri, 1 Dec 2023 13:13:37 -0800 Subject: [PATCH 13/14] Comment out tests that rely on new gms / dolt because updating it is going to be involved --- go.mod | 6 +-- go.sum | 16 ++++---- testing/go/regression_test.go | 72 +++++++++++++++++------------------ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/go.mod b/go.mod index 89ce9b8462..ca9092bab5 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,10 @@ require ( github.com/PuerkitoBio/goquery v1.8.1 github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a github.com/cockroachdb/errors v1.7.5 - github.com/dolthub/dolt/go v0.40.5-0.20231130221002-0d5eeb513092 - github.com/dolthub/go-mysql-server v0.17.1-0.20231130181846-c0a0060c4fe7 + github.com/dolthub/dolt/go v0.40.5-0.20231114163244-0cc42b844045 + github.com/dolthub/go-mysql-server v0.17.1-0.20231113191556-2da061871eb8 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20231127171856-2466012fb61f + github.com/dolthub/vitess v0.0.0-20231109003730-c0fa018b5ef6 github.com/fatih/color v1.13.0 github.com/gogo/protobuf v1.3.2 github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35 diff --git a/go.sum b/go.sum index c98e74ae1c..e1e968109a 100644 --- a/go.sum +++ b/go.sum @@ -216,8 +216,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dolthub/dolt/go v0.40.5-0.20231130221002-0d5eeb513092 h1:DvCGM7uxHtNe8b6C2vpX71oFhhHf1KoXeb+/y8wBkt8= -github.com/dolthub/dolt/go v0.40.5-0.20231130221002-0d5eeb513092/go.mod h1:PVPL+qOhr6+DPUW0QyHTvoTd0AbYBIRd7Y4ITrhi97s= +github.com/dolthub/dolt/go v0.40.5-0.20231114163244-0cc42b844045 h1:3XcJEPd9hydNGegfDC95b+PJWvzJrqU0serxh5Bo9Qw= +github.com/dolthub/dolt/go v0.40.5-0.20231114163244-0cc42b844045/go.mod h1:CAA/kBFxZdT8s3aLtLUw3gEsuxSOVeChlQucDlZCTBU= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20231018220650-48f565111c6a h1:WYBHmrFuKPqPfLB8ab1WqL5MgR8PQICkfUs5RTjHZM8= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20231018220650-48f565111c6a/go.mod h1:Fi7KchJVfwMuPJkX4vJeAlNZkxCiVyhvVYfCgaSDlTU= github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww= @@ -226,8 +226,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U= github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0= github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y= github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168= -github.com/dolthub/go-mysql-server v0.17.1-0.20231130181846-c0a0060c4fe7 h1:aNrWLEmWLvD3vJR14XJ8PhRzRteOOg6/1coHqU5sOR8= -github.com/dolthub/go-mysql-server v0.17.1-0.20231130181846-c0a0060c4fe7/go.mod h1:vXlRKS39WHav9N51VsfYphKhmSA2t5FkhHmW3BtwH5I= +github.com/dolthub/go-mysql-server v0.17.1-0.20231113191556-2da061871eb8 h1:hOOUs5dptLxn8hsNV/lm7GNgUcqmms3d9N86o2INALM= +github.com/dolthub/go-mysql-server v0.17.1-0.20231113191556-2da061871eb8/go.mod h1:Z3EbOzC1yoK9MoYBxl6LDksV8GRRyjjHDZTu2lWpT/E= github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 h1:0HHu0GWJH0N6a6keStrHhUAK5/o9LVfkh44pvsV4514= github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488/go.mod h1:ehexgi1mPxRTk0Mok/pADALuHbvATulTh6gzr7NzZto= github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72 h1:NfWmngMi1CYUWU4Ix8wM+USEhjc+mhPlT9JUR/anvbQ= @@ -238,8 +238,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9X github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc= github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ= -github.com/dolthub/vitess v0.0.0-20231127171856-2466012fb61f h1:I480LKHhb4usnF3dYhp6J4ORKMrncNKaWYZvIZwlK+U= -github.com/dolthub/vitess v0.0.0-20231127171856-2466012fb61f/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw= +github.com/dolthub/vitess v0.0.0-20231109003730-c0fa018b5ef6 h1:/GOBV8ceNCMuyS9/sdjqfmgti6OSibUKDTop9YbowzM= +github.com/dolthub/vitess v0.0.0-20231109003730-c0fa018b5ef6/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -982,8 +982,8 @@ golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnL golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.10.0 h1:gXjUUtwtx5yOE0VKWq1CH4IJAClq4UGgUA3i+rpON9M= -golang.org/x/image v0.10.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0= +golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI= +golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/testing/go/regression_test.go b/testing/go/regression_test.go index 37471acf4f..a4135f678c 100755 --- a/testing/go/regression_test.go +++ b/testing/go/regression_test.go @@ -22,42 +22,42 @@ import ( func TestRegressions(t *testing.T) { RunScripts(t, []ScriptTest{ - { - Name: "nullif", - SetUpScript: []string{}, - Assertions: []ScriptTestAssertion{ - { - Query: "select nullif(1, 1);", - Expected: []sql.Row{{nil}}, - }, - { - Query: "select nullif('', null);", - Expected: []sql.Row{{""}}, - }, - { - Query: "select nullif(10, 'a');", - Expected: []sql.Row{{10}}, - }, - }, - }, - { - Name: "coalesce", - SetUpScript: []string{}, - Assertions: []ScriptTestAssertion{ - { - Query: "select coalesce(null + 5, 100);", - Expected: []sql.Row{{100.0}}, // TODO: this should be an integer - }, - { - Query: "select coalesce(null, null, 'abc');", - Expected: []sql.Row{{"abc"}}, - }, - { - Query: "select coalesce(null, null);", - Expected: []sql.Row{{nil}}, - }, - }, - }, + // { + // Name: "nullif", + // SetUpScript: []string{}, + // Assertions: []ScriptTestAssertion{ + // { + // Query: "select nullif(1, 1);", + // Expected: []sql.Row{{nil}}, + // }, + // { + // Query: "select nullif('', null);", + // Expected: []sql.Row{{""}}, + // }, + // { + // Query: "select nullif(10, 'a');", + // Expected: []sql.Row{{10}}, + // }, + // }, + // }, + // { + // Name: "coalesce", + // SetUpScript: []string{}, + // Assertions: []ScriptTestAssertion{ + // { + // Query: "select coalesce(null + 5, 100);", + // Expected: []sql.Row{{100.0}}, // TODO: this should be an integer + // }, + // { + // Query: "select coalesce(null, null, 'abc');", + // Expected: []sql.Row{{"abc"}}, + // }, + // { + // Query: "select coalesce(null, null);", + // Expected: []sql.Row{{nil}}, + // }, + // }, + // }, { Name: "case / when", SetUpScript: []string{}, From 7b284d574bdeb846062ce4da8b71410f1f082dca Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Fri, 1 Dec 2023 13:14:03 -0800 Subject: [PATCH 14/14] formatting --- testing/go/regression_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/go/regression_test.go b/testing/go/regression_test.go index a4135f678c..4f86f14463 100755 --- a/testing/go/regression_test.go +++ b/testing/go/regression_test.go @@ -111,7 +111,7 @@ func TestRegressions(t *testing.T) { }, Assertions: []ScriptTestAssertion{ { - Query: "select * from t1 cross join t2 order by pk1, pk2;", + Query: "select * from t1 cross join t2 order by pk1, pk2;", Expected: []sql.Row{ {1, 3}, {1, 4}, @@ -120,7 +120,7 @@ func TestRegressions(t *testing.T) { }, }, { - Query: "select * from t1, t2 order by pk1, pk2;", + Query: "select * from t1, t2 order by pk1, pk2;", Expected: []sql.Row{ {1, 3}, {1, 4},