Skip to content

Commit 56d51ec

Browse files
committed
fix
1 parent 45e9855 commit 56d51ec

File tree

4 files changed

+87
-7
lines changed

4 files changed

+87
-7
lines changed

src/query/sql/src/planner/binder/aggregate.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'a> AggregateRewriter<'a> {
249249
// grouping(b, a) will be rewritten to grouping<1, 0>(grouping_id).
250250
let mut replaced_params = Vec::with_capacity(function.arguments.len());
251251
for arg in &function.arguments {
252-
if let Some(index) = agg_info.group_items_map.get(&format!("{:?}", arg)) {
252+
if let Some(index) = agg_info.group_items_map.get(arg) {
253253
replaced_params.push(*index);
254254
} else {
255255
return Err(ErrorCode::BadArguments(
@@ -259,9 +259,11 @@ impl<'a> AggregateRewriter<'a> {
259259
}
260260

261261
let replaced_func = FunctionCall {
262+
span: function.span,
262263
func_name: function.func_name.clone(),
263264
params: replaced_params,
264265
arguments: vec![ScalarExpr::BoundColumnRef(BoundColumnRef {
266+
span: function.span,
265267
column: grouping_id_column,
266268
})],
267269
};
@@ -434,12 +436,10 @@ impl Binder {
434436
let index = grouping_id_column.index;
435437
agg_info.grouping_id_column = Some(grouping_id_column.clone());
436438
agg_info.group_items_map.insert(
437-
format!(
438-
"{:?}",
439-
ScalarExpr::BoundColumnRef(BoundColumnRef {
440-
column: grouping_id_column.clone()
441-
})
442-
),
439+
ScalarExpr::BoundColumnRef(BoundColumnRef {
440+
span: None,
441+
column: grouping_id_column.clone(),
442+
}),
443443
agg_info.group_items.len(),
444444
);
445445
agg_info.group_items.push(ScalarItem {

src/query/sql/src/planner/semantic/type_check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ impl<'a> TypeChecker<'a> {
10061006
// `grouping` will be rewritten again after resolving grouping sets.
10071007
return Ok(Box::new((
10081008
ScalarExpr::FunctionCall(FunctionCall {
1009+
span,
10091010
params: vec![],
10101011
arguments: args,
10111012
func_name: "grouping".to_string(),
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ERROR 1105 (HY000) at line 1: Code: 1065, displayText = error:
2+
--> SQL:1:8
3+
|
4+
1 | select *
5+
| ^ SELECT * with no tables specified is not valid
6+
7+
.
8+
ERROR 1105 (HY000) at line 1: Code: 1025, displayText = error:
9+
--> SQL:1:15
10+
|
11+
1 | select * from t
12+
| ^ Unknown table 't'
13+
14+
.
15+
ERROR 1105 (HY000) at line 1: Code: 1008, displayText = error:
16+
--> SQL:1:8
17+
|
18+
1 | select base64(1)
19+
| ^^^^^^^^^ no function matches the given name: base64
20+
21+
.
22+
ERROR 1105 (HY000) at line 1: Code: 1065, displayText = error:
23+
--> SQL:1:8
24+
|
25+
1 | select to_base64(1)
26+
| ^^^^^^^^^^^^ no overload satisfies `to_base64(UInt8)`
27+
28+
has tried possible overloads:
29+
to_base64(String) :: String : unable to unify `UInt8` with `String`
30+
to_base64(String NULL) :: String NULL : unable to unify `UInt8` with `String`
31+
32+
.
33+
ERROR 1105 (HY000) at line 1: Code: 1001, displayText = error:
34+
--> SQL:1:12
35+
|
36+
1 | select 1 + 'a'
37+
| ^^^ invalid digit found in string while evaluating function `to_uint8("a")`
38+
39+
.
40+
ERROR 1105 (HY000) at line 1: Code: 1025, displayText = error:
41+
--> SQL:1:20
42+
|
43+
1 | select t1.a:z from t
44+
| ^ Unknown table 't'
45+
46+
.
47+
ERROR 1105 (HY000) at line 1: Code: 2302, displayText = Table 't3' already exists.
48+
ERROR 1105 (HY000) at line 1: Code: 1065, displayText = error:
49+
--> SQL:1:33
50+
|
51+
1 | select * from t2 join t3 using (c)
52+
| ^ column c specified in USING clause does not exist in left table
53+
54+
.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
. "$CURDIR"/../../../shell_env.sh
5+
6+
7+
echo "DROP DATABASE IF EXISTS db20_13;" | $MYSQL_CLIENT_CONNECT
8+
echo "CREATE DATABASE db20_13;" | $MYSQL_CLIENT_CONNECT
9+
echo "USE db20_13;" | $MYSQL_CLIENT_CONNECT
10+
11+
12+
echo "select *;" | $MYSQL_CLIENT_CONNECT
13+
echo "select * from t;" | $MYSQL_CLIENT_CONNECT
14+
echo "select base64(1);" | $MYSQL_CLIENT_CONNECT
15+
echo "select to_base64(1);" | $MYSQL_CLIENT_CONNECT
16+
echo "select 1 + 'a';" | $MYSQL_CLIENT_CONNECT
17+
18+
echo "create table t1 (a tuple(b int, c int))" | $MYSQL_CLIENT_CONNECT
19+
echo "select t1.a:z from t" | $MYSQL_CLIENT_CONNECT
20+
21+
echo "create table t2 (a int, b int)" | $MYSQL_CLIENT_CONNECT
22+
echo "create table t3 (c int, d int)" | $MYSQL_CLIENT_CONNECT
23+
echo "select * from t2 join t3 using (c)" | $MYSQL_CLIENT_CONNECT
24+
25+
echo "DROP DATABASE db20_13;" | $MYSQL_CLIENT_CONNECT

0 commit comments

Comments
 (0)