google-cloud-go icon indicating copy to clipboard operation
google-cloud-go copied to clipboard

feat(bigquery): Add Clone() method to bigquery.Schema

Open IvanIsCoding opened this issue 1 year ago • 2 comments

This is mostly a convenience method. It comes in handy when creating Views from BigQuery, because we want to have a subset of the fields for the View but still want to keep the original FieldSchema entries of the cloned object intact.

There is nothing here that could not be replicated in clients because all the fields of the struct are exported, but it would be good if this was supported upstream.

IvanIsCoding avatar Jul 24 '24 19:07 IvanIsCoding

The PR itself looks straightforward, but I wanted to understand how you're leveraging this. You mention views, but they're not typically defined via the output schema. Can you elaborate a bit more? Thanks!

shollyman avatar Aug 26 '24 22:08 shollyman

The PR itself looks straightforward, but I wanted to understand how you're leveraging this. You mention views, but they're not typically defined via the output schema. Can you elaborate a bit more? Thanks!

Sure, that is a good question. I mentioned BigQuery Views because my team uses views, but it could also apply to folks copying tables. We want to keep track of what is the schema for queries like:

SELECT A, B, C
FROM TABLE

For us, it is easier to clone the schema from TABLE and delete what is not in the SELECT statement, because our queries generally have lots of columns. The extreme is the case with EXCEPT clauses:

SELECT * EXCEPT D, E
FROM TABLE

where the clone method with deleting is the best way to keep track of the columns shown for the View.

IvanIsCoding avatar Aug 27 '24 13:08 IvanIsCoding

@shollyman please see response above

codyoss avatar Dec 10 '24 16:12 codyoss