Skip to content

Commit bb94330

Browse files
committed
Reuse coercion on binary to varchar for non-orc partitioned table
1 parent 10de7c6 commit bb94330

File tree

3 files changed

+1
-69
lines changed

3 files changed

+1
-69
lines changed

plugin/trino-hive/src/main/java/io/trino/plugin/hive/coercions/VarbinaryToVarcharCoercers.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.HexFormat;
2727

2828
import static io.trino.plugin.hive.HiveStorageFormat.ORC;
29-
import static io.trino.plugin.hive.HiveStorageFormat.PARQUET;
3029
import static io.trino.spi.type.VarbinaryType.VARBINARY;
3130
import static io.trino.spi.type.Varchars.truncateToLength;
3231
import static java.nio.charset.CodingErrorAction.REPLACE;
@@ -41,9 +40,6 @@ public static TypeCoercer<VarbinaryType, VarcharType> createVarbinaryToVarcharCo
4140
if (storageFormat == ORC) {
4241
return new OrcVarbinaryToVarcharCoercer(toType);
4342
}
44-
if (storageFormat == PARQUET) {
45-
return new ParquetVarbinaryToVarcharCoercer(toType);
46-
}
4743
return new VarbinaryToVarcharCoercer(toType);
4844
}
4945

@@ -55,31 +51,6 @@ public VarbinaryToVarcharCoercer(VarcharType toType)
5551
super(VARBINARY, toType);
5652
}
5753

