【问题标题】:Append / Insert Data Into BigQuery Table Using R's bigrquery Library使用 R 的 bigrquery 库将数据追加/插入到 BigQuery 表中
【发布时间】:2020-06-22 23:17:30
【问题描述】:

问题很简单。我有以下代码:

# 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)

这里,players_df 是已经在 R 中计算的玩家统计数据的数据框。以下代码成功运行,创建了一个新表。但是,如果我有更多的玩家想要添加到桌面上,我会很挣扎。我尝试了以下方法:

bq_table_upload(x = players_table, values = players_df_2)

...其中players_df_2 是另一个具有更多玩家统计信息的数据框...但是,这会返回错误Error: Already Exists: Table mygreatprojectid:static.players [duplicate]

关于如何做到这一点的任何想法,最好不必删除+重新创建表?谢谢!!

编辑:看起来bq_table_patch 存在,但这似乎是用于添加新字段/列,而不是用于附加新行...

【问题讨论】:

    标签: r google-bigquery bigrquery


    【解决方案1】:

    您需要设置WRITE_DISPOSITIONCREATE_DISPOSITION,例如:

    bq_table_upload(x=players_table, values= players_df_2, create_disposition='CREATE_IF_NEEDED', write_disposition='WRITE_APPEND')
    

    【讨论】:

      猜你喜欢
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 2019-12-28
      • 2019-03-02
      相关资源
      最近更新 更多