Skip to content

Commit 1ecb128

Browse files
add support for delta lake for big tables (#11215) (#18915)
[upstream:c015e3ff8450ee011bb290f13683991e18ecb109] Signed-off-by: Modular Magician <[email protected]>
1 parent 0f71c35 commit 1ecb128

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

.changelog/11215.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigquery: added support for value `DELTA_LAKE` to `source_format` in `google_bigquery_table` resource
3+
```

google/services/bigquery/resource_bigquery_table.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func ResourceBigQueryTable() *schema.Resource {
517517
Optional: true,
518518
Description: `Please see sourceFormat under ExternalDataConfiguration in Bigquery's public API documentation (https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#externaldataconfiguration) for supported formats. To use "GOOGLE_SHEETS" the scopes must include "googleapis.com/auth/drive.readonly".`,
519519
ValidateFunc: validation.StringInSlice([]string{
520-
"CSV", "GOOGLE_SHEETS", "NEWLINE_DELIMITED_JSON", "AVRO", "ICEBERG", "DATASTORE_BACKUP", "PARQUET", "ORC", "BIGTABLE",
520+
"CSV", "GOOGLE_SHEETS", "NEWLINE_DELIMITED_JSON", "AVRO", "ICEBERG", "DATASTORE_BACKUP", "PARQUET", "ORC", "BIGTABLE", "DELTA_LAKE",
521521
}, false),
522522
},
523523
// SourceURIs [Required] The fully-qualified URIs that point to your data in Google Cloud.

google/services/bigquery/resource_bigquery_table_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,26 @@ func TestAccBigQueryTable_MaterializedView_NonIncremental_basic(t *testing.T) {
642642
})
643643
}
644644

645+
func TestAccBigQueryExternalDataTable_deltaLake(t *testing.T) {
646+
t.Parallel()
647+
648+
bucketName := acctest.TestBucketName(t)
649+
650+
datasetID := fmt.Sprintf("tf_test_%s", acctest.RandString(t, 10))
651+
tableID := fmt.Sprintf("tf_test_%s", acctest.RandString(t, 10))
652+
653+
acctest.VcrTest(t, resource.TestCase{
654+
PreCheck: func() { acctest.AccTestPreCheck(t) },
655+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
656+
CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t),
657+
Steps: []resource.TestStep{
658+
{
659+
Config: testAccBigQueryTableFromGCSDeltaLake(datasetID, tableID, bucketName),
660+
},
661+
},
662+
})
663+
}
664+
645665
func TestAccBigQueryExternalDataTable_parquet(t *testing.T) {
646666
t.Parallel()
647667

@@ -2644,6 +2664,44 @@ resource "google_bigquery_table" "test" {
26442664
`, connectionID, datasetID, bucketName, objectName, tableID, metadataCacheMode, maxStaleness)
26452665
}
26462666

2667+
func testAccBigQueryTableFromGCSDeltaLake(datasetID, tableID, bucketName string) string {
2668+
return fmt.Sprintf(`
2669+
resource "google_bigquery_dataset" "test" {
2670+
dataset_id = "%s"
2671+
}
2672+
2673+
resource "google_storage_bucket" "test" {
2674+
name = "%s"
2675+
location = "US"
2676+
force_destroy = true
2677+
}
2678+
2679+
# Setup Empty Delta Lake table in Bucket.
2680+
2681+
// Upload Metadata File.
2682+
resource "google_storage_bucket_object" "metadata" {
2683+
name = "_delta_log/00000000000000000000.json"
2684+
source = "./test-fixtures/simple/metadata/00000000000000000000.json"
2685+
bucket = google_storage_bucket.test.name
2686+
}
2687+
2688+
resource "google_bigquery_table" "test" {
2689+
deletion_protection = false
2690+
table_id = "%s"
2691+
dataset_id = google_bigquery_dataset.test.dataset_id
2692+
external_data_configuration {
2693+
autodetect = true
2694+
source_format = "DELTA_LAKE"
2695+
reference_file_schema_uri = "gs://${google_storage_bucket.test.name}/${google_storage_bucket_object.metadata.name}"
2696+
2697+
source_uris = [
2698+
"gs://${google_storage_bucket.test.name}/*",
2699+
]
2700+
}
2701+
}
2702+
`, datasetID, bucketName, tableID)
2703+
}
2704+
26472705
func testAccBigQueryTableFromGCSParquet(datasetID, tableID, bucketName, objectName string) string {
26482706
return fmt.Sprintf(`
26492707
resource "google_bigquery_dataset" "test" {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{"commitInfo":{"timestamp":1706278148531,"operation":"WRITE","operationParameters":{"mode":"Overwrite","partitionBy":"[\"country\"]"},"isolationLevel":"Serializable","isBlindAppend":false,"operationMetrics":{"numFiles":"3","numOutputRows":"5","numOutputBytes":"3045"},"engineInfo":"Apache-Spark/3.4.0 Delta-Lake/2.4.0","txnId":"1cbc9537-63eb-4799-8647-2d947ae8fa41"}}
2+
{"protocol":{"minReaderVersion":1,"minWriterVersion":2}}
3+
{"metaData":{"id":"1f110132-a652-4be9-815e-348f294515cf","format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"first_name\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"last_name\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"country\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"continent\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":["country"],"configuration":{},"createdTime":1706278146762}}
4+
{"add":{"path":"country=Argentina/part-00000-8d0390a3-f797-4265-b9c2-da1c941680a3.c000.snappy.parquet","partitionValues":{"country":"Argentina"},"size":1018,"modificationTime":1706278148083,"dataChange":true,"stats":"{\"numRecords\":1,\"minValues\":{\"first_name\":\"Ernesto\",\"last_name\":\"Guevara\",\"continent\":\"NaN\"},\"maxValues\":{\"first_name\":\"Ernesto\",\"last_name\":\"Guevara\",\"continent\":\"NaN\"},\"nullCount\":{\"first_name\":0,\"last_name\":0,\"continent\":0}}"}}
5+
{"add":{"path":"country=China/part-00000-88fba1af-b28d-4303-9c85-9a97be631d40.c000.snappy.parquet","partitionValues":{"country":"China"},"size":1002,"modificationTime":1706278148138,"dataChange":true,"stats":"{\"numRecords\":2,\"minValues\":{\"first_name\":\"Bruce\",\"last_name\":\"Lee\",\"continent\":\"Asia\"},\"maxValues\":{\"first_name\":\"Jack\",\"last_name\":\"Ma\",\"continent\":\"Asia\"},\"nullCount\":{\"first_name\":0,\"last_name\":0,\"continent\":0}}"}}
6+
{"add":{"path":"country=Germany/part-00000-030076e1-5ec9-47c2-830a-1569f823b6ee.c000.snappy.parquet","partitionValues":{"country":"Germany"},"size":1025,"modificationTime":1706278148185,"dataChange":true,"stats":"{\"numRecords\":2,\"minValues\":{\"first_name\":\"Soraya\",\"last_name\":\"Jala\",\"continent\":\"NaN\"},\"maxValues\":{\"first_name\":\"Wolfgang\",\"last_name\":\"Manche\",\"continent\":\"NaN\"},\"nullCount\":{\"first_name\":0,\"last_name\":0,\"continent\":0}}"}}

0 commit comments

Comments
 (0)