Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 8141017

Browse files
authored
Merge pull request #643 from kuba--/count
Make count int64 function
2 parents 0093a75 + 184b584 commit 8141017

File tree

5 files changed

+52
-52
lines changed

5 files changed

+52
-52
lines changed

engine_test.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"testing"
1212
"time"
1313

14-
"gopkg.in/src-d/go-mysql-server.v0"
14+
sqle "gopkg.in/src-d/go-mysql-server.v0"
1515
"gopkg.in/src-d/go-mysql-server.v0/auth"
1616
"gopkg.in/src-d/go-mysql-server.v0/mem"
1717
"gopkg.in/src-d/go-mysql-server.v0/sql"
@@ -50,15 +50,15 @@ var queries = []struct {
5050
},
5151
{
5252
"SELECT COUNT(*) FROM mytable;",
53-
[]sql.Row{{int32(3)}},
53+
[]sql.Row{{int64(3)}},
5454
},
5555
{
5656
"SELECT COUNT(*) FROM mytable LIMIT 1;",
57-
[]sql.Row{{int32(3)}},
57+
[]sql.Row{{int64(3)}},
5858
},
5959
{
6060
"SELECT COUNT(*) AS c FROM mytable;",
61-
[]sql.Row{{int32(3)}},
61+
[]sql.Row{{int64(3)}},
6262
},
6363
{
6464
"SELECT substring(s, 2, 3) FROM mytable",
@@ -176,9 +176,9 @@ var queries = []struct {
176176
) t
177177
GROUP BY fi`,
178178
[]sql.Row{
179-
{int32(1), "first row"},
180-
{int32(1), "second row"},
181-
{int32(1), "third row"},
179+
{int64(1), "first row"},
180+
{int64(1), "second row"},
181+
{int64(1), "third row"},
182182
},
183183
},
184184
{
@@ -188,25 +188,25 @@ var queries = []struct {
188188
) t
189189
GROUP BY 2`,
190190
[]sql.Row{
191-
{int32(1), "first row"},
192-
{int32(1), "second row"},
193-
{int32(1), "third row"},
191+
{int64(1), "first row"},
192+
{int64(1), "second row"},
193+
{int64(1), "third row"},
194194
},
195195
},
196196
{
197197
`SELECT COUNT(*) as cnt, s as fi FROM mytable GROUP BY fi`,
198198
[]sql.Row{
199-
{int32(1), "first row"},
200-
{int32(1), "second row"},
201-
{int32(1), "third row"},
199+
{int64(1), "first row"},
200+
{int64(1), "second row"},
201+
{int64(1), "third row"},
202202
},
203203
},
204204
{
205205
`SELECT COUNT(*) as cnt, s as fi FROM mytable GROUP BY 2`,
206206
[]sql.Row{
207-
{int32(1), "first row"},
208-
{int32(1), "second row"},
209-
{int32(1), "third row"},
207+
{int64(1), "first row"},
208+
{int64(1), "second row"},
209+
{int64(1), "third row"},
210210
},
211211
},
212212
{
@@ -333,41 +333,41 @@ var queries = []struct {
333333
{
334334
`SELECT COUNT(*) c, i as foo FROM mytable GROUP BY i ORDER BY i DESC`,
335335
[]sql.Row{
336-
{int32(1), int64(3)},
337-
{int32(1), int64(2)},
338-
{int32(1), int64(1)},
336+
{int64(1), int64(3)},
337+
{int64(1), int64(2)},
338+
{int64(1), int64(1)},
339339
},
340340
},
341341
{
342342
`SELECT COUNT(*) c, i as foo FROM mytable GROUP BY 2 ORDER BY 2 DESC`,
343343
[]sql.Row{
344-
{int32(1), int64(3)},
345-
{int32(1), int64(2)},
346-
{int32(1), int64(1)},
344+
{int64(1), int64(3)},
345+
{int64(1), int64(2)},
346+
{int64(1), int64(1)},
347347
},
348348
},
349349
{
350350
`SELECT COUNT(*) c, i as foo FROM mytable GROUP BY i ORDER BY foo, i DESC`,
351351
[]sql.Row{
352-
{int32(1), int64(3)},
353-
{int32(1), int64(2)},
354-
{int32(1), int64(1)},
352+
{int64(1), int64(3)},
353+
{int64(1), int64(2)},
354+
{int64(1), int64(1)},
355355
},
356356
},
357357
{
358358
`SELECT COUNT(*) c, i as foo FROM mytable GROUP BY 2 ORDER BY foo, i DESC`,
359359
[]sql.Row{
360-
{int32(1), int64(3)},
361-
{int32(1), int64(2)},
362-
{int32(1), int64(1)},
360+
{int64(1), int64(3)},
361+
{int64(1), int64(2)},
362+
{int64(1), int64(1)},
363363
},
364364
},
365365
{
366366
`SELECT COUNT(*) c, i as i FROM mytable GROUP BY 2`,
367367
[]sql.Row{
368-
{int32(1), int64(3)},
369-
{int32(1), int64(2)},
370-
{int32(1), int64(1)},
368+
{int64(1), int64(3)},
369+
{int64(1), int64(2)},
370+
{int64(1), int64(1)},
371371
},
372372
},
373373
{
@@ -875,7 +875,7 @@ var queries = []struct {
875875
},
876876
{
877877
"SELECT substring(s, 1, 1), count(*) FROM mytable GROUP BY substring(s, 1, 1)",
878-
[]sql.Row{{"f", int32(1)}, {"s", int32(1)}, {"t", int32(1)}},
878+
[]sql.Row{{"f", int64(1)}, {"s", int64(1)}, {"t", int64(1)}},
879879
},
880880
}
881881

@@ -1805,9 +1805,9 @@ func TestOrderByGroupBy(t *testing.T) {
18051805
require.NoError(err)
18061806

18071807
expected := []sql.Row{
1808-
{"purple", int32(1)},
1809-
{"red", int32(2)},
1810-
{"orange", int32(3)},
1808+
{"purple", int64(1)},
1809+
{"red", int64(2)},
1810+
{"orange", int64(3)},
18111811
}
18121812

18131813
require.Equal(expected, rows)

sql/analyzer/aggregations_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestReorderAggregationsMultiple(t *testing.T) {
9898
[]sql.Expression{
9999
expression.NewArithmetic(
100100
expression.NewGetField(0, sql.Float64, "SUM(foo.a)", false),
101-
expression.NewGetField(1, sql.Int32, "COUNT(foo.a)", false),
101+
expression.NewGetField(1, sql.Int64, "COUNT(foo.a)", false),
102102
"/",
103103
),
104104
expression.NewGetFieldWithTable(2, sql.Int64, "foo", "b", false),

sql/expression/function/aggregation/count.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ func NewCount(e sql.Expression) *Count {
1919

2020
// NewBuffer creates a new buffer for the aggregation.
2121
func (c *Count) NewBuffer() sql.Row {
22-
return sql.NewRow(int32(0))
22+
return sql.NewRow(int64(0))
2323
}
2424

2525
// Type returns the type of the result.
2626
func (c *Count) Type() sql.Type {
27-
return sql.Int32
27+
return sql.Int64
2828
}
2929

3030
// IsNullable returns whether the return value can be null.
@@ -71,15 +71,15 @@ func (c *Count) Update(ctx *sql.Context, buffer, row sql.Row) error {
7171
}
7272

7373
if inc {
74-
buffer[0] = buffer[0].(int32) + int32(1)
74+
buffer[0] = buffer[0].(int64) + int64(1)
7575
}
7676

7777
return nil
7878
}
7979

8080
// Merge implements the Aggregation interface.
8181
func (c *Count) Merge(ctx *sql.Context, buffer, partial sql.Row) error {
82-
buffer[0] = buffer[0].(int32) + partial[0].(int32)
82+
buffer[0] = buffer[0].(int64) + partial[0].(int64)
8383
return nil
8484
}
8585

sql/expression/function/aggregation/count_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ func TestCount_Eval_1(t *testing.T) {
2121

2222
c := NewCount(expression.NewLiteral(1, sql.Int32))
2323
b := c.NewBuffer()
24-
require.Equal(int32(0), eval(t, c, b))
24+
require.Equal(int64(0), eval(t, c, b))
2525

2626
require.NoError(c.Update(ctx, b, nil))
2727
require.NoError(c.Update(ctx, b, sql.NewRow("foo")))
2828
require.NoError(c.Update(ctx, b, sql.NewRow(1)))
2929
require.NoError(c.Update(ctx, b, sql.NewRow(nil)))
3030
require.NoError(c.Update(ctx, b, sql.NewRow(1, 2, 3)))
31-
require.Equal(int32(5), eval(t, c, b))
31+
require.Equal(int64(5), eval(t, c, b))
3232

3333
b2 := c.NewBuffer()
3434
require.NoError(c.Update(ctx, b2, nil))
3535
require.NoError(c.Update(ctx, b2, sql.NewRow("foo")))
3636
require.NoError(c.Merge(ctx, b, b2))
37-
require.Equal(int32(7), eval(t, c, b))
37+
require.Equal(int64(7), eval(t, c, b))
3838
}
3939

4040
func TestCount_Eval_Star(t *testing.T) {
@@ -43,20 +43,20 @@ func TestCount_Eval_Star(t *testing.T) {
4343

4444
c := NewCount(expression.NewStar())
4545
b := c.NewBuffer()
46-
require.Equal(int32(0), eval(t, c, b))
46+
require.Equal(int64(0), eval(t, c, b))
4747

4848
c.Update(ctx, b, nil)
4949
c.Update(ctx, b, sql.NewRow("foo"))
5050
c.Update(ctx, b, sql.NewRow(1))
5151
c.Update(ctx, b, sql.NewRow(nil))
5252
c.Update(ctx, b, sql.NewRow(1, 2, 3))
53-
require.Equal(int32(5), eval(t, c, b))
53+
require.Equal(int64(5), eval(t, c, b))
5454

5555
b2 := c.NewBuffer()
5656
c.Update(ctx, b2, sql.NewRow())
5757
c.Update(ctx, b2, sql.NewRow("foo"))
5858
c.Merge(ctx, b, b2)
59-
require.Equal(int32(7), eval(t, c, b))
59+
require.Equal(int64(7), eval(t, c, b))
6060
}
6161

6262
func TestCount_Eval_String(t *testing.T) {
@@ -65,11 +65,11 @@ func TestCount_Eval_String(t *testing.T) {
6565

6666
c := NewCount(expression.NewGetField(0, sql.Text, "", true))
6767
b := c.NewBuffer()
68-
require.Equal(int32(0), eval(t, c, b))
68+
require.Equal(int64(0), eval(t, c, b))
6969

7070
c.Update(ctx, b, sql.NewRow("foo"))
71-
require.Equal(int32(1), eval(t, c, b))
71+
require.Equal(int64(1), eval(t, c, b))
7272

7373
c.Update(ctx, b, sql.NewRow(nil))
74-
require.Equal(int32(1), eval(t, c, b))
74+
require.Equal(int64(1), eval(t, c, b))
7575
}

sql/plan/group_by_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestGroupBySchema(t *testing.T) {
2121
gb := NewGroupBy(agg, nil, NewResolvedTable(child))
2222
require.Equal(sql.Schema{
2323
{Name: "c1", Type: sql.Text},
24-
{Name: "c2", Type: sql.Int32},
24+
{Name: "c2", Type: sql.Int64},
2525
}, gb.Schema())
2626
}
2727

@@ -144,8 +144,8 @@ func TestGroupByAggregationGrouping(t *testing.T) {
144144
require.NoError(err)
145145

146146
expected := []sql.Row{
147-
{int32(3), false},
148-
{int32(2), false},
147+
{int64(3), false},
148+
{int64(2), false},
149149
}
150150

151151
require.Equal(expected, rows)

0 commit comments

Comments
 (0)