dqr3883 2019-05-02 11:48
浏览 53
已采纳

在没有明确定义的结构的情况下插入BigQuery

I'd like to insert any type of JSON directly into BigQuery, but haven't found any good way of doing this? All ways assume I have a well defined struct that I insert. It seems it was possible with the old deprecated api but not with the new "cloud.google.com/go/bigquery" package.

I'd like to have /api/table_name/insert be able to take any type of json and insert it into BigQuery as both the client and server knows the schema the endpoint should just forward it.

Thanks

  • 写回答

1条回答 默认 最新

  • duanshang9426 2019-06-15 20:48
    关注

    seems like this was replaced with ValueSaver which you can implement like:

    type genericRecord map[string]bigquery.Value
    
    func (rec genericRecord) Save() (map[string]bigquery.Value, string, error) {
        insertID := uuid.New().String()
        return rec, insertID, nil
    }
    
    var data []*genericRecord
    json.Unmarshal(<YOUR JSON BYTE>, &data)
    
    ctx := context.Background()
    client, err := bigquery.NewClient(ctx, <YOUR PROJECT ID>)
    ins := client.Dataset(<DATASET>).Table(<TABLE>).Inserter()
    ins.Put(ctx, data)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动