-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
google_bigquery_job: Add support for importing GeoJSON #12423
google_bigquery_job: Add support for importing GeoJSON #12423
Comments
After running a test with both For {
"configuration": {
"jobType": "LOAD",
"load": {
"autodetect": true,
"destinationTable": {
"datasetId": "DATASET",
"projectId": "PROJECT",
"tableId": "TABLE"
},
"jsonExtension": "GEOJSON",
"maxBadRecords": 0,
"sourceFormat": "NEWLINE_DELIMITED_JSON",
"sourceUris": [
"gs://BUCKET/FILE.json"
]
}
}
} For terraform with {
"configuration": {
"jobType": "LOAD",
"load": {
"autodetect": true,
"createDisposition": "CREATE_IF_NEEDED",
"destinationTable": {
"datasetId": "DATASET",
"projectId": "PROJECT",
"tableId": "TABLE"
},
"encoding": "UTF-8",
"sourceFormat": "NEWLINE_DELIMITED_JSON",
"sourceUris": [
"gs://BUCKET/FILE.json"
],
"writeDisposition": "WRITE_TRUNCATE"
}
}
} It seems as if a |
Looking at the API reference documentation for bigquery JobConfigurationLoad, it seems like the Edit: Looking at the REST API schema, that contains "jsonExtension": {
"description": "[Optional] If sourceFormat is set to newline-delimited JSON, indicates whether it should be processed as a JSON variant such as GeoJSON. For a sourceFormat other than JSON, omit this field. If the sourceFormat is newline-delimited JSON: - for newline-delimited GeoJSON: set to GEOJSON.",
"type": "string"
}, |
I'm barely superficially familiar with Go so take it with a pinch of salt, but I think something like this might do the trick: index 3aaca78a2..bd358dbd3 100644
--- a/google/resource_bigquery_job.go
+++ b/google/resource_bigquery_job.go
@@ -451,6 +451,12 @@ CSV: Trailing columns
JSON: Named values that don't match any column names`,
Default: false,
},
+ "json_extension": {
+ Type: schema.TypeString,
+ Optional: true,
+ ForceNew: true,
+ Description: `If sourceFormat is set to newline-delimited JSON, indicates whether it should be processed as a JSON variant such as GeoJSON. For a sourceFormat other than JSON, omit this field. If the sourceFormat is newline-delimited JSON: - for newline-delimited GeoJSON: set to GEOJSON.`,
+ },
"max_bad_records": {
Type: schema.TypeInt,
Optional: true,
@@ -1446,6 +1452,8 @@ func flattenBigQueryJobConfigurationLoad(v interface{}, d *schema.ResourceData,
flattenBigQueryJobConfigurationLoadAllowQuotedNewlines(original["allowQuotedNewlines"], d, config)
transformed["source_format"] =
flattenBigQueryJobConfigurationLoadSourceFormat(original["sourceFormat"], d, config)
+ transformed["json_extension"] =
+ flattenBigQueryJobConfigurationLoadJsonExtension(original["jsonExtension"], d, config)
transformed["allow_jagged_rows"] =
flattenBigQueryJobConfigurationLoadAllowJaggedRows(original["allowJaggedRows"], d, config)
transformed["ignore_unknown_values"] =
@@ -1552,6 +1560,10 @@ func flattenBigQueryJobConfigurationLoadSourceFormat(v interface{}, d *schema.Re
return v
}
+func flattenBigQueryJobConfigurationLoadJsonExtension(v interface{}, d *schema.ResourceData, config *Config) interface{} {
+ return v
+}
+
func flattenBigQueryJobConfigurationLoadAllowJaggedRows(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
@@ -2454,6 +2466,13 @@ func expandBigQueryJobConfigurationLoad(v interface{}, d TerraformResourceData,
transformed["sourceFormat"] = transformedSourceFormat
}
+ transformedJsonExtension, err := expandBigQueryJobConfigurationLoadJsonExtension(original["json_extension"], d, config)
+ if err != nil {
+ return nil, err
+ } else if val := reflect.ValueOf(transformedSourceFormat); val.IsValid() && !isEmptyValue(val) {
+ transformed["jsonExtension"] = transformedJsonExtension
+ }
+
transformedAllowJaggedRows, err := expandBigQueryJobConfigurationLoadAllowJaggedRows(original["allow_jagged_rows"], d, config)
if err != nil {
return nil, err
@@ -2583,6 +2602,10 @@ func expandBigQueryJobConfigurationLoadSourceFormat(v interface{}, d TerraformRe
return v, nil
}
+func expandBigQueryJobConfigurationLoadJsonExtension(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
+ return v, nil
+}
+
func expandBigQueryJobConfigurationLoadAllowJaggedRows(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
} |
The BigQuery REST API supports `jsonExtension: "GEOJSON"` for newline delimited JSON, to import the data as GeoJSON (autodetecting the schema and creating GEOGRAPHY fields for geo data). Expose this in the job load configuration. Fixes hashicorp/terraform-provider-google#12423.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Description
When loading GeoJSON with the
bq
command line tool, it is possible to autodetect a schema and create a table from newline delimited GeoJSON as described here, like so:I am currently trying to accomplish the same with Terraform, with something like this:
Resulting in an error:
Trying to specify a schema for the table, and remove
autodetect
, the error is instead:Either way, importing the GeoJSON with a
google_bigquery_job
seems either impossible or at least not as simple asbq
does it. If it would be possible to support something likebq
:sjson_extension=GEOJSON
it would be helpful.New or Affected Resource(s)
Potential Terraform Configuration
References
The text was updated successfully, but these errors were encountered: