Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ List<Types.NestedField> convertInternal(List<String> names, List<TypeInfo> typeI
List<Types.NestedField> result = new ArrayList<>(names.size());
for (int i = 0; i < names.size(); ++i) {
result.add(Types.NestedField.optional(id++, names.get(i), convertType(typeInfos.get(i)),
comments.isEmpty() ? null : comments.get(i)));
(comments.isEmpty() || i >= comments.size()) ? null : comments.get(i)));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ public void testComplexTypeAndTypeInfoConvert() {
}
}

@Test
public void testConversionWithoutLastComment() {
Schema expected = new Schema(
optional(0, "customer_id", Types.LongType.get(), "customer comment"),
optional(1, "first_name", Types.StringType.get(), null)
);

Schema schema = HiveSchemaUtil.convert(
Arrays.asList("customer_id", "first_name"),
Arrays.asList(TypeInfoUtils.getTypeInfoFromTypeString(serdeConstants.BIGINT_TYPE_NAME),
TypeInfoUtils.getTypeInfoFromTypeString(serdeConstants.STRING_TYPE_NAME)),
Arrays.asList("customer comment"));

Assert.assertEquals(expected.asStruct(), schema.asStruct());
}

protected List<FieldSchema> getSupportedFieldSchemas() {
List<FieldSchema> fields = new ArrayList<>();
fields.add(new FieldSchema("c_float", serdeConstants.FLOAT_TYPE_NAME, "float comment"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ public void testCreateTableWithColumnComments() {
TableIdentifier identifier = TableIdentifier.of("default", "comment_table");
shell.executeStatement("CREATE EXTERNAL TABLE comment_table (" +
"t_int INT COMMENT 'int column', " +
"t_string STRING COMMENT 'string column') " +
"t_string STRING COMMENT 'string column', " +
"t_string_2 STRING) " +
"STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler' " +
testTables.locationForCreateTableSQL(identifier) +
testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
Expand All @@ -558,7 +559,7 @@ public void testCreateTableWithColumnComments() {
for (int i = 0; i < icebergTable.schema().columns().size(); i++) {
Types.NestedField field = icebergTable.schema().columns().get(i);
Assert.assertArrayEquals(new Object[] {field.name(), HiveSchemaUtil.convert(field.type()).getTypeName(),
field.doc()}, rows.get(i));
(field.doc() != null ? field.doc() : "from deserializer")}, rows.get(i));
}
}

Expand Down