Skip to content

Commit fa59db2

Browse files
author
James Cor
committed
merge with main
2 parents 0d1adac + 6abfb25 commit fa59db2

File tree

13 files changed

+520
-14
lines changed

13 files changed

+520
-14
lines changed

enginetest/queries/script_queries.go

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4694,6 +4694,16 @@ CREATE TABLE tab3 (
46944694
"insert into collate_tbl values (7, 'a,c');",
46954695
"insert into collate_tbl values (8, 'a,b,c');",
46964696

4697+
"create table text_tbl (i int primary key, s text);",
4698+
"insert into text_tbl values (0, '');",
4699+
"insert into text_tbl values (1, 'a');",
4700+
"insert into text_tbl values (2, 'b');",
4701+
"insert into text_tbl values (3, 'c');",
4702+
"insert into text_tbl values (4, 'a,b');",
4703+
"insert into text_tbl values (6, 'b,c');",
4704+
"insert into text_tbl values (7, 'a,c');",
4705+
"insert into text_tbl values (8, 'a,b,c');",
4706+
46974707
"create table enum_tbl (i int primary key, s enum('a','b','c'));",
46984708
"insert into enum_tbl values (0, 'a'), (1, 'b'), (2, 'c');",
46994709
"select i, s, find_in_set('a', s) from enum_tbl;",
@@ -4725,6 +4735,19 @@ CREATE TABLE tab3 (
47254735
{8, 1},
47264736
},
47274737
},
4738+
{
4739+
Query: "select i, find_in_set('a', s) from text_tbl;",
4740+
Expected: []sql.Row{
4741+
{0, 0},
4742+
{1, 1},
4743+
{2, 0},
4744+
{3, 0},
4745+
{4, 1},
4746+
{6, 0},
4747+
{7, 1},
4748+
{8, 1},
4749+
},
4750+
},
47284751
{
47294752
Query: "select i, find_in_set('a', s) from enum_tbl;",
47304753
Expected: []sql.Row{
@@ -8107,6 +8130,208 @@ where
81078130
},
81088131
},
81098132
},
8133+
{
8134+
Name: "ntile tests",
8135+
Dialect: "mysql",
8136+
SetUpScript: []string{
8137+
"create table t (i int primary key, j int);",
8138+
"insert into t values (1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2);",
8139+
},
8140+
Assertions: []ScriptTestAssertion{
8141+
{
8142+
Query: "select i, ntile(null) over() from t;",
8143+
ExpectedErr: sql.ErrInvalidArgument,
8144+
},
8145+
{
8146+
Query: "select i, ntile(0) over() from t;",
8147+
ExpectedErr: sql.ErrInvalidArgument,
8148+
},
8149+
{
8150+
Query: "select i, ntile(-1) over() from t;",
8151+
ExpectedErr: sql.ErrInvalidArgument,
8152+
},
8153+
{
8154+
Query: "select i, ntile(100) over() from t;",
8155+
Expected: []sql.Row{
8156+
{1, uint64(1)},
8157+
{2, uint64(2)},
8158+
{3, uint64(3)},
8159+
{4, uint64(4)},
8160+
{5, uint64(5)},
8161+
{6, uint64(6)},
8162+
{7, uint64(7)},
8163+
{8, uint64(8)},
8164+
{9, uint64(9)},
8165+
{10, uint64(10)},
8166+
},
8167+
},
8168+
{
8169+
Query: "select i, ntile(10) over() from t;",
8170+
Expected: []sql.Row{
8171+
{1, uint64(1)},
8172+
{2, uint64(2)},
8173+
{3, uint64(3)},
8174+
{4, uint64(4)},
8175+
{5, uint64(5)},
8176+
{6, uint64(6)},
8177+
{7, uint64(7)},
8178+
{8, uint64(8)},
8179+
{9, uint64(9)},
8180+
{10, uint64(10)},
8181+
},
8182+
},
8183+
{
8184+
Query: "select i, ntile(9) over() from t;",
8185+
Expected: []sql.Row{
8186+
{1, uint64(1)},
8187+
{2, uint64(1)},
8188+
{3, uint64(2)},
8189+
{4, uint64(3)},
8190+
{5, uint64(4)},
8191+
{6, uint64(5)},
8192+
{7, uint64(6)},
8193+
{8, uint64(7)},
8194+
{9, uint64(8)},
8195+
{10, uint64(9)},
8196+
},
8197+
},
8198+
{
8199+
Query: "select i, ntile(8) over() from t;",
8200+
Expected: []sql.Row{
8201+
{1, uint64(1)},
8202+
{2, uint64(1)},
8203+
{3, uint64(2)},
8204+
{4, uint64(2)},
8205+
{5, uint64(3)},
8206+
{6, uint64(4)},
8207+
{7, uint64(5)},
8208+
{8, uint64(6)},
8209+
{9, uint64(7)},
8210+
{10, uint64(8)},
8211+
},
8212+
},
8213+
{
8214+
Query: "select i, ntile(7) over() from t;",
8215+
Expected: []sql.Row{
8216+
{1, uint64(1)},
8217+
{2, uint64(1)},
8218+
{3, uint64(2)},
8219+
{4, uint64(2)},
8220+
{5, uint64(3)},
8221+
{6, uint64(3)},
8222+
{7, uint64(4)},
8223+
{8, uint64(5)},
8224+
{9, uint64(6)},
8225+
{10, uint64(7)},
8226+
},
8227+
},
8228+
{
8229+
Query: "select i, ntile(6) over() from t;",
8230+
Expected: []sql.Row{
8231+
{1, uint64(1)},
8232+
{2, uint64(1)},
8233+
{3, uint64(2)},
8234+
{4, uint64(2)},
8235+
{5, uint64(3)},
8236+
{6, uint64(3)},
8237+
{7, uint64(4)},
8238+
{8, uint64(4)},
8239+
{9, uint64(5)},
8240+
{10, uint64(6)},
8241+
},
8242+
},
8243+
{
8244+
Query: "select i, ntile(5) over() from t;",
8245+
Expected: []sql.Row{
8246+
{1, uint64(1)},
8247+
{2, uint64(1)},
8248+
{3, uint64(2)},
8249+
{4, uint64(2)},
8250+
{5, uint64(3)},
8251+
{6, uint64(3)},
8252+
{7, uint64(4)},
8253+
{8, uint64(4)},
8254+
{9, uint64(5)},
8255+
{10, uint64(5)},
8256+
},
8257+
},
8258+
{
8259+
Query: "select i, ntile(4) over() from t;",
8260+
Expected: []sql.Row{
8261+
{1, uint64(1)},
8262+
{2, uint64(1)},
8263+
{3, uint64(1)},
8264+
{4, uint64(2)},
8265+
{5, uint64(2)},
8266+
{6, uint64(2)},
8267+
{7, uint64(3)},
8268+
{8, uint64(3)},
8269+
{9, uint64(4)},
8270+
{10, uint64(4)},
8271+
},
8272+
},
8273+
{
8274+
Query: "select i, ntile(3) over() from t;",
8275+
Expected: []sql.Row{
8276+
{1, uint64(1)},
8277+
{2, uint64(1)},
8278+
{3, uint64(1)},
8279+
{4, uint64(1)},
8280+
{5, uint64(2)},
8281+
{6, uint64(2)},
8282+
{7, uint64(2)},
8283+
{8, uint64(3)},
8284+
{9, uint64(3)},
8285+
{10, uint64(3)},
8286+
},
8287+
},
8288+
{
8289+
Query: "select i, ntile(2) over() from t;",
8290+
Expected: []sql.Row{
8291+
{1, uint64(1)},
8292+
{2, uint64(1)},
8293+
{3, uint64(1)},
8294+
{4, uint64(1)},
8295+
{5, uint64(1)},
8296+
{6, uint64(2)},
8297+
{7, uint64(2)},
8298+
{8, uint64(2)},
8299+
{9, uint64(2)},
8300+
{10, uint64(2)},
8301+
},
8302+
},
8303+
{
8304+
Query: "select i, ntile(1) over() from t;",
8305+
Expected: []sql.Row{
8306+
{1, uint64(1)},
8307+
{2, uint64(1)},
8308+
{3, uint64(1)},
8309+
{4, uint64(1)},
8310+
{5, uint64(1)},
8311+
{6, uint64(1)},
8312+
{7, uint64(1)},
8313+
{8, uint64(1)},
8314+
{9, uint64(1)},
8315+
{10, uint64(1)},
8316+
},
8317+
},
8318+
{
8319+
Query: "select i, j, ntile(2) over(partition by j) from t;",
8320+
Expected: []sql.Row{
8321+
{1, 1, uint64(1)},
8322+
{2, 1, uint64(1)},
8323+
{3, 1, uint64(1)},
8324+
{4, 1, uint64(2)},
8325+
{5, 1, uint64(2)},
8326+
{6, 2, uint64(1)},
8327+
{7, 2, uint64(1)},
8328+
{8, 2, uint64(1)},
8329+
{9, 2, uint64(2)},
8330+
{10, 2, uint64(2)},
8331+
},
8332+
},
8333+
},
8334+
},
81108335
}
81118336

81128337
var SpatialScriptTests = []ScriptTest{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250411172524-030d7ebedb96
9+
github.com/dolthub/vitess v0.0.0-20250414165810-f0031a6472b7
1010
github.com/go-kit/kit v0.10.0
1111
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1212
github.com/gocraft/dbr/v2 v2.7.2

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE
5858
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
5959
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
6060
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
61-
github.com/dolthub/vitess v0.0.0-20250411172524-030d7ebedb96 h1:CRHpJLqR9rYaBfEwFn5De/6j7IPQxUObMxuO3svg2FI=
62-
github.com/dolthub/vitess v0.0.0-20250411172524-030d7ebedb96/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
61+
github.com/dolthub/vitess v0.0.0-20250410233614-8d8c7a5b3d6b h1:2wE+qJwJ5SRIzz+dJQT8XbkpK+g8/pFt34AU/iJ5K+Y=
62+
github.com/dolthub/vitess v0.0.0-20250410233614-8d8c7a5b3d6b/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
63+
github.com/dolthub/vitess v0.0.0-20250414165810-f0031a6472b7 h1:4Y043kZgAH1WhOER0nk+02KPKxJX8Ir6yK7cGzY04c4=
64+
github.com/dolthub/vitess v0.0.0-20250414165810-f0031a6472b7/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
6365
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
6466
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
6567
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=

optgen/cmd/source/unary_aggs.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ unaryAggs:
3232
- name: "Sum"
3333
desc: "returns the sum of expr in all rows"
3434
nullable: false
35-
- name: "StdDevPop"
36-
desc: "returns the population standard deviation of expr"
37-
- name: "StdDevSamp"
38-
desc: "returns the sample standard deviation of expr"
39-
- name: "VarPop"
40-
desc: "returns the population variance of expr"
41-
- name: "VarSamp"
42-
desc: "returns the sample variance of expr"
35+
- name: "StdDevPop"
36+
desc: "returns the population standard deviation of expr"
37+
- name: "StdDevSamp"
38+
desc: "returns the sample standard deviation of expr"
39+
- name: "VarPop"
40+
desc: "returns the population variance of expr"
41+
- name: "VarSamp"
42+
desc: "returns the sample variance of expr"

sql/analyzer/constraints.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ func resolveDropConstraint(ctx *sql.Context, a *Analyzer, n sql.Node, scope *pla
7474
}
7575
}
7676

77+
if dropConstraint.IfExists {
78+
newAlterDropCheck := plan.NewAlterDropCheck(rt, dropConstraint.Name)
79+
newAlterDropCheck.IfExists = true
80+
return newAlterDropCheck, transform.NewTree, nil
81+
}
82+
7783
return nil, transform.SameTree, sql.ErrUnknownConstraint.New(dropConstraint.Name)
7884
})
7985
}
@@ -82,6 +88,11 @@ func resolveDropConstraint(ctx *sql.Context, a *Analyzer, n sql.Node, scope *pla
8288
func validateDropConstraint(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
8389
switch n := n.(type) {
8490
case *plan.DropCheck:
91+
// Don't bother validating that the constraint exists if the IfExists flag is set
92+
if n.IfExists {
93+
return n, transform.SameTree, nil
94+
}
95+
8596
rt := n.Table
8697

8798
ct, ok := rt.Table.(sql.CheckTable)

0 commit comments

Comments
 (0)