AppendRows在Storage Write API Golang中陷入循环。

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

AppendRows in Storage Write API Golang gets stuck in a loop

问题

我正在尝试使用Storage Write API将一些数据发送到BQ。我使用了这个示例:https://cloud.google.com/bigquery/docs/write-api-batch

当我的代码是平的时候,它可以工作,但是一旦我将它放入循环中,它就会在第二个循环步骤和res, err := ms.AppendRows(ctx, pfProto)这一行永远卡住:

	results := []*managedwriter.AppendResult{}
	for i := 0; i < len(skus); i = i + PFStocksLimit {
		lim := i + PFStocksLimit
		if lim > len(skus)-1 {
			lim = len(skus) - 1
		}
		stocks := getStocks(skus[i:lim])
		pfProto := prepProto(gd, stocks)

		res, err := ms.AppendRows(ctx, pfProto)
		if err != nil {
			log.Fatalf("AppendRows call error: %v", err)
		}
		results = append(results, res)
}

有趣的是,当我移除results = append(results, res)时,它可以工作。我不明白这里出了什么问题。

英文:

I am trying to send some data to BQ using Storage Write API.
I use this example:
https://cloud.google.com/bigquery/docs/write-api-batch

When my code is flat it works, but as soon as I put it into a loop it stucks forever at the second loop step and res, err := ms.AppendRows(ctx, pfProto):

	results := []*managedwriter.AppendResult{}
	for i := 0; i &lt; len(skus); i = i + PFStocksLimit {
		lim := i + PFStocksLimit
		if lim &gt; len(skus)-1 {
			lim = len(skus) - 1
		}
		stocks := getStocks(skus[i:lim])
		pfProto := prepProto(gd, stocks)

		res, err := ms.AppendRows(ctx, pfProto)
		if err != nil {
			log.Fatalf(&quot;AppendRows call error: %v&quot;, err)
		}
		results = append(results, res)
}

Funny enough when I remove results = append(results, res) it works.
I do not understang what is wrong here.

答案1

得分: 1

我刚刚意识到这是一个关于大数据插入的错误,该问题已在此处报告:https://github.com/googleapis/google-cloud-go/issues/6321

解决方案:一次插入较少的行。

英文:

I just realized that this is a bug for big data inserts, the issue is reported here: https://github.com/googleapis/google-cloud-go/issues/6321

Solution: insert less rows at one time

huangapple
  • 本文由 发表于 2022年7月11日 01:36:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/72930564.html
匿名

发表评论

匿名网友

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

确定