Golang:在插入之前检查BigQuery的唯一键

huangapple go评论84阅读模式
英文:

Golang: Bigquery Check Unique Key before Inserting

问题

我正在使用Golang实现向Google BigQuery插入数据。
文件中存在重复项,并且需要每天更新。但是,重复项不应该被插入到BigQuery中。
我使用了一些Google Cloud Platform和Golang的API。然而,我没有找到任何API可以在插入之前检查唯一性,或者在模式中设置特定字段为唯一。
我正在使用一个包装的API,并直接调用函数。然而,该函数并不检查字段是否唯一。请推荐任何在Golang中具有唯一键检查或将唯一键设置为模式的BigQuery API。非常感谢!我会立即更新回复。

英文:

I am implementing the insertion to google bigquery using golang.
The file has duplicates, and needs to be update everyday. However, the duplicates should not be inserted into the bigquery.
I use some apis by google cloud platform and golang. However, I have not found any apis can either check if unique before inserting or setting to unique for specific fields in schema.
I am using a wrapper api and calling the function directly. However, the function does not check if the field is unique. Please suggest any bigquery apis for golang has unique key checking or unique key setting to the schema. Much appreciate! I will update replies immediately.

答案1

得分: 2

在BigQuery中,没有任何特定的API或函数可以对给定字段进行唯一性检查。
您可以通过将插入操作构建为源表与目标表的连接,并仅插入唯一的记录来满足您的需求。
这可能需要您首先将数据插入到“temp”表中,然后在BigQuery中执行上述连接操作。

英文:

In BigQuery, there is no any API or Function to specifically do uniqueness check of given field
You can meet your requirements by constructing your insert as join of source with destination and insert only unique ones
This might require you first to insert your data into “temp” table and then do above join in GBQ

答案2

得分: 0

请查看StructSaver结构的文档。

它有一个名为InsertID的字段,正是你所询问的:

// 如果非空,BigQuery将尽力使用InsertID来对该行的插入进行去重。
InsertID string
英文:

Check the doc for StructSaver struct.

It has a field InserdID, exactly for what you're asking:

// If non-empty, BigQuery will use InsertID to de-duplicate insertions
// of this row on a best-effort basis.
InsertID string

huangapple
  • 本文由 发表于 2016年1月7日 01:43:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/34639372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定