Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2814dc4

Browse files
PhongChuonggcf-owl-bot[bot]
andauthoredJun 19, 2024
feat: add MetadataCacheMode to ExternalTableDefinition (#3351)
* feat: add MetadataCacheMode to ExternalTableDefinition * Update comment * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 4b9613d commit 2814dc4

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed
 

‎README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ If you are using Maven without the BOM, add this to your dependencies:
5353
If you are using Gradle 5.x or later, add this to your dependencies:
5454

5555
```Groovy
56-
implementation platform('com.google.cloud:libraries-bom:26.40.0')
56+
implementation platform('com.google.cloud:libraries-bom:26.41.0')
5757
5858
implementation 'com.google.cloud:google-cloud-bigquery'
5959
```
6060
If you are using Gradle without BOM, add this to your dependencies:
6161

6262
```Groovy
63-
implementation 'com.google.cloud:google-cloud-bigquery:2.40.2'
63+
implementation 'com.google.cloud:google-cloud-bigquery:2.40.3'
6464
```
6565

6666
If you are using SBT, add this to your dependencies:
6767

6868
```Scala
69-
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.40.2"
69+
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.40.3"
7070
```
7171
<!-- {x-version-update-end} -->
7272

@@ -351,7 +351,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
351351
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquery/java11.html
352352
[stability-image]: https://img.shields.io/badge/stability-stable-green
353353
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquery.svg
354-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.40.2
354+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.40.3
355355
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
356356
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
357357
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

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

+40
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ public Builder setObjectMetadata(String objectMetadata) {
186186

187187
abstract Builder setObjectMetadataInner(String objectMetadata);
188188

189+
/**
190+
* [Optional] Metadata Cache Mode for the table. Set this to enable caching of metadata from
191+
* external data source.
192+
*
193+
* @see <a
194+
* href="https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#metadatacachemode">
195+
* MetadataCacheMode</a>
196+
*/
197+
public Builder setMetadataCacheMode(String metadataCacheMode) {
198+
return setMetadataCacheModeInner(metadataCacheMode);
199+
}
200+
201+
abstract Builder setMetadataCacheModeInner(String metadataCacheMode);
202+
189203
/** Creates an {@code ExternalTableDefinition} object. */
190204
@Override
191205
public abstract ExternalTableDefinition build();
@@ -276,6 +290,21 @@ public String getObjectMetadata() {
276290
@Nullable
277291
abstract String getObjectMetadataInner();
278292

293+
/**
294+
* Returns the metadata cache mode.
295+
*
296+
* @see <a
297+
* href="https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#metadatacachemode">
298+
* MetadataCacheMode</a>
299+
*/
300+
@Nullable
301+
public String getMetadataCacheMode() {
302+
return getMetadataCacheModeInner();
303+
}
304+
305+
@Nullable
306+
abstract String getMetadataCacheModeInner();
307+
279308
/**
280309
* Returns the source format, and possibly some parsing options, of the external data. Supported
281310
* formats are {@code CSV} and {@code NEWLINE_DELIMITED_JSON}.
@@ -387,6 +416,10 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toExternalDataC
387416
externalConfigurationPb.setObjectMetadata(getObjectMetadata());
388417
}
389418

419+
if (getMetadataCacheMode() != null) {
420+
externalConfigurationPb.setMetadataCacheMode(getMetadataCacheMode());
421+
}
422+
390423
return externalConfigurationPb;
391424
}
392425

@@ -580,6 +613,9 @@ static ExternalTableDefinition fromPb(Table tablePb) {
580613
if (externalDataConfiguration.getObjectMetadata() != null) {
581614
builder.setObjectMetadata(externalDataConfiguration.getObjectMetadata());
582615
}
616+
if (externalDataConfiguration.getMetadataCacheMode() != null) {
617+
builder.setMetadataCacheMode(externalDataConfiguration.getMetadataCacheMode());
618+
}
583619
}
584620
return builder.build();
585621
}
@@ -647,6 +683,10 @@ static ExternalTableDefinition fromExternalDataConfiguration(
647683
builder.setObjectMetadata(externalDataConfiguration.getObjectMetadata());
648684
}
649685

686+
if (externalDataConfiguration.getMetadataCacheMode() != null) {
687+
builder.setMetadataCacheMode(externalDataConfiguration.getMetadataCacheMode());
688+
}
689+
650690
return builder.build();
651691
}
652692
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class ExternalTableDefinitionTest {
5959
.setSourceUriPrefix(SOURCE_URIS.get(0))
6060
.build();
6161
private static final String OBJECT_METADATA = "SIMPLE";
62+
63+
private static final String METADATA_CACHE_MODE = "AUTOMATIC";
6264
private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION =
6365
ExternalTableDefinition.newBuilder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS)
6466
.setFileSetSpecType("FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH")
@@ -70,6 +72,7 @@ public class ExternalTableDefinitionTest {
7072
.setAutodetect(AUTODETECT)
7173
.setHivePartitioningOptions(HIVE_PARTITIONING_OPTIONS)
7274
.setObjectMetadata(OBJECT_METADATA)
75+
.setMetadataCacheMode(METADATA_CACHE_MODE)
7376
.build();
7477

7578
private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION_AVRO =
@@ -170,5 +173,6 @@ private void compareExternalTableDefinition(
170173
assertEquals(expected.getAutodetect(), value.getAutodetect());
171174
assertEquals(expected.getHivePartitioningOptions(), value.getHivePartitioningOptions());
172175
assertEquals(expected.getObjectMetadata(), value.getObjectMetadata());
176+
assertEquals(expected.getMetadataCacheMode(), value.getMetadataCacheMode());
173177
}
174178
}

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

+26
Original file line numberDiff line numberDiff line change
@@ -6832,6 +6832,32 @@ public void testExternalTableMetadataCachingNotEnable() throws InterruptedExcept
68326832
assertTrue(remoteTable.delete());
68336833
}
68346834

6835+
@Test
6836+
public void testExternalMetadataCacheModeFailForNonBiglake() {
6837+
// Validate that MetadataCacheMode is passed to the backend.
6838+
// TODO: Enhance this test after BigLake testing infrastructure is inplace.
6839+
String tableName = "test_metadata_cache_mode_fail_for_non_biglake";
6840+
TableId tableId = TableId.of(DATASET, tableName);
6841+
ExternalTableDefinition externalTableDefinition =
6842+
ExternalTableDefinition.newBuilder(
6843+
"gs://" + BUCKET + "/" + JSON_LOAD_FILE, TABLE_SCHEMA, FormatOptions.json())
6844+
.setMetadataCacheMode("AUTOMATIC")
6845+
.build();
6846+
TableInfo tableInfo = TableInfo.of(tableId, externalTableDefinition);
6847+
6848+
try {
6849+
bigquery.create(tableInfo);
6850+
fail("BigQueryException was expected");
6851+
} catch (BigQueryException e) {
6852+
BigQueryError error = e.getError();
6853+
assertNotNull(error);
6854+
assertEquals("invalid", error.getReason());
6855+
assertThat(
6856+
e.getMessage().contains("metadataCacheMode provided for non BigLake external table"))
6857+
.isTrue();
6858+
}
6859+
}
6860+
68356861
@Test
68366862
public void testObjectTable() throws InterruptedException {
68376863
String tableName = "test_object_table";

0 commit comments

Comments
 (0)
Failed to load comments.