Skip to content

Commit 31e073e

Browse files
committed
Test improvements: classloader usage, field name verification, and E2E test
1 parent ae86d6e commit 31e073e

File tree

2 files changed

+85
-14
lines changed

2 files changed

+85
-14
lines changed

presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergTypes.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,68 @@ public void testMixedHyphenatedAndNormalFieldNames()
286286
}
287287
}
288288

289+
/**
290+
* End-to-end test that writes to an Iceberg table with hyphenated struct fields
291+
* and reads it back, verifying the complete write→read cycle works correctly.
292+
* This test validates the full integration of:
293+
* 1. PrimitiveTypeMapBuilder.makeCompatibleName() for writing hex-encoded field names
294+
* 2. ColumnIOConverter.constructField() for reading with makeCompatibleName()
295+
* 3. IcebergPageSourceProvider.getColumnType() for SYNTHESIZED column handling
296+
*/
297+
@Test
298+
public void testEndToEndWriteReadWithHyphenatedStructFields()
299+
{
300+
String tableName = "test_e2e_hyphenated_struct";
301+
try {
302+
// Create table with multiple hyphenated fields in struct
303+
assertUpdate("CREATE TABLE " + tableName + " (" +
304+
"id INT, " +
305+
"application ROW(" +
306+
" \"aws-region\" VARCHAR, " +
307+
" \"user-id\" INT, " +
308+
" \"data-center\" VARCHAR, " +
309+
" \"zone-id\" INT, " +
310+
" normal_field VARCHAR" +
311+
")" +
312+
")");
313+
314+
// Write data - tests PrimitiveTypeMapBuilder.makeCompatibleName()
315+
assertUpdate("INSERT INTO " + tableName + " VALUES " +
316+
"(1, ROW('us-west-2', 1001, 'dc-west-01', 100, 'normal1')), " +
317+
"(2, ROW('eu-central-1', 1002, 'dc-eu-01', 200, 'normal2')), " +
318+
"(3, ROW('ap-south-1', 1003, 'dc-ap-01', 300, 'normal3'))", 3);
319+
320+
// Read back - tests ColumnIOConverter.constructField() with makeCompatibleName()
321+
// Test individual field access (SYNTHESIZED path)
322+
assertQuery(
323+
"SELECT id, application.\"aws-region\", application.\"user-id\", application.\"data-center\" FROM " + tableName,
324+
"VALUES (1, 'us-west-2', 1001, 'dc-west-01'), " +
325+
"(2, 'eu-central-1', 1002, 'dc-eu-01'), " +
326+
"(3, 'ap-south-1', 1003, 'dc-ap-01')");
327+
328+
// Test all fields including normal field
329+
assertQuery(
330+
"SELECT application.\"aws-region\", application.\"user-id\", application.\"data-center\", " +
331+
"application.\"zone-id\", application.normal_field FROM " + tableName,
332+
"VALUES ('us-west-2', 1001, 'dc-west-01', 100, 'normal1'), " +
333+
"('eu-central-1', 1002, 'dc-eu-01', 200, 'normal2'), " +
334+
"('ap-south-1', 1003, 'dc-ap-01', 300, 'normal3')");
335+
336+
// Test with WHERE clause on hyphenated field
337+
assertQuery(
338+
"SELECT id, application.\"aws-region\" FROM " + tableName + " WHERE application.\"user-id\" = 1002",
339+
"VALUES (2, 'eu-central-1')");
340+
341+
// Test with ORDER BY on hyphenated field
342+
assertQuery(
343+
"SELECT id, application.\"zone-id\" FROM " + tableName + " ORDER BY application.\"zone-id\" DESC",
344+
"VALUES (3, 300), (2, 200), (1, 100)");
345+
}
346+
finally {
347+
assertUpdate("DROP TABLE IF EXISTS " + tableName);
348+
}
349+
}
350+
289351
/**
290352
* Test top level hyphenated column names still work correctly.
291353
* Top level columns use field ID based lookup so they were never broken.

presto-parquet/src/test/java/com/facebook/presto/parquet/TestParquetTypeUtils.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import org.testng.annotations.Test;
2525

2626
import java.io.IOException;
27+
import java.net.URISyntaxException;
2728

2829
import static com.facebook.presto.parquet.ParquetTypeUtils.lookupColumnByName;
2930
import static com.facebook.presto.parquet.ParquetTypeUtils.makeCompatibleName;
31+
import static java.util.Objects.requireNonNull;
3032
import static org.testng.Assert.assertEquals;
3133
import static org.testng.Assert.assertNotNull;
3234
import static org.testng.Assert.assertNull;
@@ -82,10 +84,12 @@ public void testMakeCompatibleName()
8284
*/
8385
@Test
8486
public void testReadPreCannedParquetWithHyphenatedFields()
85-
throws IOException
87+
throws IOException, URISyntaxException
8688
{
87-
String parquetFilePath = "src/test/resources/hyphenated-fields/hyphenated_struct_fields.parquet";
88-
Path path = new Path(parquetFilePath);
89+
Path path = new Path(requireNonNull(
90+
getClass().getClassLoader()
91+
.getResource("hyphenated-fields/hyphenated_struct_fields.parquet"))
92+
.toURI());
8993
Configuration conf = new Configuration(false);
9094

9195
ParquetMetadata parquetMetadata = ParquetFileReader.readFooter(conf, path);
@@ -118,10 +122,12 @@ public void testReadPreCannedParquetWithHyphenatedFields()
118122
*/
119123
@Test
120124
public void testLookupWithMakeCompatibleNameFindsFields()
121-
throws IOException
125+
throws IOException, URISyntaxException
122126
{
123-
String parquetFilePath = "src/test/resources/hyphenated-fields/hyphenated_struct_fields.parquet";
124-
Path path = new Path(parquetFilePath);
127+
Path path = new Path(requireNonNull(
128+
getClass().getClassLoader()
129+
.getResource("hyphenated-fields/hyphenated_struct_fields.parquet"))
130+
.toURI());
125131
Configuration conf = new Configuration(false);
126132

127133
ParquetMetadata parquetMetadata = ParquetFileReader.readFooter(conf, path);
@@ -132,11 +138,12 @@ public void testLookupWithMakeCompatibleNameFindsFields()
132138
org.apache.parquet.io.GroupColumnIO applicationColumnIO =
133139
(org.apache.parquet.io.GroupColumnIO) messageColumnIO.getChild(1);
134140

135-
// WITH makeCompatibleName() - fields should be found
136-
assertNotNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("aws-region")));
137-
assertNotNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("user-id")));
138-
assertNotNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("data-center")));
139-
assertNotNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("normal_field")));
141+
// WITH makeCompatibleName() - fields should be found and names should match
142+
assertEquals(requireNonNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("aws-region"))).getName(), "aws_x2Dregion");
143+
assertEquals(requireNonNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("user-id"))).getName(), "user_x2Did");
144+
assertEquals(requireNonNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("data-center"))).getName(), "data_x2Dcenter");
145+
assertEquals(requireNonNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("normal_field"))).getName(), "normal_field");
146+
assertEquals(requireNonNull(lookupColumnByName(applicationColumnIO, makeCompatibleName("aws_x2Dregion_2"))).getName(), "aws_x2Dregion_2");
140147
}
141148

142149
/**
@@ -145,10 +152,12 @@ public void testLookupWithMakeCompatibleNameFindsFields()
145152
*/
146153
@Test
147154
public void testLookupWithoutEncodingDoesNotFindFields()
148-
throws IOException
155+
throws IOException, URISyntaxException
149156
{
150-
String parquetFilePath = "src/test/resources/hyphenated-fields/hyphenated_struct_fields.parquet";
151-
Path path = new Path(parquetFilePath);
157+
Path path = new Path(requireNonNull(
158+
getClass().getClassLoader()
159+
.getResource("hyphenated-fields/hyphenated_struct_fields.parquet"))
160+
.toURI());
152161
Configuration conf = new Configuration(false);
153162

154163
ParquetMetadata parquetMetadata = ParquetFileReader.readFooter(conf, path);

0 commit comments

Comments
 (0)