Skip to content

Commit 50e0ef9

Browse files
committed
address @ggevay's buggy name regression
1 parent bd7c46f commit 50e0ef9

File tree

4 files changed

+116
-9
lines changed

4 files changed

+116
-9
lines changed

src/expr/src/explain/text.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,10 +1192,11 @@ where
11921192
M::humanize_ident(*self.expr.0, ident, f)
11931193
}
11941194
// We don't have name inferred for this column.
1195-
_ => {
1196-
// Write the stored name.
1197-
write!(f, "#{}{{{}}}", self.expr.0, self.expr.1)
1198-
}
1195+
_ => M::humanize_ident(
1196+
*self.expr.0,
1197+
Ident::new_unchecked(self.expr.1.to_string()),
1198+
f,
1199+
),
11991200
}
12001201
}
12011202
}

src/transform/src/analysis.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,12 +959,14 @@ mod column_names {
959959
}
960960

961961
impl ColumnName {
962-
/// Return `true` iff this the variant is not unknown.
962+
/// Return `true` iff the variant has an inferred name.
963963
pub fn is_known(&self) -> bool {
964-
matches!(
965-
self,
966-
Self::Global(..) | Self::Aggregate(..) | Self::Annotated(..)
967-
)
964+
match self {
965+
Self::Global(..) | Self::Aggregate(..) => true,
966+
// We treat annotated columns as unknown because we would rather
967+
// override them with inferred names, if we can.
968+
Self::Annotated(..) | Self::Unknown => false,
969+
}
968970
}
969971

970972
/// Humanize the column to a [`String`], returns an empty [`String`] for

test/sqllogictest/github-31878.slt

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Copyright Materialize, Inc. and contributors. All rights reserved.
2+
#
3+
# Use of this software is governed by the Business Source License
4+
# included in the LICENSE file at the root of this repository.
5+
#
6+
# As of the Change Date specified in that file, in accordance with
7+
# the Business Source License, use of this software will be governed
8+
# by the Apache License, Version 2.0.
9+
10+
mode cockroach
11+
12+
statement ok
13+
create table t1(x int, y int);
14+
15+
query T multiline
16+
EXPLAIN OPTIMIZED PLAN WITH (humanized expressions, column names) AS VERBOSE TEXT FOR
17+
select sum(x) + 5 as s from t1;
18+
----
19+
Explained Query:
20+
With
21+
cte l0 =
22+
Reduce aggregates=[sum(#0{x})] // { column_names: "(sum_x)" }
23+
Project (#0{x}) // { column_names: "(x)" }
24+
ReadStorage materialize.public.t1 // { column_names: "(x, y)" }
25+
Return // { column_names: "(#0)" }
26+
Project (#1) // { column_names: "(#0)" }
27+
Map ((#0{sum_x} + 5)) // { column_names: "(sum_x, #1)" }
28+
Union // { column_names: "(sum_x)" }
29+
Get l0 // { column_names: "(sum_x)" }
30+
Map (null) // { column_names: "(#0)" }
31+
Union // { column_names: "()" }
32+
Negate // { column_names: "()" }
33+
Project () // { column_names: "()" }
34+
Get l0 // { column_names: "(sum_x)" }
35+
Constant // { column_names: "()" }
36+
- ()
37+
38+
Source materialize.public.t1
39+
40+
Target cluster: quickstart
41+
42+
EOF
43+
44+
query T multiline
45+
EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
46+
select sum(x) + 5 as s from t1;
47+
----
48+
Explained Query:
49+
With
50+
cte l0 =
51+
Reduce aggregates=[sum(#0{x})]
52+
Project (#0{x})
53+
ReadStorage materialize.public.t1
54+
Return
55+
Project (#1)
56+
Map ((#0{sum_x} + 5))
57+
Union
58+
Get l0
59+
Map (null)
60+
Union
61+
Negate
62+
Project ()
63+
Get l0
64+
Constant
65+
- ()
66+
67+
Source materialize.public.t1
68+
69+
Target cluster: quickstart
70+
71+
EOF
72+
73+
# NB no humanized expressions means we won't infer any column names
74+
# but we _will_ get to keep the annotated names (for better or worse)
75+
76+
query T multiline
77+
EXPLAIN OPTIMIZED PLAN WITH (humanized expressions = false) AS VERBOSE TEXT FOR
78+
select sum(x) + 5 as s from t1;
79+
----
80+
Explained Query:
81+
With
82+
cte l0 =
83+
Reduce aggregates=[sum(#0{x})]
84+
Project (#0)
85+
ReadStorage materialize.public.t1
86+
Return
87+
Project (#1)
88+
Map ((#0{"?column?"} + 5))
89+
Union
90+
Get l0
91+
Map (null)
92+
Union
93+
Negate
94+
Project ()
95+
Get l0
96+
Constant
97+
- ()
98+
99+
Source materialize.public.t1
100+
101+
Target cluster: quickstart
102+
103+
EOF

test/sqllogictest/mzcompose.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def compileFastSltConfig() -> SltRunConfig:
262262
"test/sqllogictest/github-5536.slt",
263263
"test/sqllogictest/github-5717.slt",
264264
"test/sqllogictest/github-7585.slt",
265+
"test/sqllogictest/github-31878.slt",
265266
"test/sqllogictest/id.slt",
266267
"test/sqllogictest/id_reuse.slt",
267268
"test/sqllogictest/information_schema_columns.slt",

0 commit comments

Comments
 (0)