58-
@Override
59-
protected void applyCoercedValue(BlockBuilder blockBuilder, Block block, int position)
60-
{
61-
try {
62-
Slice decodedValue = fromType.getSlice(block, position);
63-
if (toType.isUnbounded()) {
64-
toType.writeSlice(blockBuilder, decodedValue);
65-
return;
66-
}
67-
toType.writeSlice(blockBuilder, truncateToLength(decodedValue, toType.getBoundedLength()));
68-
}
69-
catch (RuntimeException e) {
70-
blockBuilder.appendNull();
71-
}
72-
}
73-
}
74-
75-
private static class ParquetVarbinaryToVarcharCoercer
76-
extends TypeCoercer<VarbinaryType, VarcharType>
77-
{
78-
public ParquetVarbinaryToVarcharCoercer(VarcharType toType)
79-
{
80-
super(VARBINARY, toType);
81-
}
82-
8354
@Override
8455
protected void applyCoercedValue(BlockBuilder blockBuilder, Block block, int position)
8556
{

plugin/trino-hive/src/test/java/io/trino/plugin/hive/coercions/TestVarbinaryToVarcharCoercer.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import static io.trino.plugin.hive.HiveStorageFormat.ORC;
2525
import static io.trino.plugin.hive.HiveStorageFormat.PARQUET;
26-
import static io.trino.plugin.hive.HiveStorageFormat.RCTEXT;
2726
import static io.trino.plugin.hive.HiveTimestampPrecision.DEFAULT_PRECISION;
2827
import static io.trino.plugin.hive.coercions.CoercionUtils.createCoercer;
2928
import static io.trino.plugin.hive.util.HiveTypeTranslator.toHiveType;
@@ -45,35 +44,6 @@ public class TestVarbinaryToVarcharCoercer
4544

4645
@Test
4746
public void testVarbinaryToVarcharCoercion()
48-
{
49-
assertVarbinaryToVarcharCoercion(Slices.utf8Slice("abc"), VARBINARY, Slices.utf8Slice("abc"), VARCHAR);
50-
assertVarbinaryToVarcharCoercion(Slices.utf8Slice("abc"), VARBINARY, Slices.utf8Slice("ab"), createVarcharType(2));
51-
// Invalid UTF-8 encoding
52-
assertVarbinaryToVarcharCoercion(Slices.wrappedBuffer(X_CHAR, CONTINUATION_BYTE), VARBINARY, Slices.wrappedBuffer(X_CHAR, CONTINUATION_BYTE), VARCHAR);
53-
assertVarbinaryToVarcharCoercion(
54-
Slices.wrappedBuffer(X_CHAR, START_4_BYTE, CONTINUATION_BYTE, CONTINUATION_BYTE, CONTINUATION_BYTE),
55-
VARBINARY,
56-
Slices.wrappedBuffer(X_CHAR, START_4_BYTE, CONTINUATION_BYTE, CONTINUATION_BYTE, CONTINUATION_BYTE),
57-
VARCHAR);
58-
assertVarbinaryToVarcharCoercion(
59-
Slices.wrappedBuffer(X_CHAR, START_4_BYTE, CONTINUATION_BYTE, CONTINUATION_BYTE, CONTINUATION_BYTE, X_CHAR),
60-
VARBINARY,
61-
Slices.wrappedBuffer(X_CHAR, START_4_BYTE, CONTINUATION_BYTE, CONTINUATION_BYTE, CONTINUATION_BYTE, X_CHAR),
62-
VARCHAR);
63-
assertVarbinaryToVarcharCoercion(
64-
Slices.wrappedBuffer(X_CHAR, (byte) 0b11101101, (byte) 0xA0, (byte) 0x80),
65-
VARBINARY,
66-
Slices.wrappedBuffer(X_CHAR, (byte) 0b11101101, (byte) 0xA0, (byte) 0x80),
67-
VARCHAR);
68-
assertVarbinaryToVarcharCoercion(
69-
Slices.wrappedBuffer(X_CHAR, (byte) 0b11101101, (byte) 0xBF, (byte) 0xBF),
70-
VARBINARY,
71-
Slices.wrappedBuffer(X_CHAR, (byte) 0b11101101, (byte) 0xBF, (byte) 0xBF),
72-
VARCHAR);
73-
}
74-
75-
@Test
76-
public void testVarbinaryToVarcharCoercionForParquet()
7747
{
7848
assertVarbinaryToVarcharCoercionForParquet(Slices.utf8Slice("abc"), VARBINARY, "abc", VARCHAR);
7949
assertVarbinaryToVarcharCoercionForParquet(Slices.utf8Slice("abc"), VARBINARY, "ab", createVarcharType(2));
@@ -98,11 +68,6 @@ public void testVarbinaryToVarcharCoercionForOrc()
9868
assertVarbinaryToVarcharCoercionForOrc(Slices.wrappedBuffer(X_CHAR, (byte) 0b11101101, (byte) 0xBF, (byte) 0xBF), VARBINARY, "58 ed bf bf", VARCHAR);
9969
}
10070

101-
private static void assertVarbinaryToVarcharCoercion(Slice actualValue, Type fromType, Slice expectedValue, Type toType)
102-
{
103-
assertVarbinaryToVarcharCoercion(actualValue, fromType, expectedValue, toType, RCTEXT);
104-
}
105-
10671
private static void assertVarbinaryToVarcharCoercionForOrc(Slice actualValue, Type fromType, String expectedValue, Type toType)
10772
{
10873
assertVarbinaryToVarcharCoercion(actualValue, fromType, Slices.utf8Slice(expectedValue), toType, ORC);

testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/BaseTestHiveCoercion.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,12 @@ protected void doTestHiveCoercion(HiveTableDefinition tableDefinition)
214214

215215
// Additional assertions for VARBINARY coercion
216216
if (prestoReadColumns.contains("binary_to_string")) {
217-
List<Object> hexRepresentedValue = ImmutableList.of("58F7BFBFBF", "58F7BFBFBF58");
217+
List<Object> hexRepresentedValue = ImmutableList.of("58EFBFBDEFBFBDEFBFBDEFBFBD", "58EFBFBDEFBFBDEFBFBDEFBFBD58");
218218

219219
if (tableName.toLowerCase(ENGLISH).contains("orc")) {
220220
hexRepresentedValue = ImmutableList.of("3538206637206266206266206266", "3538206637206266206266206266203538");
221221
}
222222

223-
if (tableName.toLowerCase(ENGLISH).contains("parquet")) {
224-
hexRepresentedValue = ImmutableList.of("58EFBFBDEFBFBDEFBFBDEFBFBD", "58EFBFBDEFBFBDEFBFBDEFBFBD58");
225-
}
226-
227223
assertQueryResults(
228224
Engine.TRINO,
229225
format("SELECT to_hex(cast(binary_to_string as varbinary)) as hex_representation FROM %s", tableName),

0 commit comments

Comments
 (0)