Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: SQL queries erroring with message unknown aggregation random #13330

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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