doudang2817 2017-01-26 14:36
浏览 136
已采纳

如何在BigQuery中使用非必填字段创建表?

I'm making a RESTful API in Go that writes rows in BigQuery. I'm using Google BigQuery package for Go.

In order to create the BigQuery scheme, I'm infering the schema from a struct as described in the example.

The problem is that, the resulting schema has all the non-repeated fields as "Required", so that, when I want to upload a struct with null values, the null values are uploaded as empy fields...

This is an example of my struct:

type Stats struct {
    Name            string        `bigquery:"name"`
    LastName        int           `bigquery:"last_name"`
    PhoneNumber     string        `bigquery:"phone_number"`
}

This is an example of how the schema is created:

testSchema, err := bigquery.InferSchema(Stats{})
if err != nil {
    // TODO: Handle error.
}

And, if I upload a struct with only one field set:

rows := []*Stats{
    {Name: "testA"},
}

u := table.Uploader()
err2 := u.Put(ctx, rows)

The result is that, in BigQuery, the fields "last_name" and "phone_number" is an empty string "" instead of NULL

  • 写回答

2条回答 默认 最新

  • duanlu1793 2018-04-05 16:43
    关注

    For that, apparently you would have to use the specific BigQuery nullable types (NullInt64, NullFloat64, NullString, NullBool, NullTimestamp, NullDate, NullTime and NullDateTime).

    Example using bigquery.NullBool: https://godoc.org/cloud.google.com/go/bigquery#ex-InferSchema--Tags

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接