Skip to content

Commit 35e0774

Browse files
authored
feat(bigquery): support managed iceberg tables (#11931)
This CL plumbs in the new configuration object to configured managed tables for apache iceberg.
1 parent df2bd94 commit 35e0774

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

bigquery/table.go

+77
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ type TableMetadata struct {
164164
// where 12345 is parent id. The value is the friendly short name of the
165165
// tag value, e.g. "production".
166166
ResourceTags map[string]string
167+
168+
// Specifies the configuration of a BigQuery table for Apache Iceberg (formerly BigLake Managed Table).
169+
BigLakeConfiguration *BigLakeConfiguration
167170
}
168171

169172
// TableConstraints defines the primary key and foreign key of a table.
@@ -380,6 +383,71 @@ func bqToMaterializedViewDefinition(q *bq.MaterializedViewDefinition) *Materiali
380383
}
381384
}
382385

386+
// BigLakeFileFormat represents the file format for Managed Tables for Apache Iceberg.
387+
type BigLakeFileFormat string
388+
389+
var (
390+
// UnspecifiedBigLakeFileFormat represents the default value.
391+
UnspecifiedBigLakeFileFormat BigLakeFileFormat = "FILE_FORMAT_UNSPECIFIED"
392+
// ParquetBigLakeFileFormat represents Apache Parquet Format.
393+
ParquetBigLakeFileFormat BigLakeFileFormat = "PARQUET"
394+
)
395+
396+
// BigLakeTableFormat represents the table metadata format for Managed Tables for Apache Iceberg.
397+
type BigLakeTableFormat string
398+
399+
var (
400+
// UnspecifiedBigLakeTableFormat represents the default value.
401+
UnspecifiedBigLakeTableFormat BigLakeTableFormat = "TABLE_FORMAT_UNSPECIFIED"
402+
// IcebergBigLakeTableFormat represent Apache Iceberg Format.
403+
IcebergBigLakeTableFormat BigLakeTableFormat = "ICEBERG"
404+
)
405+
406+
// BigLakeConfiguration is used to configure aspects of BigQuery tables for
407+
// Apache Iceberg (previously known as BigLake managed tables).
408+
type BigLakeConfiguration struct {
409+
// Optional. The connection specifying the credentials to be used to read and
410+
// write to external storage, such as Cloud Storage. The connection_id can
411+
// have the form `{project}.{location}.{connection_id}` or
412+
// `projects/{project}/locations/{location}/connections/{connection_id}".
413+
ConnectionID string
414+
415+
// Optional. The fully qualified location prefix of the external folder where
416+
// table data is stored. The '*' wildcard character is not allowed. The URI
417+
// should be in the format `gs://bucket/path_to_table/`
418+
StorageURI string
419+
420+
// Optional. The file format the table data is stored in.
421+
FileFormat BigLakeFileFormat
422+
423+
// Optional. The table format the metadata only snapshots are stored in.
424+
TableFormat BigLakeTableFormat
425+
}
426+
427+
func (blc *BigLakeConfiguration) toBQ() *bq.BigLakeConfiguration {
428+
if blc == nil {
429+
return nil
430+
}
431+
return &bq.BigLakeConfiguration{
432+
ConnectionId: blc.ConnectionID,
433+
StorageUri: blc.StorageURI,
434+
FileFormat: string(blc.FileFormat),
435+
TableFormat: string(blc.TableFormat),
436+
}
437+
}
438+
439+
func bqToBigLakeConfiguration(in *bq.BigLakeConfiguration) *BigLakeConfiguration {
440+
if in == nil {
441+
return nil
442+
}
443+
return &BigLakeConfiguration{
444+
ConnectionID: in.ConnectionId,
445+
StorageURI: in.StorageUri,
446+
FileFormat: BigLakeFileFormat(in.FileFormat),
447+
TableFormat: BigLakeTableFormat(in.TableFormat),
448+
}
449+
}
450+
383451
// SnapshotDefinition provides metadata related to the origin of a snapshot.
384452
type SnapshotDefinition struct {
385453

@@ -769,6 +837,7 @@ func (tm *TableMetadata) toBQ() (*bq.Table, error) {
769837
t.RequirePartitionFilter = tm.RequirePartitionFilter
770838
t.SnapshotDefinition = tm.SnapshotDefinition.toBQ()
771839
t.CloneDefinition = tm.CloneDefinition.toBQ()
840+
t.BiglakeConfiguration = tm.BigLakeConfiguration.toBQ()
772841

773842
if !validExpiration(tm.ExpirationTime) {
774843
return nil, fmt.Errorf("invalid expiration time: %v.\n"+
@@ -917,6 +986,7 @@ func bqToTableMetadata(t *bq.Table, c *Client) (*TableMetadata, error) {
917986
RequirePartitionFilter: t.RequirePartitionFilter,
918987
SnapshotDefinition: bqToSnapshotDefinition(t.SnapshotDefinition, c),
919988
CloneDefinition: bqToCloneDefinition(t.CloneDefinition, c),
989+
BigLakeConfiguration: bqToBigLakeConfiguration(t.BiglakeConfiguration),
920990
}
921991
if t.MaterializedView != nil {
922992
md.MaterializedView = bqToMaterializedViewDefinition(t.MaterializedView)
@@ -1145,6 +1215,10 @@ func (tm *TableMetadataToUpdate) toBQ() (*bq.Table, error) {
11451215
}
11461216
forceSend("ResourceTags")
11471217
}
1218+
if tm.BigLakeConfiguration != nil {
1219+
t.BiglakeConfiguration = tm.BigLakeConfiguration.toBQ()
1220+
forceSend("BigLakeConfiguration")
1221+
}
11481222
labels, forces, nulls := tm.update()
11491223
t.Labels = labels
11501224
t.ForceSendFields = append(t.ForceSendFields, forces...)
@@ -1239,6 +1313,9 @@ type TableMetadataToUpdate struct {
12391313
// tag value, e.g. "production".
12401314
ResourceTags map[string]string
12411315

1316+
// Update the configuration of a BigQuery table for Apache Iceberg (formerly BigLake Managed Table).
1317+
BigLakeConfiguration *BigLakeConfiguration
1318+
12421319
labelUpdater
12431320
}
12441321

bigquery/table_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ func TestBQToTableMetadata(t *testing.T) {
102102
"key1": "val1",
103103
"key2": "val2",
104104
},
105+
BiglakeConfiguration: &bq.BigLakeConfiguration{
106+
ConnectionId: "bigconn",
107+
StorageUri: "biguri",
108+
FileFormat: "PARQUET",
109+
TableFormat: "ICEBERG",
110+
},
105111
},
106112
&TableMetadata{
107113
Description: "desc",
@@ -168,6 +174,12 @@ func TestBQToTableMetadata(t *testing.T) {
168174
"key1": "val1",
169175
"key2": "val2",
170176
},
177+
BigLakeConfiguration: &BigLakeConfiguration{
178+
ConnectionID: "bigconn",
179+
StorageURI: "biguri",
180+
FileFormat: ParquetBigLakeFileFormat,
181+
TableFormat: IcebergBigLakeTableFormat,
182+
},
171183
},
172184
},
173185
} {
@@ -208,6 +220,12 @@ func TestTableMetadataToBQ(t *testing.T) {
208220
"key1": "val1",
209221
"key2": "val2",
210222
},
223+
BigLakeConfiguration: &BigLakeConfiguration{
224+
ConnectionID: "bigconn",
225+
StorageURI: "biguri",
226+
FileFormat: ParquetBigLakeFileFormat,
227+
TableFormat: IcebergBigLakeTableFormat,
228+
},
211229
},
212230
&bq.Table{
213231
FriendlyName: "n",
@@ -228,6 +246,12 @@ func TestTableMetadataToBQ(t *testing.T) {
228246
"key1": "val1",
229247
"key2": "val2",
230248
},
249+
BiglakeConfiguration: &bq.BigLakeConfiguration{
250+
ConnectionId: "bigconn",
251+
StorageUri: "biguri",
252+
FileFormat: "PARQUET",
253+
TableFormat: "ICEBERG",
254+
},
231255
},
232256
},
233257
{

0 commit comments

Comments
 (0)