Skip to content

Commit

Permalink
Bug fix: SQL queries erroring with message `unknown aggregation rando…
Browse files Browse the repository at this point in the history
…m` (#13330)

Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
arvind-murty authored and frouioui committed Jun 23, 2023
1 parent 576f2ae commit e2b9830
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ func TestAggregateRandom(t *testing.T) {
mcmp.Exec("insert into t2(id, shardKey) values (1, 10), (2, 20)")

mcmp.AssertMatches("SELECT /*vt+ PLANNER=gen4 */ t1.shardKey, t1.name, count(t2.id) FROM t1 JOIN t2 ON t1.value != t2.shardKey GROUP BY t1.t1_id", `[[INT64(1) VARCHAR("name 1") INT64(2)] [INT64(2) VARCHAR("name 2") INT64(2)]]`)

mcmp.Exec("set sql_mode=''")
mcmp.AssertMatches("select /*vt+ PLANNER=Gen4 */ tbl0.comm, count(*) from emp as tbl0, emp as tbl1 where tbl0.empno = tbl1.deptno", `[[NULL INT64(0)]]`)
}

// TestAggregateLeftJoin tests that aggregates work with left joins and does not ignore the count when column value does not match the right side table.
Expand Down
23 changes: 22 additions & 1 deletion go/test/endtoend/vtgate/queries/aggregation/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,25 @@ CREATE TABLE t10 (
k BIGINT PRIMARY KEY,
a INT,
b INT
);
);

CREATE TABLE emp (
empno bigint NOT NULL,
ename VARCHAR(10),
job VARCHAR(9),
mgr bigint,
hiredate DATE,
sal bigint,
comm bigint,
deptno bigint,
PRIMARY KEY (empno)
) Engine = InnoDB
COLLATE = utf8mb4_general_ci;

CREATE TABLE dept (
deptno bigint,
dname VARCHAR(14),
loc VARCHAR(13),
PRIMARY KEY (deptno)
) Engine = InnoDB
COLLATE = utf8mb4_general_ci;
16 changes: 16 additions & 0 deletions go/test/endtoend/vtgate/queries/aggregation/vschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@
"name": "hash"
}
]
},
"emp": {
"column_vindexes": [
{
"column": "deptno",
"name": "hash"
}
]
},
"dept": {
"column_vindexes": [
{
"column": "deptno",
"name": "hash"
}
]
}
}
}
3 changes: 2 additions & 1 deletion go/vt/vtgate/engine/scalar_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ func createEmptyValueFor(opcode AggregateOpcode) (sqltypes.Value, error) {
AggregateSumDistinct,
AggregateSum,
AggregateMin,
AggregateMax:
AggregateMax,
AggregateRandom:
return sqltypes.NULL, nil

}
Expand Down

0 comments on commit e2b9830

Please sign in to comment.