@@ -59,6 +59,9 @@ public TableFieldSchema apply(Field field) {
59
59
private final String mode ;
60
60
private final String description ;
61
61
private final PolicyTags policyTags ;
62
+ private final Long maxLength ;
63
+ private final Long scale ;
64
+ private final Long precision ;
62
65
63
66
/**
64
67
* Mode for a BigQuery Table field. {@link Mode#NULLABLE} fields can be set to {@code null},
@@ -79,6 +82,9 @@ public static final class Builder {
79
82
private String mode ;
80
83
private String description ;
81
84
private PolicyTags policyTags ;
85
+ private Long maxLength ;
86
+ private Long scale ;
87
+ private Long precision ;
82
88
83
89
private Builder () {}
84
90
@@ -89,6 +95,9 @@ private Builder(Field field) {
89
95
this .mode = field .mode ;
90
96
this .description = field .description ;
91
97
this .policyTags = field .policyTags ;
98
+ this .maxLength = field .maxLength ;
99
+ this .scale = field .scale ;
100
+ this .precision = field .precision ;
92
101
}
93
102
94
103
/**
@@ -199,6 +208,43 @@ public Builder setPolicyTags(PolicyTags policyTags) {
199
208
return this ;
200
209
}
201
210
211
+ /**
212
+ * Sets the maximum length of the field for STRING or BYTES type.
213
+ *
214
+ * <p>It is invalid to set value for types other than STRING or BYTES.
215
+ *
216
+ * <p>For STRING type, this represents the maximum UTF-8 length of strings allowed in the field.
217
+ * For BYTES type, this represents the maximum number of bytes in the field.
218
+ */
219
+ public Builder setMaxLength (Long maxLength ) {
220
+ this .maxLength = maxLength ;
221
+ return this ;
222
+ }
223
+
224
+ /**
225
+ * Scale can be used to constrain the maximum number of digits in the fractional part of a
226
+ * NUMERIC or BIGNUMERIC type. If the Scale value is set, the Precision value must be set as
227
+ * well. It is invalid to set values for Scale for types other than NUMERIC or BIGNUMERIC. See
228
+ * the Precision field for additional guidance about valid values.
229
+ */
230
+ public Builder setScale (Long scale ) {
231
+ this .scale = scale ;
232
+ return this ;
233
+ }
234
+
235
+ /**
236
+ * Precision can be used to constrain the maximum number of total digits allowed for NUMERIC or
237
+ * BIGNUMERIC types. It is invalid to set values for Precision for types other than // NUMERIC
238
+ * or BIGNUMERIC. For NUMERIC type, acceptable values for Precision must be: 1 ≤ (Precision -
239
+ * Scale) ≤ 29. Values for Scale must be: 0 ≤ Scale ≤ 9. For BIGNUMERIC type, acceptable values
240
+ * for Precision must be: 1 ≤ (Precision - Scale) ≤ 38. Values for Scale must be: 0 ≤ Scale ≤
241
+ * 38.
242
+ */
243
+ public Builder setPrecision (Long precision ) {
244
+ this .precision = precision ;
245
+ return this ;
246
+ }
247
+
202
248
/** Creates a {@code Field} object. */
203
249
public Field build () {
204
250
return new Field (this );
@@ -212,6 +258,9 @@ private Field(Builder builder) {
212
258
this .mode = builder .mode ;
213
259
this .description = builder .description ;
214
260
this .policyTags = builder .policyTags ;
261
+ this .maxLength = builder .maxLength ;
262
+ this .scale = builder .scale ;
263
+ this .precision = builder .precision ;
215
264
}
216
265
217
266
/** Returns the field name. */
@@ -244,6 +293,24 @@ public PolicyTags getPolicyTags() {
244
293
return policyTags ;
245
294
}
246
295
296
+ /** Returns the maximum length of the field for STRING or BYTES type. */
297
+ public Long getMaxLength () {
298
+ return maxLength ;
299
+ }
300
+
301
+ /**
302
+ * Returns the maximum number of digits set in the fractional part of a NUMERIC or BIGNUMERIC
303
+ * type.
304
+ */
305
+ public Long getScale () {
306
+ return scale ;
307
+ }
308
+
309
+ /** Returns the maximum number of total digits allowed for NUMERIC or BIGNUMERIC types. */
310
+ public Long getPrecision () {
311
+ return precision ;
312
+ }
313
+
247
314
/**
248
315
* Returns the list of sub-fields if {@link #getType()} is a {@link LegacySQLTypeName#RECORD}.
249
316
* Returns {@code null} otherwise.
@@ -265,6 +332,9 @@ public String toString() {
265
332
.add ("mode" , mode )
266
333
.add ("description" , description )
267
334
.add ("policyTags" , policyTags )
335
+ .add ("maxLength" , maxLength )
336
+ .add ("scale" , scale )
337
+ .add ("precision" , precision )
268
338
.toString ();
269
339
}
270
340
@@ -335,6 +405,15 @@ TableFieldSchema toPb() {
335
405
if (policyTags != null ) {
336
406
fieldSchemaPb .setPolicyTags (policyTags .toPb ());
337
407
}
408
+ if (maxLength != null ) {
409
+ fieldSchemaPb .setMaxLength (maxLength );
410
+ }
411
+ if (scale != null ) {
412
+ fieldSchemaPb .setScale (scale );
413
+ }
414
+ if (precision != null ) {
415
+ fieldSchemaPb .setPrecision (precision );
416
+ }
338
417
if (getSubFields () != null ) {
339
418
List <TableFieldSchema > fieldsPb = Lists .transform (getSubFields (), TO_PB_FUNCTION );
340
419
fieldSchemaPb .setFields (fieldsPb );
@@ -354,6 +433,15 @@ static Field fromPb(TableFieldSchema fieldSchemaPb) {
354
433
if (fieldSchemaPb .getPolicyTags () != null ) {
355
434
fieldBuilder .setPolicyTags (PolicyTags .fromPb (fieldSchemaPb .getPolicyTags ()));
356
435
}
436
+ if (fieldSchemaPb .getMaxLength () != null ) {
437
+ fieldBuilder .setMaxLength (fieldSchemaPb .getMaxLength ());
438
+ }
439
+ if (fieldSchemaPb .getScale () != null ) {
440
+ fieldBuilder .setScale (fieldSchemaPb .getScale ());
441
+ }
442
+ if (fieldSchemaPb .getPrecision () != null ) {
443
+ fieldBuilder .setPrecision (fieldSchemaPb .getPrecision ());
444
+ }
357
445
FieldList subFields =
358
446
fieldSchemaPb .getFields () != null
359
447
? FieldList .of (Lists .transform (fieldSchemaPb .getFields (), FROM_PB_FUNCTION ))
0 commit comments