From 9aaa049c750b4fd712c72c94aa318caa6178707d Mon Sep 17 00:00:00 2001 From: fpopic Date: Wed, 24 Jun 2020 08:57:16 +0200 Subject: [PATCH 1/5] Add TODO for checking the go library for HOUR support, update description and validation value. --- google/resource_bigquery_table.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/google/resource_bigquery_table.go b/google/resource_bigquery_table.go index 7e723671616..df24d873ecb 100644 --- a/google/resource_bigquery_table.go +++ b/google/resource_bigquery_table.go @@ -336,13 +336,14 @@ func resourceBigQueryTable() *schema.Resource { Description: `Number of milliseconds for which to keep the storage for a partition.`, }, - // Type: [Required] The only type supported is DAY, which will generate - // one partition per day based on data loading time. + // TODO: check https://github.com/googleapis/google-cloud-go/commit/8618bf3d044f4da30b144689b870354c0071cfb0 + // Type: [Required] The supported types are DAY and HOUR, which will generate + // one partition per day or hour based on data loading time. "type": { Type: schema.TypeString, Required: true, - Description: `The only type supported is DAY, which will generate one partition per day based on data loading time.`, - ValidateFunc: validation.StringInSlice([]string{"DAY"}, false), + Description: `The supported types are DAY and HOUR, which will generate one partition per day or hour based on data loading time`, + ValidateFunc: validation.StringInSlice([]string{"DAY", "HOUR"}, false), }, // Field: [Optional] The field used to determine how to create a time-based From 67fc0b9c8a58ce58511d9f673cb658744b7e6a9a Mon Sep 17 00:00:00 2001 From: fpopic Date: Wed, 24 Jun 2020 09:25:09 +0200 Subject: [PATCH 2/5] Remove TODO from code and run gofmt. --- google/resource_bigquery_table.go | 1 - 1 file changed, 1 deletion(-) diff --git a/google/resource_bigquery_table.go b/google/resource_bigquery_table.go index df24d873ecb..71865d3d406 100644 --- a/google/resource_bigquery_table.go +++ b/google/resource_bigquery_table.go @@ -336,7 +336,6 @@ func resourceBigQueryTable() *schema.Resource { Description: `Number of milliseconds for which to keep the storage for a partition.`, }, - // TODO: check https://github.com/googleapis/google-cloud-go/commit/8618bf3d044f4da30b144689b870354c0071cfb0 // Type: [Required] The supported types are DAY and HOUR, which will generate // one partition per day or hour based on data loading time. "type": { From 85e650c086b756f115fff2c23b4b62ffbf52d4b5 Mon Sep 17 00:00:00 2001 From: fpopic Date: Wed, 24 Jun 2020 09:43:26 +0200 Subject: [PATCH 3/5] Test table creation with HOUR instead of DAY. --- google/resource_bigquery_table_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/resource_bigquery_table_test.go b/google/resource_bigquery_table_test.go index eb665179e22..a3161365c8c 100644 --- a/google/resource_bigquery_table_test.go +++ b/google/resource_bigquery_table_test.go @@ -338,7 +338,7 @@ resource "google_bigquery_table" "test" { dataset_id = "${google_bigquery_dataset.test.dataset_id}" time_partitioning { - type = "DAY" + type = "HOUR" field = "ts" } From 4d54a1e8324573b4b15b58d950c1be880f49547c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Popi=C4=87?= Date: Wed, 24 Jun 2020 10:07:50 +0200 Subject: [PATCH 4/5] Update google/resource_bigquery_table.go --- google/resource_bigquery_table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/resource_bigquery_table.go b/google/resource_bigquery_table.go index 71865d3d406..01e92e4e85c 100644 --- a/google/resource_bigquery_table.go +++ b/google/resource_bigquery_table.go @@ -341,7 +341,7 @@ func resourceBigQueryTable() *schema.Resource { "type": { Type: schema.TypeString, Required: true, - Description: `The supported types are DAY and HOUR, which will generate one partition per day or hour based on data loading time`, + Description: `The supported types are DAY and HOUR, which will generate one partition per day or hour based on data loading time.`, ValidateFunc: validation.StringInSlice([]string{"DAY", "HOUR"}, false), }, From 252f98884303b957635d9e6c1f773a2b4b3f62e9 Mon Sep 17 00:00:00 2001 From: fpopic Date: Wed, 24 Jun 2020 12:15:29 +0200 Subject: [PATCH 5/5] Add testAccBigQueryTableHourlyTimePartitioning test. --- google/resource_bigquery_table_test.go | 94 +++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/google/resource_bigquery_table_test.go b/google/resource_bigquery_table_test.go index a3161365c8c..5a6228d3f3b 100644 --- a/google/resource_bigquery_table_test.go +++ b/google/resource_bigquery_table_test.go @@ -20,7 +20,7 @@ func TestAccBigQueryTable_Basic(t *testing.T) { CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccBigQueryTable(datasetID, tableID), + Config: testAccBigQueryTableDailyTimePartitioning(datasetID, tableID), }, { ResourceName: "google_bigquery_table.test", @@ -64,6 +64,37 @@ func TestAccBigQueryTable_Kms(t *testing.T) { }) } +func TestAccBigQueryTable_HourlyTimePartitioning(t *testing.T) { + t.Parallel() + + datasetID := fmt.Sprintf("tf_test_%s", randString(t, 10)) + tableID := fmt.Sprintf("tf_test_%s", randString(t, 10)) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccBigQueryTableHourlyTimePartitioning(datasetID, tableID), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBigQueryTableUpdated(datasetID, tableID), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccBigQueryTable_HivePartitioning(t *testing.T) { t.Parallel() bucketName := testBucketName(t) @@ -261,7 +292,7 @@ func testAccCheckBigQueryTableDestroyProducer(t *testing.T) func(s *terraform.St } } -func testAccBigQueryTable(datasetID, tableID string) string { +func testAccBigQueryTableDailyTimePartitioning(datasetID, tableID string) string { return fmt.Sprintf(` resource "google_bigquery_dataset" "test" { dataset_id = "%s" @@ -318,6 +349,63 @@ EOH `, datasetID, tableID) } +func testAccBigQueryTableHourlyTimePartitioning(datasetID, tableID string) string { + return fmt.Sprintf(` +resource "google_bigquery_dataset" "test" { + dataset_id = "%s" +} + +resource "google_bigquery_table" "test" { + table_id = "%s" + dataset_id = google_bigquery_dataset.test.dataset_id + + time_partitioning { + type = "HOUR" + field = "ts" + require_partition_filter = true + } + clustering = ["some_int", "some_string"] + schema = <