Skip to content

Commit bd54570

Browse files
hqbhohofindepi
andauthored
Fix EXPLAIN (TYPE IO) failure when constraint contains type which cannot be cast to varchar (#27433)
* Avoid exception in EXPLAIN (TYPE IO) Avoid exception if constraint contain type which can't cast to varchar * Make castToVarcharOrFail method private in ValuePrinter * empty: roll the dice 🎲 --------- Co-authored-by: Piotr Findeisen <[email protected]>
1 parent dd05807 commit bd54570

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ private FormattedDomain parseDomain(Domain domain)
783783
.collect(toImmutableSet())),
784784
discreteValues -> formattedRanges.addAll(
785785
discreteValues.getValues().stream()
786-
.map(value -> valuePrinter.castToVarcharOrFail(type, value))
786+
.map(value -> valuePrinter.castToVarchar(type, value))
787787
.map(value -> new FormattedMarker(Optional.of(value), Bound.EXACTLY))
788788
.map(marker -> new FormattedRange(marker, marker))
789789
.collect(toImmutableSet())),
@@ -799,13 +799,13 @@ private FormattedRange formatRange(Range range)
799799
FormattedMarker low = range.isLowUnbounded()
800800
? new FormattedMarker(Optional.empty(), Bound.ABOVE)
801801
: new FormattedMarker(
802-
Optional.of(valuePrinter.castToVarcharOrFail(range.getType(), range.getLowBoundedValue())),
802+
Optional.of(valuePrinter.castToVarchar(range.getType(), range.getLowBoundedValue())),
803803
range.isLowInclusive() ? Bound.EXACTLY : Bound.ABOVE);
804804

805805
FormattedMarker high = range.isHighUnbounded()
806806
? new FormattedMarker(Optional.empty(), Bound.BELOW)
807807
: new FormattedMarker(
808-
Optional.of(valuePrinter.castToVarcharOrFail(range.getType(), range.getHighBoundedValue())),
808+
Optional.of(valuePrinter.castToVarchar(range.getType(), range.getHighBoundedValue())),
809809
range.isHighInclusive() ? Bound.EXACTLY : Bound.BELOW);
810810

811811
return new FormattedRange(low, high);

core/trino-main/src/main/java/io/trino/sql/planner/planprinter/ValuePrinter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public String castToVarchar(Type type, Object value)
4848
}
4949
}
5050

51-
public String castToVarcharOrFail(Type type, Object value)
51+
private String castToVarcharOrFail(Type type, Object value)
5252
throws OperatorNotFoundException
5353
{
5454
if (value == null) {

plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import io.trino.spi.security.Identity;
4848
import io.trino.spi.security.SelectedRole;
4949
import io.trino.spi.statistics.TableStatistics;
50+
import io.trino.spi.type.ArrayType;
5051
import io.trino.spi.type.DateType;
5152
import io.trino.spi.type.TimestampType;
5253
import io.trino.spi.type.Type;
@@ -1661,6 +1662,33 @@ public void testIoExplainWithPrimitiveTypes()
16611662
}
16621663
}
16631664

1665+
@Test
1666+
public void testIoExplainWithStructuralTypes()
1667+
{
1668+
assertUpdate("CREATE TABLE io_explain_test_structural_type(array_col ARRAY(int)) WITH (format='PARQUET')");
1669+
EstimatedStatsAndCost estimate = new EstimatedStatsAndCost(0.0, 0.0, 0.0, 0.0, 0.0);
1670+
assertThat(getIoPlanCodec().fromJson((String) getOnlyElement(computeActual("EXPLAIN (TYPE IO, FORMAT JSON) SELECT * FROM io_explain_test_structural_type WHERE array_col = ARRAY[1]").getOnlyColumnAsSet())))
1671+
.isEqualTo(new IoPlan(
1672+
ImmutableSet.of(new TableColumnInfo(
1673+
new CatalogSchemaTableName(catalog, "tpch", "io_explain_test_structural_type"),
1674+
new IoPlanPrinter.Constraint(
1675+
false,
1676+
ImmutableSet.of(
1677+
new ColumnConstraint(
1678+
"array_col",
1679+
new ArrayType(INTEGER),
1680+
new FormattedDomain(
1681+
false,
1682+
ImmutableSet.of(
1683+
new FormattedRange(
1684+
new FormattedMarker(Optional.of("<UNREPRESENTABLE VALUE>"), EXACTLY),
1685+
new FormattedMarker(Optional.of("<UNREPRESENTABLE VALUE>"), EXACTLY))))))),
1686+
estimate)),
1687+
Optional.empty(),
1688+
estimate));
1689+
assertUpdate("DROP TABLE io_explain_test_structural_type");
1690+
}
1691+
16641692
@Test
16651693
public void testReadNoColumns()
16661694
{

0 commit comments

Comments
 (0)