Can*_*ice 11 r google-bigquery bigrquery
问题很简单。我有以下代码:
# authenticate
bigrquery::bq_auth(path = '/Users/me/restofthepath/bigquery-credentials.json')
# set my project ID and dataset name
project_id <- 'mygreatprojectid'
dataset_name <- 'static'
# how i normally create a new table
players_table = bq_table(project = project_id, dataset = dataset_name, table = 'players')
bq_table_create(x = players_table, fields = as_bq_fields(players_df))
bq_table_upload(x = players_table, values = players_df)
Run Code Online (Sandbox Code Playgroud)
这里players_df是已经在 R 中计算的玩家统计数据的数据框。以下代码成功运行,创建了一个新表。然而,如果我想将更多球员添加到表格中,我就会陷入困境。我已经尝试过以下方法:
bq_table_upload(x = players_table, values = players_df_2)
Run Code Online (Sandbox Code Playgroud)
...players_df_2另一个具有更多玩家统计数据的数据框在哪里...但是,这会返回错误Error: Already Exists: Table mygreatprojectid:static.players [duplicate]
关于如何执行此操作有什么想法,最好不必删除+重新创建表?谢谢!!
编辑:看起来bq_table_patch存在,但这似乎是为了添加新字段/列,而不是为了附加新行...
Gra*_*ley 19
您需要设置WRITE_DISPOSITION和CREATE_DISPOSITION,例如:
bq_table_upload(x=players_table, values= players_df_2, create_disposition='CREATE_IF_NEEDED', write_disposition='WRITE_APPEND')
Run Code Online (Sandbox Code Playgroud)