4

I am uploading an R data frame to Big Query with this:

bq_table_upload("project.dataset.table_name", df_name) 

It works, but the order of the columns is different in BQ than in R.

Is it possible to get the table to inherit the order of the columns from the data frame? I have looked through the documentation and have not found this option, though it is certainly possible I missed it.

dimitriy
  • 9,077
  • 2
  • 25
  • 50
  • 2
    Have you tried providing a list of fields to use? For example, `bq_table_upload("project.dataset.table_name", df_name, fields=df_name)`. When you provide fields argument as a dataframe, [the table schema is generated from it](https://github.com/r-dbi/bigrquery/blob/feb1a9ab3019bdd96848acce81cdcfe6770696d6/R/bq-field.R#L86) and used in the [upload request](https://github.com/r-dbi/bigrquery/blob/d12fabaa4cf6dfe0ea81c721fb0932abbc90c0e7/R/bq-perform.R#L130) – Oluwafemi Sule Jul 23 '20 at 06:49

1 Answers1

0

As pointed out in the comments by Oluwafemi Sule, it's only a matter of providing the dataframe in the "fields" attribute like below:

bq_table_upload("project.dataset.table_name", values = df_name, fields=df_name)