googleapis / googleapis/google-cloud-go
bigquery: make InferSchema set column defaults
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 1.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 109
Description
## Is your feature request related to a problem? Please describe.
I'd like `InferSchema` to set defaults for columns.
## Describe the solution you'd like
Add `default=` as an option for the `bigquery` tag. For example:
```go
type withDefaults struct {
Bytes []byte `bigquery:",nullable,default=b'hey now'"`
Rat *big.Rat `bigquery:",nullable,default=3.1415"`
RequiredBytes []byte `bigquery:",default=b'hey now'"`
RequiredRat *big.Rat `bigquery:",default=3.1415"`
NullInt64 NullInt64 `bigquery:",default=77"`
NullFloat64 NullFloat64 `bigquery:",default=77.24"`
NullBool NullBool `bigquery:",default=false"`
NullString NullString `bigquery:",default='hey now'"`
NullJSON NullJSON `bigquery:",default='{}'"`
NullTimestamp NullTimestamp `bigquery:",default=CURRENT_TIMESTAMP()"`
NullDate NullDate `bigquery:",default=CURRENT_DATE()"`
NullTime NullTime `bigquery:",default=CURRENT_TIME()"`
NullDateTime NullDateTime `bigquery:",default=CURRENT_DATETIME()"`
GoTime time.Time `bigquery:",default=CURRENT_DATETIME()"`
Time civil.Time `bigquery:",default=CURRENT_TIME()"`
Date civil.Date `bigquery:",default=CURRENT_DATE()"`
DateTime civil.DateTime `bigquery:",default=CURRENT_DATETIME()"`
String string `bigquery:",default='hey now'"`
Bool bool `bigquery:",default=true"`
Float32 float32 `bigquery:",default=3.14"`
Float64 float64 `bigquery:",default=3.1415"`
Int32 int32 `bigquery:",default=77"`
Int64 int64 `bigquery:",default=7777"`
}
```
## Describe alternatives you've considered
When creating tables
1. Modify columns in the schema returned from `InferSchema`
2. Execute an `ALTER TABLE ALTER COLUMN` statement to set the default
Both of those alternatives require extra code with the drawbacks
* Table creation wouldn't be atomic
* It would be necessary to keep extra code in sync with the table described in the structure, which is brittle
## Additional context
No.
Contributor guide
Assessment
This issue has not been assessed yet.