Skip to content

Commit

Permalink
fix: null field mode inconsistency (#2863)
Browse files Browse the repository at this point in the history
* fix: null field mode inconsistency

* chore: update null field mode test name

---------

Co-authored-by: PhongChuong <phong.hoa.chuong@gmail.com>
  • Loading branch information
2 people authored and lqiu96 committed Aug 28, 2024
1 parent 3f97b23 commit 1ab53a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public Builder setType(StandardSQLTypeName type, FieldList subFields) {

/** Sets the mode of the field. When not specified {@link Mode#NULLABLE} is used. */
public Builder setMode(Mode mode) {
this.mode = mode != null ? mode.name() : Data.<String>nullOf(String.class);
this.mode = mode != null ? mode.name() : null;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class FieldTest {
private static final String FIELD_NAME1 = "StringField";
private static final String FIELD_NAME2 = "IntegerField";
private static final String FIELD_NAME3 = "RecordField";
private static final String FIELD_NAME4 = "NullModeField";
private static final String FIELD_NAME5 = "NullModeField2";
private static final LegacySQLTypeName FIELD_TYPE1 = LegacySQLTypeName.STRING;
private static final LegacySQLTypeName FIELD_TYPE2 = LegacySQLTypeName.INTEGER;
private static final StandardSQLTypeName FIELD_TYPE1_STANDARD = StandardSQLTypeName.STRING;
Expand Down Expand Up @@ -79,6 +81,10 @@ public class FieldTest {
.setMode(FIELD_MODE3)
.setDescription(FIELD_DESCRIPTION3)
.build();
private static final Field STANDARD_FIELD_SCHEMA4 =
Field.newBuilder(FIELD_NAME4, StandardSQLTypeName.INT64).setMode(null).build();
private static final Field STANDARD_FIELD_SCHEMA5 =
Field.newBuilder(FIELD_NAME5, StandardSQLTypeName.STRING).build();

@Test
public void testToBuilder() {
Expand All @@ -96,6 +102,8 @@ public void testToBuilderWithStandardSQLTypeName() {
compareFieldSchemas(STANDARD_FIELD_SCHEMA1, STANDARD_FIELD_SCHEMA1.toBuilder().build());
compareFieldSchemas(STANDARD_FIELD_SCHEMA2, STANDARD_FIELD_SCHEMA2.toBuilder().build());
compareFieldSchemas(STANDARD_FIELD_SCHEMA3, STANDARD_FIELD_SCHEMA3.toBuilder().build());
compareFieldSchemas(STANDARD_FIELD_SCHEMA4, STANDARD_FIELD_SCHEMA4.toBuilder().build());
compareFieldSchemas(STANDARD_FIELD_SCHEMA5, STANDARD_FIELD_SCHEMA5.toBuilder().build());
Field field = STANDARD_FIELD_SCHEMA1.toBuilder().setDescription("New Description").build();
assertEquals("New Description", field.getDescription());
field = field.toBuilder().setDescription(FIELD_DESCRIPTION1).build();
Expand Down Expand Up @@ -162,6 +170,8 @@ public void testBuilderWithStandardSQLTypeName() {
assertEquals(FIELD_TYPE3, STANDARD_FIELD_SCHEMA3.getType());
assertEquals(FIELD_MODE3, STANDARD_FIELD_SCHEMA3.getMode());
assertEquals(FIELD_DESCRIPTION3, STANDARD_FIELD_SCHEMA3.getDescription());
assertEquals(null, STANDARD_FIELD_SCHEMA4.getMode());
assertEquals(null, STANDARD_FIELD_SCHEMA5.getMode());
assertEquals(
FieldList.of(STANDARD_FIELD_SCHEMA1, STANDARD_FIELD_SCHEMA2),
STANDARD_FIELD_SCHEMA3.getSubFields());
Expand All @@ -181,6 +191,8 @@ public void testToAndFromPbWithStandardSQLTypeName() {
compareFieldSchemas(STANDARD_FIELD_SCHEMA1, Field.fromPb(STANDARD_FIELD_SCHEMA1.toPb()));
compareFieldSchemas(STANDARD_FIELD_SCHEMA2, Field.fromPb(STANDARD_FIELD_SCHEMA2.toPb()));
compareFieldSchemas(STANDARD_FIELD_SCHEMA3, Field.fromPb(STANDARD_FIELD_SCHEMA3.toPb()));
compareFieldSchemas(STANDARD_FIELD_SCHEMA4, Field.fromPb(STANDARD_FIELD_SCHEMA4.toPb()));
compareFieldSchemas(STANDARD_FIELD_SCHEMA5, Field.fromPb(STANDARD_FIELD_SCHEMA5.toPb()));
Field field = Field.newBuilder(FIELD_NAME1, FIELD_TYPE1).build();
compareFieldSchemas(field, Field.fromPb(field.toPb()));
}
Expand Down

0 comments on commit 1ab53a8

Please sign in to comment.