Skip to content

Commit

Permalink
[release-16.0] Bug fix: SQL queries erroring with message `unknown ag…
Browse files Browse the repository at this point in the history
…gregation random` (#13330) (#13334)

* fixed unknown aggregation random bug

Signed-off-by: Arvind Murty <10248018+arvind-murty@users.noreply.github.com>

* fixed schema.sql formatting

Signed-off-by: Arvind Murty <10248018+arvind-murty@users.noreply.github.com>

---------

Signed-off-by: Arvind Murty <10248018+arvind-murty@users.noreply.github.com>
Co-authored-by: Arvind Murty <10248018+arvind-murty@users.noreply.github.com>
  • Loading branch information
vitess-bot[bot] and arvind-murty authored Jun 20, 2023
1 parent 60baf51 commit 2b26d57
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 @@ -383,6 +383,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 @@ -213,7 +213,8 @@ func createEmptyValueFor(opcode AggregateOpcode) (sqltypes.Value, error) {
AggregateSumDistinct,
AggregateSum,
AggregateMin,
AggregateMax:
AggregateMax,
AggregateRandom:
return sqltypes.NULL, nil

}
Expand Down

0 comments on commit 2b26d57

Please sign in to comment.