Content-Length: 454308 | pFad | https://github.com/googleapis/java-bigquery/commit/f1ebd5be5877a68f76efafc30e3b5b0763f343c5

28 feat: add max staleness to ExternalTableDefinition (#3499) · googleapis/java-bigquery@f1ebd5b · GitHub
Skip to content

Commit f1ebd5b

Browse files
authored
feat: add max staleness to ExternalTableDefinition (#3499)
* feat: add max staleness TODO: Remove the manual testing anchors * test: add max staleness to ExternalTableDefinition * Format fix * Remove unintentional changes
1 parent 4153057 commit f1ebd5b

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ public Builder setMetadataCacheMode(String metadataCacheMode) {
200200

201201
abstract Builder setMetadataCacheModeInner(String metadataCacheMode);
202202

203+
/**
204+
* [Optional] Metadata Cache Mode for the table. Set this to enable caching of metadata from
205+
* external data source.
206+
*
207+
* @see <a
208+
* href="https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#resource:-table">
209+
* MaxStaleness</a>
210+
*/
211+
public Builder setMaxStaleness(String maxStaleness) {
212+
return setMaxStalenessInner(maxStaleness);
213+
}
214+
215+
abstract Builder setMaxStalenessInner(String maxStaleness);
216+
203217
/** Creates an {@code ExternalTableDefinition} object. */
204218
@Override
205219
public abstract ExternalTableDefinition build();
@@ -305,6 +319,22 @@ public String getMetadataCacheMode() {
305319
@Nullable
306320
abstract String getMetadataCacheModeInner();
307321

322+
/**
323+
* Returns the maximum staleness of data that could be returned when the table is queried.
324+
* Staleness encoded as a string encoding of sql IntervalValue type.
325+
*
326+
* @see <a
327+
* href="hhttps://cloud.google.com/bigquery/docs/reference/rest/v2/tables#resource:-table">
328+
* MaxStaleness</a>
329+
*/
330+
@Nullable
331+
public String getMaxStaleness() {
332+
return getMaxStalenessInner();
333+
}
334+
335+
@Nullable
336+
abstract String getMaxStalenessInner();
337+
308338
/**
309339
* Returns the source format, and possibly some parsing options, of the external data. Supported
310340
* formats are {@code CSV} and {@code NEWLINE_DELIMITED_JSON}.
@@ -351,6 +381,9 @@ public HivePartitioningOptions getHivePartitioningOptions() {
351381
com.google.api.services.bigquery.model.Table toPb() {
352382
Table tablePb = super.toPb();
353383
tablePb.setExternalDataConfiguration(toExternalDataConfigurationPb());
384+
if (getMaxStaleness() != null) {
385+
tablePb.setMaxStaleness(getMaxStaleness());
386+
}
354387
return tablePb;
355388
}
356389

@@ -616,6 +649,9 @@ static ExternalTableDefinition fromPb(Table tablePb) {
616649
if (externalDataConfiguration.getMetadataCacheMode() != null) {
617650
builder.setMetadataCacheMode(externalDataConfiguration.getMetadataCacheMode());
618651
}
652+
if (tablePb.getMaxStaleness() != null) {
653+
builder.setMaxStaleness(tablePb.getMaxStaleness());
654+
}
619655
}
620656
return builder.build();
621657
}

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ExternalTableDefinitionTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public class ExternalTableDefinitionTest {
5959
.setSourceUriPrefix(SOURCE_URIS.get(0))
6060
.build();
6161
private static final String OBJECT_METADATA = "SIMPLE";
62-
6362
private static final String METADATA_CACHE_MODE = "AUTOMATIC";
63+
private static final String MAX_STALENESS = "INTERVAL 15 MINUTE";
6464
private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION =
6565
ExternalTableDefinition.newBuilder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS)
6666
.setFileSetSpecType("FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH")
@@ -73,6 +73,7 @@ public class ExternalTableDefinitionTest {
7373
.setHivePartitioningOptions(HIVE_PARTITIONING_OPTIONS)
7474
.setObjectMetadata(OBJECT_METADATA)
7575
.setMetadataCacheMode(METADATA_CACHE_MODE)
76+
.setMaxStaleness(MAX_STALENESS)
7677
.build();
7778

7879
private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION_AVRO =
@@ -174,5 +175,6 @@ private void compareExternalTableDefinition(
174175
assertEquals(expected.getHivePartitioningOptions(), value.getHivePartitioningOptions());
175176
assertEquals(expected.getObjectMetadata(), value.getObjectMetadata());
176177
assertEquals(expected.getMetadataCacheMode(), value.getMetadataCacheMode());
178+
assertEquals(expected.getMaxStaleness(), value.getMaxStaleness());
177179
}
178180
}

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,9 +2111,13 @@ public void testCreateAndGetTableWithSelectedField() {
21112111
public void testCreateExternalTable() throws InterruptedException {
21122112
String tableName = "test_create_external_table";
21132113
TableId tableId = TableId.of(DATASET, tableName);
2114+
21142115
ExternalTableDefinition externalTableDefinition =
21152116
ExternalTableDefinition.of(
2116-
"gs://" + BUCKET + "/" + JSON_LOAD_FILE, TABLE_SCHEMA, FormatOptions.json());
2117+
"gs://" + BUCKET + "/" + JSON_LOAD_FILE, TABLE_SCHEMA, FormatOptions.json())
2118+
.toBuilder()
2119+
.setMaxStaleness("INTERVAL 15 MINUTE")
2120+
.build();
21172121
TableInfo tableInfo = TableInfo.of(tableId, externalTableDefinition);
21182122
Table createdTable = bigquery.create(tableInfo);
21192123
assertNotNull(createdTable);

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/java-bigquery/commit/f1ebd5be5877a68f76efafc30e3b5b0763f343c5

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy