Skip to content
Open
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 @@ -57,7 +57,7 @@ public TableFieldSchema apply(Field field) {
private final String name;
private final LegacySQLTypeName type;
private final FieldList subFields;
private final String mode;
private final Mode mode;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Changing the internal field mode from String to Mode breaks backward serialization compatibility for the Field class, which implements Serializable. If instances of Field (or classes containing it, like Schema) are serialized and shared across different versions of the library (e.g., in distributed processing frameworks like Apache Beam or Spark), deserialization will fail with an InvalidClassException or ClassCastException due to the type mismatch. Since the performance overhead of Mode.valueOf(mode) is negligible, please consider whether breaking serialization compatibility is acceptable for this change. If compatibility must be preserved, it is safer to keep the internal representation as String.

private final String description;
private final PolicyTags policyTags;
private final Long maxLength;
Expand All @@ -84,7 +84,7 @@ public static final class Builder {
private String name;
private LegacySQLTypeName type;
private FieldList subFields;
private String mode;
private Mode mode;
private String description;
private PolicyTags policyTags;
private Long maxLength;
Expand Down Expand Up @@ -205,7 +205,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() : null;
this.mode = mode;
return this;
}

Expand Down Expand Up @@ -357,7 +357,7 @@ public LegacySQLTypeName getType() {

/** Returns the field mode. By default {@link Mode#NULLABLE} is used. */
public Mode getMode() {
return mode != null ? Mode.valueOf(mode) : null;
return mode;
}

/** Returns the field description. */
Expand Down Expand Up @@ -509,7 +509,7 @@ TableFieldSchema toPb() {
fieldSchemaPb.setName(name);
fieldSchemaPb.setType(type.name());
if (mode != null) {
fieldSchemaPb.setMode(mode);
fieldSchemaPb.setMode(mode.name());
}
if (description != null) {
fieldSchemaPb.setDescription(description);
Expand Down
Loading