Skip to content

Commit 3c595a0

Browse files
committed
Normalize symbol names
Replace any sequence of non-alphanumeric with underscore.
1 parent 6b2698e commit 3c595a0

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

core/trino-main/src/main/java/io/trino/sql/planner/SymbolAllocator.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
package io.trino.sql.planner;
1515

16+
import com.google.common.base.CharMatcher;
1617
import com.google.common.primitives.Ints;
1718
import io.trino.spi.type.Type;
1819
import io.trino.sql.analyzer.Field;
@@ -30,6 +31,11 @@
3031

3132
public class SymbolAllocator
3233
{
34+
public static final CharMatcher EXCLUDED_CHARACTERS = CharMatcher.inRange('a', 'z')
35+
.or(CharMatcher.inRange('0', '9'))
36+
.negate()
37+
.precomputed();
38+
3339
private final Map<String, Symbol> symbols;
3440
private int nextId;
3541

@@ -54,8 +60,7 @@ public Symbol newSymbol(String nameHint, Type type)
5460
requireNonNull(nameHint, "nameHint is null");
5561
requireNonNull(type, "type is null");
5662

57-
// TODO: workaround for the fact that QualifiedName lowercases parts
58-
nameHint = nameHint.toLowerCase(ENGLISH);
63+
nameHint = EXCLUDED_CHARACTERS.trimAndCollapseFrom(nameHint.toLowerCase(ENGLISH), '_');
5964

6065
// don't strip the tail if the only _ is the first character
6166
int index = nameHint.lastIndexOf("_");

core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestPushProjectionIntoTableScan.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ public void testPushProjection()
155155
Map.Entry::getValue,
156156
e -> column(e.getValue(), types.get(e.getKey()))));
157157

158-
String name = newNames.get(dereference);
159-
String name1 = newNames.get(identity);
160158
ruleTester.assertThat(createRule(ruleTester))
161159
.withSession(MOCK_SESSION)
162160
.on(p -> {
@@ -195,15 +193,7 @@ public void testPushProjection()
195193
Optional.of(ImmutableList.copyOf(expectedColumns.values())))::equals,
196194
TupleDomain.all(),
197195
expectedColumns.entrySet().stream()
198-
.collect(toImmutableMap(Map.Entry::getKey, e -> e.getValue()::equals)),
199-
Optional.of(PlanNodeStatsEstimate.builder()
200-
.setOutputRowCount(42)
201-
.addSymbolStatistics(new Symbol(UNKNOWN, name1), SymbolStatsEstimate.builder()
202-
.setDistinctValuesCount(33)
203-
.setNullsFraction(0)
204-
.build())
205-
.addSymbolStatistics(new Symbol(UNKNOWN, name), SymbolStatsEstimate.unknown())
206-
.build())::equals)));
196+
.collect(toImmutableMap(Map.Entry::getKey, e -> e.getValue()::equals)))));
207197
}
208198
}
209199

plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeConnectorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ public void testProjectionPushdownExplain()
21522152
assertExplain(
21532153
"EXPLAIN SELECT root.f2 FROM " + tableName,
21542154
"TableScan\\[table = (.*)]",
2155-
"root#f2 := root#f2:bigint:REGULAR");
2155+
"(.*) := (.*):bigint:REGULAR");
21562156

21572157
Session sessionWithoutPushdown = Session.builder(getSession())
21582158
.setCatalogSessionProperty(getSession().getCatalog().orElseThrow(), "projection_pushdown_enabled", "false")
@@ -2178,12 +2178,12 @@ public void testProjectionPushdownNonPrimitiveTypeExplain()
21782178
assertExplain(
21792179
"EXPLAIN SELECT id, _row.child, _array[1].child, _map[1] FROM " + tableName,
21802180
"ScanProject\\[table = (.*)]",
2181-
"expr(.*) := system\\.builtin\\.\\$operator\\$subscript\\(_array_.*, bigint '1'\\).0",
2181+
"expr(.*) := system\\.builtin\\.\\$operator\\$subscript\\(.*, bigint '1'\\).0",
21822182
"id(.*) := id:bigint:REGULAR",
21832183
// _array:array\\(row\\(child bigint\\)\\) is a symbol name, not a dereference expression.
2184-
"_array(.*) := _array:array\\(row\\(child bigint\\)\\):REGULAR",
2185-
"_map(.*) := _map:map\\(bigint, bigint\\):REGULAR",
2186-
"_row#child := _row#child:bigint:REGULAR");
2184+
"(.*) := _array:array\\(row\\(child bigint\\)\\):REGULAR",
2185+
"(.*) := _map:map\\(bigint, bigint\\):REGULAR",
2186+
"(.*) := _row#child:bigint:REGULAR");
21872187
}
21882188

21892189
@Test

0 commit comments

Comments
 (0)