Skip to content

Commit 1d660fa

Browse files
feat: Add BigLakeConfiguration Property in StandardTableDefinition.java (#2916)
* Added BigLakeConfiguration in standard table defenition * feat: Add BigLakeConfiguration Property in StandardTableDefinition.java * feat: Update copyright dates to 2023 * feat: Removed bigstore and gs:/ from docs * feat: Renamed Biglake to BigLake * feat: Adding difference entry to resolve clirr error * feat: Refactored formatting to comply with project rules * 🦉 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 b82692a commit 1d660fa

File tree

5 files changed

+234
-0
lines changed

5 files changed

+234
-0
lines changed

google-cloud-bigquery/clirr-ignored-differences.xml

+5
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,9 @@
109109
<className>com/google/cloud/bigquery/DatasetInfo*</className>
110110
<method>*setExternalDatasetReference(*)</method>
111111
</difference>
112+
<difference>
113+
<differenceType>7013</differenceType>
114+
<className>com/google/cloud/bigquery/StandardTableDefinition*</className>
115+
<method>*BigLakeConfiguration(*)</method>
116+
</difference>
112117
</differences>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.bigquery;
18+
19+
import com.google.auto.value.AutoValue;
20+
import java.io.Serializable;
21+
22+
@AutoValue
23+
public abstract class BigLakeConfiguration implements Serializable {
24+
25+
private static final long serialVersionUID = -5951589238459622025L;
26+
27+
/**
28+
* Credential reference for accessing external storage system. Normalized as
29+
* project_id.location_id.connection_id.
30+
*
31+
* @return value or {@code null} for none
32+
*/
33+
public abstract String getConnectionId();
34+
35+
/**
36+
* Open source file format that the table data is stored in. Currently only PARQUET is supported.
37+
*
38+
* @return value or {@code null} for none
39+
*/
40+
public abstract String getFileFormat();
41+
42+
/**
43+
* Fully qualified location prefix of the external folder where data is stored. Starts with
44+
* "gs://" ends with "/". Does not contain "*".
45+
*
46+
* @return value or {@code null} for none
47+
*/
48+
public abstract String getStorageUri();
49+
50+
/**
51+
* Open source file format that the table data is stored in. Currently only PARQUET is supported.
52+
*
53+
* @return value or {@code null} for none
54+
*/
55+
public abstract String getTableFormat();
56+
57+
public static Builder newBuilder() {
58+
return new AutoValue_BigLakeConfiguration.Builder();
59+
}
60+
61+
public abstract Builder toBuilder();
62+
63+
@AutoValue.Builder
64+
public abstract static class Builder {
65+
/**
66+
* [Required] Required and immutable. Credential reference for accessing external storage
67+
* system. Normalized as project_id.location_id.connection_id.
68+
*
69+
* @param connectionId connectionId or {@code null} for none
70+
*/
71+
public abstract Builder setConnectionId(String connectionId);
72+
73+
/**
74+
* [Required] Required and immutable. Open source file format that the table data is stored in.
75+
* Currently only PARQUET is supported.
76+
*
77+
* @param fileFormat fileFormat or {@code null} for none
78+
*/
79+
public abstract Builder setFileFormat(String fileFormat);
80+
81+
/**
82+
* [Required] Required and immutable. Fully qualified location prefix of the external folder
83+
* where data is stored. Starts with "gs://" and ends with "/". Does not contain "*".
84+
*
85+
* @param storageUri storageUri or {@code null} for none
86+
*/
87+
public abstract Builder setStorageUri(String storageUri);
88+
89+
/**
90+
* [Required] Required and immutable. Open source file format that the table data is stored in.
91+
* Currently only PARQUET is supported.
92+
*
93+
* @param tableFormat tableFormat or {@code null} for none
94+
*/
95+
public abstract Builder setTableFormat(String tableFormat);
96+
97+
public abstract BigLakeConfiguration build();
98+
}
99+
100+
com.google.api.services.bigquery.model.BigLakeConfiguration toPb() {
101+
com.google.api.services.bigquery.model.BigLakeConfiguration biglakeConfiguration =
102+
new com.google.api.services.bigquery.model.BigLakeConfiguration();
103+
biglakeConfiguration.setConnectionId(getConnectionId());
104+
biglakeConfiguration.setFileFormat(getFileFormat());
105+
biglakeConfiguration.setStorageUri(getStorageUri());
106+
biglakeConfiguration.setTableFormat(getTableFormat());
107+
108+
return biglakeConfiguration;
109+
}
110+
111+
static BigLakeConfiguration fromPb(
112+
com.google.api.services.bigquery.model.BigLakeConfiguration biglakeConfigurationPb) {
113+
return newBuilder()
114+
.setConnectionId(biglakeConfigurationPb.getConnectionId())
115+
.setFileFormat(biglakeConfigurationPb.getFileFormat())
116+
.setStorageUri(biglakeConfigurationPb.getStorageUri())
117+
.setTableFormat(biglakeConfigurationPb.getTableFormat())
118+
.build();
119+
}
120+
}

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

+21
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ public abstract static class Builder
177177

178178
public abstract Builder setTableConstraints(TableConstraints tableConstraints);
179179

180+
/**
181+
* Set the configuration of a BigLake managed table. If not set, the table is not a BigLake
182+
* managed table.
183+
*/
184+
public abstract Builder setBigLakeConfiguration(BigLakeConfiguration biglakeConfiguration);
185+
180186
/** Creates a {@code StandardTableDefinition} object. */
181187
public abstract StandardTableDefinition build();
182188
}
@@ -300,6 +306,13 @@ public abstract static class Builder
300306
@Nullable
301307
public abstract TableConstraints getTableConstraints();
302308

309+
/**
310+
* [Optional] Specifies the configuration of a BigLake managed table. The value may be {@code
311+
* null}.
312+
*/
313+
@Nullable
314+
public abstract BigLakeConfiguration getBigLakeConfiguration();
315+
303316
/** Returns a builder for a BigQuery standard table definition. */
304317
public static Builder newBuilder() {
305318
return new AutoValue_StandardTableDefinition.Builder().setType(Type.TABLE);
@@ -348,6 +361,9 @@ Table toPb() {
348361
if (getTableConstraints() != null) {
349362
tablePb.setTableConstraints(getTableConstraints().toPb());
350363
}
364+
if (getBigLakeConfiguration() != null) {
365+
tablePb.setBiglakeConfiguration(getBigLakeConfiguration().toPb());
366+
}
351367
return tablePb;
352368
}
353369

@@ -409,6 +425,11 @@ static StandardTableDefinition fromPb(Table tablePb) {
409425
if (tablePb.getTableConstraints() != null) {
410426
builder.setTableConstraints(TableConstraints.fromPb(tablePb.getTableConstraints()));
411427
}
428+
if (tablePb.getBiglakeConfiguration() != null) {
429+
builder.setBigLakeConfiguration(
430+
BigLakeConfiguration.fromPb(tablePb.getBiglakeConfiguration()));
431+
}
432+
412433
return builder.setNumBytes(tablePb.getNumBytes()).setLocation(tablePb.getLocation()).build();
413434
}
414435
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.bigquery;
18+
19+
import static org.junit.Assert.assertEquals;
20+
21+
import org.junit.Test;
22+
23+
public class BigLakeConfigurationTest {
24+
25+
private static final String STORAGE_URI = "gs://storage-uri";
26+
private static final String FILE_FORMAT = "PARQUET";
27+
private static final String TABLE_FORMAT = "ICEBERG";
28+
private static final String CONNECTION_ID = "us.test-connection";
29+
30+
private static final BigLakeConfiguration BIG_LAKE_CONFIGURATION =
31+
BigLakeConfiguration.newBuilder()
32+
.setStorageUri(STORAGE_URI)
33+
.setFileFormat(FILE_FORMAT)
34+
.setTableFormat(TABLE_FORMAT)
35+
.setConnectionId(CONNECTION_ID)
36+
.build();
37+
private static final com.google.api.services.bigquery.model.BigLakeConfiguration
38+
BIG_LAKE_CONFIGURATION_PB =
39+
new com.google.api.services.bigquery.model.BigLakeConfiguration()
40+
.setStorageUri(STORAGE_URI)
41+
.setFileFormat(FILE_FORMAT)
42+
.setTableFormat(TABLE_FORMAT)
43+
.setConnectionId(CONNECTION_ID);
44+
45+
@Test
46+
public void testToBuilder() {
47+
assertEquals(STORAGE_URI, BIG_LAKE_CONFIGURATION.getStorageUri());
48+
assertEquals(FILE_FORMAT, BIG_LAKE_CONFIGURATION.getFileFormat());
49+
assertEquals(TABLE_FORMAT, BIG_LAKE_CONFIGURATION.getTableFormat());
50+
assertEquals(CONNECTION_ID, BIG_LAKE_CONFIGURATION.getConnectionId());
51+
}
52+
53+
@Test
54+
public void testToPb() {
55+
assertBigLakeConfiguration(BIG_LAKE_CONFIGURATION_PB, BIG_LAKE_CONFIGURATION.toPb());
56+
}
57+
58+
@Test
59+
public void testFromPb() {
60+
assertBigLakeConfiguration(
61+
BIG_LAKE_CONFIGURATION, BigLakeConfiguration.fromPb(BIG_LAKE_CONFIGURATION_PB));
62+
}
63+
64+
private static void assertBigLakeConfiguration(
65+
BigLakeConfiguration expected, BigLakeConfiguration actual) {
66+
assertEquals(expected.getConnectionId(), actual.getConnectionId());
67+
assertEquals(expected.getTableFormat(), actual.getTableFormat());
68+
assertEquals(expected.getStorageUri(), actual.getStorageUri());
69+
assertEquals(expected.getFileFormat(), actual.getFileFormat());
70+
}
71+
72+
private static void assertBigLakeConfiguration(
73+
com.google.api.services.bigquery.model.BigLakeConfiguration expected,
74+
com.google.api.services.bigquery.model.BigLakeConfiguration actual) {
75+
assertEquals(expected.getConnectionId(), actual.getConnectionId());
76+
assertEquals(expected.getTableFormat(), actual.getTableFormat());
77+
assertEquals(expected.getStorageUri(), actual.getStorageUri());
78+
assertEquals(expected.getFileFormat(), actual.getFileFormat());
79+
}
80+
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public class StandardTableDefinitionTest {
6565
TimePartitioning.of(TimePartitioning.Type.DAY, 42);
6666
private static final Clustering CLUSTERING =
6767
Clustering.newBuilder().setFields(ImmutableList.of("Foo", "Bar")).build();
68+
private static final BigLakeConfiguration BIG_LAKE_CONFIGURATION =
69+
BigLakeConfiguration.newBuilder()
70+
.setConnectionId("us.connection-test")
71+
.setTableFormat("ICEBERG")
72+
.setFileFormat("PARQUET")
73+
.setStorageUri("gs://java-bigquery-test/standard-table-def")
74+
.build();
6875
private static final StandardTableDefinition TABLE_DEFINITION =
6976
StandardTableDefinition.newBuilder()
7077
.setLocation(LOCATION)
@@ -82,6 +89,7 @@ public class StandardTableDefinitionTest {
8289
.setSchema(TABLE_SCHEMA)
8390
.setTimePartitioning(TIME_PARTITIONING)
8491
.setClustering(CLUSTERING)
92+
.setBigLakeConfiguration(BIG_LAKE_CONFIGURATION)
8593
.build();
8694

8795
@Test

0 commit comments

Comments
 (0)