Skip to content
Permalink
Browse files
feat: add StandardSQLTypeName factory methods to Field (#43)
  • Loading branch information
stephaniewang526 committed Dec 18, 2019
1 parent 61f9465 commit 9b379413e9e5850060d0fbd02ab9797c574f9a44
@@ -268,12 +268,24 @@ public static Field of(String name, LegacySQLTypeName type, Field... subFields)
return newBuilder(name, type, subFields).build();
}

/** Returns a Field object with given name and type. */
public static Field of(String name, StandardSQLTypeName type, Field... subFields) {
checkArgument(!isNullOrEmpty(name), "Provided name is null or empty");
return newBuilder(name, type, subFields).build();
}

/** Returns a Field object with given name and type. */
public static Field of(String name, LegacySQLTypeName type, FieldList subFields) {
checkArgument(!isNullOrEmpty(name), "Provided name is null or empty");
return newBuilder(name, type, subFields).build();
}

/** Returns a Field object with given name and type. */
public static Field of(String name, StandardSQLTypeName type, FieldList subFields) {
checkArgument(!isNullOrEmpty(name), "Provided name is null or empty");
return newBuilder(name, type, subFields).build();
}

/** Returns a builder for a Field object with given name and type. */
public static Builder newBuilder(String name, LegacySQLTypeName type, Field... subFields) {
return new Builder().setName(name).setType(type, subFields);
@@ -32,6 +32,7 @@ public class FieldTest {
private static final String FIELD_NAME3 = "RecordField";
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;
private static final Field.Mode FIELD_MODE1 = Field.Mode.NULLABLE;
private static final Field.Mode FIELD_MODE2 = Field.Mode.REPEATED;
private static final Field.Mode FIELD_MODE3 = Field.Mode.REQUIRED;
@@ -49,6 +50,7 @@ public class FieldTest {
.setDescription(FIELD_DESCRIPTION2)
.build();
private static final LegacySQLTypeName FIELD_TYPE3 = LegacySQLTypeName.RECORD;
private static final StandardSQLTypeName FIELD_TYPE3_STANDARD = StandardSQLTypeName.STRUCT;
private static final Field FIELD_SCHEMA3 =
Field.newBuilder(FIELD_NAME3, FIELD_TYPE3, FIELD_SCHEMA1, FIELD_SCHEMA2)
.setMode(FIELD_MODE3)
@@ -112,6 +114,22 @@ public void testToBuilderIncompleteWithStandardSQLTypeName() {
compareFieldSchemas(field, field.toBuilder().build());
}

@Test
public void testToBuilderIncompleteStandard() {
Field field = Field.of(FIELD_NAME1, FIELD_TYPE1_STANDARD);
compareFieldSchemas(field, field.toBuilder().build());
field = Field.of(FIELD_NAME2, FIELD_TYPE3_STANDARD, FIELD_SCHEMA1, FIELD_SCHEMA2);
compareFieldSchemas(field, field.toBuilder().build());
}

@Test
public void testToBuilderIncompleteStandardWithStandardSQLTypeName() {
Field field = Field.of(FIELD_NAME1, FIELD_TYPE1_STANDARD);
compareFieldSchemas(field, field.toBuilder().build());
field = Field.of(FIELD_NAME2, FIELD_TYPE3_STANDARD, STANDARD_FIELD_SCHEMA1, STANDARD_FIELD_SCHEMA2);
compareFieldSchemas(field, field.toBuilder().build());
}

@Test
public void testBuilder() {
assertEquals(FIELD_NAME1, FIELD_SCHEMA1.getName());

0 comments on commit 9b37941

Please sign in to comment.