This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathTableInfo.java
More file actions
782 lines (671 loc) · 26.1 KB
/
Copy pathTableInfo.java
File metadata and controls
782 lines (671 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/*
* Copyright 2015 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigquery;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.api.client.util.Data;
import com.google.api.client.util.Strings;
import com.google.api.core.BetaApi;
import com.google.api.services.bigquery.model.Table;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import io.opentelemetry.api.common.Attributes;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.Map;
import java.util.Objects;
/**
* Google BigQuery table information. Use {@link StandardTableDefinition} to create simple BigQuery
* table. Use {@link ViewDefinition} to create a BigQuery view. Use {@link ExternalTableDefinition}
* to create a BigQuery a table backed by external data.
*
* @see <a href="https://cloud.google.com/bigquery/docs/tables">Managing Tables</a>
*/
public class TableInfo implements Serializable {
static final Function<Table, TableInfo> FROM_PB_FUNCTION =
new Function<Table, TableInfo>() {
@Override
public TableInfo apply(Table pb) {
return TableInfo.fromPb(pb);
}
};
static final Function<TableInfo, Table> TO_PB_FUNCTION =
new Function<TableInfo, Table>() {
@Override
public Table apply(TableInfo tableInfo) {
return tableInfo.toPb();
}
};
private static final long serialVersionUID = 609769795097719407L;
private final String etag;
private final String generatedId;
private final String selfLink;
private final TableId tableId;
private final String friendlyName;
private final String description;
private final Long creationTime;
private final Long expirationTime;
private final Long lastModifiedTime;
private final Long numBytes;
private final Long numLongTermBytes;
private final Long numTimeTravelPhysicalBytes;
private final Long numTotalLogicalBytes;
private final Long numActiveLogicalBytes;
private final Long numLongTermLogicalBytes;
private final Long numTotalPhysicalBytes;
private final Long numActivePhysicalBytes;
private final Long numLongTermPhysicalBytes;
private final BigInteger numRows;
private final TableDefinition definition;
private final EncryptionConfiguration encryptionConfiguration;
private final Annotations labels;
private final Annotations resourceTags;
private final Boolean requirePartitionFilter;
private final String defaultCollation;
private final CloneDefinition cloneDefinition;
private final TableConstraints tableConstraints;
/** A builder for {@code TableInfo} objects. */
public abstract static class Builder {
abstract Builder setCreationTime(Long creationTime);
/** Sets a user-friendly description for the table. */
public abstract Builder setDescription(String description);
abstract Builder setEtag(String etag);
/**
* Sets the time when this table expires, in milliseconds since the epoch. If not present, the
* table will persist indefinitely. Expired tables will be deleted and their storage reclaimed.
*/
public abstract Builder setExpirationTime(Long expirationTime);
/** Sets a user-friendly name for the table. */
public abstract Builder setFriendlyName(String friendlyName);
abstract Builder setGeneratedId(String generatedId);
abstract Builder setLastModifiedTime(Long lastModifiedTime);
abstract Builder setNumBytes(Long numBytes);
abstract Builder setNumLongTermBytes(Long numLongTermBytes);
abstract Builder setNumTimeTravelPhysicalBytes(Long numTimeTravelPhysicalBytes);
abstract Builder setNumTotalLogicalBytes(Long numTotalLogicalBytes);
abstract Builder setNumActiveLogicalBytes(Long numActiveLogicalBytes);
abstract Builder setNumLongTermLogicalBytes(Long numLongTermLogicalBytes);
abstract Builder setNumTotalPhysicalBytes(Long numTotalPhysicalBytes);
abstract Builder setNumActivePhysicalBytes(Long numActivePhysicalBytes);
abstract Builder setNumLongTermPhysicalBytes(Long numLongTermPhysicalBytes);
abstract Builder setNumRows(BigInteger numRows);
abstract Builder setSelfLink(String selfLink);
/** Sets the table identity. */
public abstract Builder setTableId(TableId tableId);
/**
* Sets the table definition. Use {@link StandardTableDefinition} to create simple BigQuery
* table. Use {@link ViewDefinition} to create a BigQuery view. Use {@link
* ExternalTableDefinition} to create a BigQuery a table backed by external data.
*/
public abstract Builder setDefinition(TableDefinition definition);
/**
* Sets the labels applied to this table.
*
* <p>Unstable, because labels are <a
* href="https://cloud.google.com/bigquery/docs/reference/rest/v2/tables">experimental</a>.
*
* <p>When used with {@link BigQuery#update(TableInfo, TableOption...)}, setting {@code labels}
* to {@code null} removes all labels; otherwise all keys that are mapped to {@code null} values
* are removed and other keys are updated to their respective values.
*/
@BetaApi
public abstract Builder setLabels(Map<String, String> labels);
/** Sets the resource tags applied to this table. */
public abstract Builder setResourceTags(Map<String, String> resourceTags);
/** Creates a {@code TableInfo} object. */
public abstract TableInfo build();
public abstract Builder setEncryptionConfiguration(EncryptionConfiguration configuration);
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
return this;
}
public abstract Builder setDefaultCollation(String defaultCollation);
public abstract Builder setCloneDefinition(CloneDefinition cloneDefinition);
public abstract Builder setTableConstraints(TableConstraints tableConstraints);
}
static class BuilderImpl extends Builder {
private String etag;
private String generatedId;
private String selfLink;
private TableId tableId;
private String friendlyName;
private String description;
private Long creationTime;
private Long expirationTime;
private Long lastModifiedTime;
private Long numBytes;
private Long numLongTermBytes;
private Long numTimeTravelPhysicalBytes;
private Long numTotalLogicalBytes;
private Long numActiveLogicalBytes;
private Long numLongTermLogicalBytes;
private Long numTotalPhysicalBytes;
private Long numActivePhysicalBytes;
private Long numLongTermPhysicalBytes;
private BigInteger numRows;
private TableDefinition definition;
private EncryptionConfiguration encryptionConfiguration;
private Annotations labels = Annotations.ZERO;
private Annotations resourceTags = Annotations.ZERO;
private Boolean requirePartitionFilter;
private String defaultCollation;
private CloneDefinition cloneDefinition;
private TableConstraints tableConstraints;
BuilderImpl() {}
BuilderImpl(TableInfo tableInfo) {
this.etag = tableInfo.etag;
this.generatedId = tableInfo.generatedId;
this.selfLink = tableInfo.selfLink;
this.tableId = tableInfo.tableId;
this.friendlyName = tableInfo.friendlyName;
this.description = tableInfo.description;
this.creationTime = tableInfo.creationTime;
this.expirationTime = tableInfo.expirationTime;
this.lastModifiedTime = tableInfo.lastModifiedTime;
this.numBytes = tableInfo.numBytes;
this.numLongTermBytes = tableInfo.numLongTermBytes;
this.numTimeTravelPhysicalBytes = tableInfo.numTimeTravelPhysicalBytes;
this.numTotalLogicalBytes = tableInfo.numTotalLogicalBytes;
this.numActiveLogicalBytes = tableInfo.numActiveLogicalBytes;
this.numLongTermLogicalBytes = tableInfo.numLongTermLogicalBytes;
this.numTotalPhysicalBytes = tableInfo.numTotalPhysicalBytes;
this.numActivePhysicalBytes = tableInfo.numActivePhysicalBytes;
this.numLongTermPhysicalBytes = tableInfo.numLongTermPhysicalBytes;
this.numRows = tableInfo.numRows;
this.definition = tableInfo.definition;
this.encryptionConfiguration = tableInfo.encryptionConfiguration;
this.labels = tableInfo.labels;
this.resourceTags = tableInfo.resourceTags;
this.requirePartitionFilter = tableInfo.requirePartitionFilter;
this.defaultCollation = tableInfo.defaultCollation;
this.cloneDefinition = tableInfo.cloneDefinition;
this.tableConstraints = tableInfo.tableConstraints;
}
BuilderImpl(Table tablePb) {
this.tableId = TableId.fromPb(tablePb.getTableReference());
if (tablePb.getLastModifiedTime() != null) {
this.setLastModifiedTime(tablePb.getLastModifiedTime().longValue());
}
this.description = tablePb.getDescription();
this.expirationTime = tablePb.getExpirationTime();
this.friendlyName = tablePb.getFriendlyName();
this.creationTime = tablePb.getCreationTime();
this.etag = tablePb.getEtag();
this.generatedId = tablePb.getId();
this.selfLink = tablePb.getSelfLink();
this.numBytes = tablePb.getNumBytes();
this.numLongTermBytes = tablePb.getNumLongTermBytes();
this.numTimeTravelPhysicalBytes = tablePb.getNumTimeTravelPhysicalBytes();
this.numTotalLogicalBytes = tablePb.getNumTotalLogicalBytes();
this.numActiveLogicalBytes = tablePb.getNumActiveLogicalBytes();
this.numLongTermLogicalBytes = tablePb.getNumLongTermLogicalBytes();
this.numTotalPhysicalBytes = tablePb.getNumTotalPhysicalBytes();
this.numActivePhysicalBytes = tablePb.getNumActivePhysicalBytes();
this.numLongTermPhysicalBytes = tablePb.getNumLongTermPhysicalBytes();
this.numRows = tablePb.getNumRows();
this.definition = TableDefinition.fromPb(tablePb);
if (tablePb.getEncryptionConfiguration() != null) {
this.encryptionConfiguration =
new EncryptionConfiguration.Builder(tablePb.getEncryptionConfiguration()).build();
}
this.labels = Annotations.fromPb(tablePb.getLabels());
this.resourceTags = Annotations.fromPb(tablePb.getResourceTags());
this.requirePartitionFilter = tablePb.getRequirePartitionFilter();
this.defaultCollation = tablePb.getDefaultCollation();
if (tablePb.getCloneDefinition() != null) {
this.cloneDefinition = CloneDefinition.fromPb(tablePb.getCloneDefinition());
}
if (tablePb.getTableConstraints() != null) {
this.tableConstraints = TableConstraints.fromPb(tablePb.getTableConstraints());
}
}
@Override
Builder setCreationTime(Long creationTime) {
this.creationTime = creationTime;
return this;
}
@Override
public Builder setDescription(String description) {
this.description = firstNonNull(description, Data.<String>nullOf(String.class));
return this;
}
@Override
Builder setEtag(String etag) {
this.etag = etag;
return this;
}
@Override
public Builder setExpirationTime(Long expirationTime) {
this.expirationTime = firstNonNull(expirationTime, Data.<Long>nullOf(Long.class));
return this;
}
@Override
public Builder setFriendlyName(String friendlyName) {
this.friendlyName = firstNonNull(friendlyName, Data.<String>nullOf(String.class));
return this;
}
@Override
Builder setGeneratedId(String generatedId) {
this.generatedId = generatedId;
return this;
}
@Override
Builder setLastModifiedTime(Long lastModifiedTime) {
this.lastModifiedTime = lastModifiedTime;
return this;
}
@Override
Builder setNumBytes(Long numBytes) {
this.numBytes = numBytes;
return this;
}
@Override
Builder setNumLongTermBytes(Long numLongTermBytes) {
this.numLongTermBytes = numLongTermBytes;
return this;
}
@Override
Builder setNumTimeTravelPhysicalBytes(Long numTimeTravelPhysicalBytes) {
this.numTimeTravelPhysicalBytes = numTimeTravelPhysicalBytes;
return this;
}
@Override
Builder setNumTotalLogicalBytes(Long numTotalLogicalBytes) {
this.numTotalLogicalBytes = numTotalLogicalBytes;
return this;
}
@Override
Builder setNumActiveLogicalBytes(Long numActiveLogicalBytes) {
this.numActiveLogicalBytes = numActiveLogicalBytes;
return this;
}
@Override
Builder setNumLongTermLogicalBytes(Long numLongTermLogicalBytes) {
this.numLongTermLogicalBytes = numLongTermLogicalBytes;
return this;
}
@Override
Builder setNumTotalPhysicalBytes(Long numTotalPhysicalBytes) {
this.numTotalPhysicalBytes = numTotalPhysicalBytes;
return this;
}
@Override
Builder setNumActivePhysicalBytes(Long numActivePhysicalBytes) {
this.numActivePhysicalBytes = numActivePhysicalBytes;
return this;
}
@Override
Builder setNumLongTermPhysicalBytes(Long numLongTermPhysicalBytes) {
this.numLongTermPhysicalBytes = numLongTermPhysicalBytes;
return this;
}
@Override
Builder setNumRows(BigInteger numRows) {
this.numRows = numRows;
return this;
}
@Override
Builder setSelfLink(String selfLink) {
this.selfLink = selfLink;
return this;
}
@Override
public Builder setTableId(TableId tableId) {
this.tableId = checkNotNull(tableId);
return this;
}
@Override
public Builder setDefinition(TableDefinition definition) {
this.definition = checkNotNull(definition);
return this;
}
@Override
public Builder setEncryptionConfiguration(EncryptionConfiguration configuration) {
this.encryptionConfiguration = configuration;
return this;
}
@Override
public Builder setLabels(Map<String, String> labels) {
this.labels = Annotations.fromUser(labels);
return this;
}
@Override
public Builder setResourceTags(Map<String, String> resourceTags) {
this.resourceTags = Annotations.fromUser(resourceTags);
return this;
}
@Override
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
this.requirePartitionFilter = requirePartitionFilter;
return this;
}
@Override
public Builder setDefaultCollation(String defaultCollation) {
this.defaultCollation = defaultCollation;
return this;
}
public Builder setCloneDefinition(CloneDefinition cloneDefinition) {
this.cloneDefinition = cloneDefinition;
return this;
}
public Builder setTableConstraints(TableConstraints tableConstraints) {
this.tableConstraints = tableConstraints;
return this;
}
@Override
public TableInfo build() {
return new TableInfo(this);
}
}
TableInfo(BuilderImpl builder) {
this.tableId = checkNotNull(builder.tableId);
this.etag = builder.etag;
this.generatedId = builder.generatedId;
this.selfLink = builder.selfLink;
this.friendlyName = builder.friendlyName;
this.description = builder.description;
this.creationTime = builder.creationTime;
this.expirationTime = builder.expirationTime;
this.lastModifiedTime = builder.lastModifiedTime;
this.numBytes = builder.numBytes;
this.numLongTermBytes = builder.numLongTermBytes;
this.numTimeTravelPhysicalBytes = builder.numTimeTravelPhysicalBytes;
this.numTotalLogicalBytes = builder.numTotalLogicalBytes;
this.numActiveLogicalBytes = builder.numActiveLogicalBytes;
this.numLongTermLogicalBytes = builder.numLongTermLogicalBytes;
this.numTotalPhysicalBytes = builder.numTotalPhysicalBytes;
this.numActivePhysicalBytes = builder.numActivePhysicalBytes;
this.numLongTermPhysicalBytes = builder.numLongTermPhysicalBytes;
this.numRows = builder.numRows;
this.definition = builder.definition;
this.encryptionConfiguration = builder.encryptionConfiguration;
this.labels = builder.labels;
this.resourceTags = builder.resourceTags;
this.requirePartitionFilter = builder.requirePartitionFilter;
this.defaultCollation = builder.defaultCollation;
this.cloneDefinition = builder.cloneDefinition;
this.tableConstraints = builder.tableConstraints;
}
/** Returns the hash of the table resource. */
public String getEtag() {
return etag;
}
/** Returns the service-generated id for the table. */
public String getGeneratedId() {
return generatedId;
}
/**
* Returns an URL that can be used to access the resource again. The returned URL can be used for
* get or update requests.
*/
public String getSelfLink() {
return selfLink;
}
/** Returns the table identity. */
public TableId getTableId() {
return tableId;
}
/** Returns a user-friendly name for the table. */
public String getFriendlyName() {
return Data.isNull(friendlyName) ? null : friendlyName;
}
/** Returns a user-friendly description for the table. */
public String getDescription() {
return Data.isNull(description) ? null : description;
}
/** Returns the time when this table was created, in milliseconds since the epoch. */
public Long getCreationTime() {
return creationTime;
}
/**
* Returns the time when this table expires, in milliseconds since the epoch. If not present, the
* table will persist indefinitely. Expired tables will be deleted and their storage reclaimed.
*/
public Long getExpirationTime() {
return Data.isNull(expirationTime) ? null : expirationTime;
}
/** Returns the time when this table was last modified, in milliseconds since the epoch. */
public Long getLastModifiedTime() {
return lastModifiedTime;
}
public EncryptionConfiguration getEncryptionConfiguration() {
return encryptionConfiguration;
}
/** Returns the table definition. */
@SuppressWarnings("unchecked")
public <T extends TableDefinition> T getDefinition() {
return (T) definition;
}
/** Returns the size of this table in bytes */
public Long getNumBytes() {
return numBytes;
}
/**
* Returns the number of bytes considered "long-term storage" for reduced billing purposes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#long-term-storage">Long Term Storage
* Pricing</a>
*/
public Long getNumLongTermBytes() {
return numLongTermBytes;
}
/**
* Returns the number of time travel physical bytes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#storage">Storage Pricing</a>
*/
public Long getNumTimeTravelPhysicalBytes() {
return this.numTimeTravelPhysicalBytes;
}
/**
* Returns the number of total logical bytes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#storage">Storage Pricing</a>
*/
public Long getNumTotalLogicalBytes() {
return this.numTotalLogicalBytes;
}
/**
* Returns the number of active logical bytes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#storage">Storage Pricing</a>
*/
public Long getNumActiveLogicalBytes() {
return this.numActiveLogicalBytes;
}
/**
* Returns the number of long term logical bytes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#storage">Storage Pricing</a>
*/
public Long getNumLongTermLogicalBytes() {
return this.numLongTermLogicalBytes;
}
/**
* Returns the number of total physical bytes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#storage">Storage Pricing</a>
*/
public Long getNumTotalPhysicalBytes() {
return this.numTotalPhysicalBytes;
}
/**
* Returns the number of active physical bytes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#storage">Storage Pricing</a>
*/
public Long getNumActivePhysicalBytes() {
return this.numActivePhysicalBytes;
}
/**
* Returns the number of long term physical bytes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#storage">Storage Pricing</a>
*/
public Long getNumLongTermPhysicalBytes() {
return this.numLongTermPhysicalBytes;
}
/** Returns the number of rows of data in this table */
public BigInteger getNumRows() {
return numRows;
}
/**
* Return a map for labels applied to the table.
*
* <p>Unstable, because labels are <a
* href="https://cloud.google.com/bigquery/docs/reference/rest/v2/tables">experimental</a>.
*/
@BetaApi
public Map<String, String> getLabels() {
return labels.userMap();
}
/** Return a map for resource tags applied to the table. */
public Map<String, String> getResourceTags() {
return resourceTags.userMap();
}
/**
* Returns true if a partition filter (that can be used for partition elimination) is required for
* queries over this table.
*/
public Boolean getRequirePartitionFilter() {
return requirePartitionFilter;
}
public String getDefaultCollation() {
return defaultCollation;
}
public CloneDefinition getCloneDefinition() {
return cloneDefinition;
}
public TableConstraints getTableConstraints() {
return tableConstraints;
}
/** Returns a builder for the table object. */
public Builder toBuilder() {
return new BuilderImpl(this);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("tableId", tableId)
.add("etag", etag)
.add("generatedId", generatedId)
.add("selfLink", selfLink)
.add("friendlyName", friendlyName)
.add("description", description)
.add("expirationTime", expirationTime)
.add("creationTime", creationTime)
.add("lastModifiedTime", lastModifiedTime)
.add("numBytes", numBytes)
.add("numLongTermBytes", numLongTermBytes)
.add("numTimeTravelPhysicalBytes", numTimeTravelPhysicalBytes)
.add("numTotalLogicalBytes", numTotalLogicalBytes)
.add("numActiveLogicalBytes", numActiveLogicalBytes)
.add("numLongTermLogicalBytes", numLongTermLogicalBytes)
.add("numTotalPhysicalBytes", numTotalPhysicalBytes)
.add("numActivePhysicalBytes", numActivePhysicalBytes)
.add("numLongTermPhysicalBytes", numLongTermPhysicalBytes)
.add("numRows", numRows)
.add("definition", definition)
.add("encryptionConfiguration", encryptionConfiguration)
.add("labels", labels)
.add("resourceTags", resourceTags)
.add("requirePartitionFilter", requirePartitionFilter)
.add("defaultCollation", defaultCollation)
.add("cloneDefinition", cloneDefinition)
.add("tableConstraints", tableConstraints)
.toString();
}
@Override
public int hashCode() {
return Objects.hash(tableId);
}
@Override
public boolean equals(Object obj) {
return obj == this
|| obj != null
&& obj.getClass().equals(TableInfo.class)
&& Objects.equals(toPb(), ((TableInfo) obj).toPb());
}
/**
* Returns a builder for a {@code TableInfo} object given table identity and definition. Use
* {@link StandardTableDefinition} to create simple BigQuery table. Use {@link ViewDefinition} to
* create a BigQuery view. Use {@link ExternalTableDefinition} to create a BigQuery a table backed
* by external data.
*/
public static Builder newBuilder(TableId tableId, TableDefinition definition) {
return new BuilderImpl().setTableId(tableId).setDefinition(definition);
}
/**
* Returns a {@code TableInfo} object given table identity and definition. Use {@link
* StandardTableDefinition} to create simple BigQuery table. Use {@link ViewDefinition} to create
* a BigQuery view. Use {@link ExternalTableDefinition} to create a BigQuery a table backed by
* external data.
*/
public static TableInfo of(TableId tableId, TableDefinition definition) {
return newBuilder(tableId, definition).build();
}
TableInfo setProjectId(String projectId) {
if (Strings.isNullOrEmpty(getTableId().getProject())) {
return toBuilder().setTableId(getTableId().setProjectId(projectId)).build();
}
return this;
}
Table toPb() {
Table tablePb = definition.toPb();
tablePb.setTableReference(tableId.toPb());
if (lastModifiedTime != null) {
tablePb.setLastModifiedTime(BigInteger.valueOf(lastModifiedTime));
}
tablePb.setCreationTime(creationTime);
tablePb.setDescription(description);
tablePb.setEtag(etag);
tablePb.setExpirationTime(expirationTime);
tablePb.setFriendlyName(friendlyName);
tablePb.setId(generatedId);
tablePb.setSelfLink(selfLink);
if (encryptionConfiguration != null) {
tablePb.setEncryptionConfiguration(encryptionConfiguration.toPb());
}
tablePb.setLabels(labels.toPb());
tablePb.setResourceTags(resourceTags.toPb());
tablePb.setRequirePartitionFilter(requirePartitionFilter);
if (defaultCollation != null) {
tablePb.setDefaultCollation(defaultCollation);
}
if (cloneDefinition != null) {
tablePb.setCloneDefinition(cloneDefinition.toPb());
}
if (tableConstraints != null) {
tablePb.setTableConstraints(tableConstraints.toPb());
}
return tablePb;
}
static TableInfo fromPb(Table tablePb) {
return new BuilderImpl(tablePb).build();
}
private static String getFieldAsString(Object field) {
return field == null ? "null" : field.toString();
}
protected Attributes getOtelAttributes() {
return Attributes.builder()
.putAll(this.getTableId().getOtelAttributes())
.put("bq.table.creation_time", getFieldAsString(this.getCreationTime()))
.put("bq.table.expiration_time", getFieldAsString(this.getExpirationTime()))
.put("bq.table.last_modified_time", getFieldAsString(this.getLastModifiedTime()))
.put("bq.table.num_bytes", getFieldAsString(this.getNumBytes()))
.put("bq.table.num_rows", getFieldAsString(this.getNumRows()))
.build();
}
}