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 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch