Skip to content

Commit da8c026

Browse files
format code
1 parent 96fbf22 commit da8c026

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/iceberg/avro/avro_schema_util.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ Status ToAvroNodeVisitor::Visit(const StructType& type, ::avro::NodePtr* node) {
240240
ICEBERG_RETURN_UNEXPECTED(Visit(sub_field, &field_node));
241241

242242
bool isValidFieldName = validAvroName(std::string(sub_field.name()));
243-
std::string fieldName = isValidFieldName ? std::string(sub_field.name()) : SanitizeFieldName(sub_field.name());
243+
std::string fieldName = isValidFieldName ? std::string(sub_field.name())
244+
: SanitizeFieldName(sub_field.name());
244245
(*node)->addName(fieldName);
245246
(*node)->addLeaf(field_node);
246247
(*node)->addCustomAttributesForField(GetAttributesWithFieldId(sub_field.field_id()));

src/iceberg/avro/avro_schema_util_internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,13 @@ Result<::avro::NodePtr> MakeAvroNodeWithFieldIds(const ::avro::NodePtr& original
169169
/// Conversion rules:
170170
/// 1. If the first character is not a letter or underscore, it is specially handled:
171171
/// - Digits: Prefixed with an underscore (e.g., '3' -> '_3')
172-
/// - Other characters: Converted to '_x' followed by the uppercase hexadecimal representation
172+
/// - Other characters: Converted to '_x' followed by the uppercase hexadecimal
173+
/// representation
173174
/// of the character (e.g., '$' -> '_x24')
174175
/// 2. For characters other than the first:
175176
/// - If it's a letter, digit, or underscore, it remains unchanged
176-
/// - Other characters: Converted to '_x' followed by the uppercase hexadecimal representation
177+
/// - Other characters: Converted to '_x' followed by the uppercase hexadecimal
178+
/// representation
177179
///
178180
/// Examples:
179181
/// - "123field" -> "_123field"

test/avro_schema_test.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ TEST(ValidAvroNameTest, InvalidNames) {
7373
// Names starting with numbers should return false
7474
EXPECT_FALSE(validAvroName("123field"));
7575
EXPECT_FALSE(validAvroName("0value"));
76-
76+
7777
// Names with special characters should return false
7878
EXPECT_FALSE(validAvroName("field-name"));
7979
EXPECT_FALSE(validAvroName("field.name"));
@@ -109,7 +109,8 @@ TEST(SanitizeFieldNameTest, InvalidFieldNames) {
109109
EXPECT_EQ(SanitizeFieldName("field#name"), "field_x23name");
110110

111111
// Complex field names with multiple issues
112-
EXPECT_EQ(SanitizeFieldName("1field-with.special@chars"), "_1field_x2Dwith_x2Especial_x40chars");
112+
EXPECT_EQ(SanitizeFieldName("1field-with.special@chars"),
113+
"_1field_x2Dwith_x2Especial_x40chars");
113114
EXPECT_EQ(SanitizeFieldName("user-email"), "user_x2Demail");
114115
}
115116

@@ -275,11 +276,13 @@ TEST(ToAvroNodeVisitorTest, StructTypeWithSanitizedFieldNames) {
275276

276277
// Check that field names are sanitized
277278
ASSERT_EQ(node->names(), 4);
278-
EXPECT_EQ(node->nameAt(0), "user_x2Dname"); // "user-name" -> "user_x2Dname"
279-
EXPECT_EQ(node->nameAt(1), "email_x2Eaddress"); // "email.address" -> "email_x2Eaddress"
280-
EXPECT_EQ(node->nameAt(2), "_123field"); // "123field" -> "_123field"
281-
EXPECT_EQ(node->nameAt(3),
282-
"field_x20with_x20spaces"); // "field with spaces" -> "field_x20with_x20spaces"
279+
EXPECT_EQ(node->nameAt(0), "user_x2Dname"); // "user-name" -> "user_x2Dname"
280+
EXPECT_EQ(node->nameAt(1),
281+
"email_x2Eaddress"); // "email.address" -> "email_x2Eaddress"
282+
EXPECT_EQ(node->nameAt(2), "_123field"); // "123field" -> "_123field"
283+
EXPECT_EQ(
284+
node->nameAt(3),
285+
"field_x20with_x20spaces"); // "field with spaces" -> "field_x20with_x20spaces"
283286

284287
// Check that field IDs are correctly applied
285288
// Each field has 1 custom attribute: field-id

0 commit comments

Comments
 (0)