doushi1900 2019-05-09 14:45
浏览 82

导入到BigQuery中之前的CSV中的日期格式

I have developed a Golang code that takes the csv file from Google cloud storage than import it to the Big Query table.

Everything is ok except that my CSV contains a DATE column in format of "2017-06-14 00:49:52 PDT". This cause the issue that CSV file can not be imported in the Big Query since the format must be "2017-06-14". I can not manually edit it in the CSV before uploading to the Google storage because it is about a very huge files (that changes every day).

Is there any option to update the CSV hosted on a storage using go lang and leave only "2017-06-14" value for this column (DATE) before executing the rest of code which import it to the Big Query, or any other solution?

Thank you in advance!

package storagetobigquery

import (
    "cloud.google.com/go/bigquery"
    "github.com/gin-gonic/gin"
    "google.golang.org/appengine"
)

// StoragetoBigquery function
func StoragetoBigquery(c *gin.Context) {
    ctx := appengine.NewContext(c.Request)

    client, err := bigquery.NewClient(ctx, "MY PROJECT ID")

    gcsRef := bigquery.NewGCSReference("PATH TO THE GOOGLE STORAGE CSV FILE")
    gcsRef.SourceFormat = bigquery.CSV
    gcsRef.AutoDetect = true
    gcsRef.SkipLeadingRows = 1


    loader := client.Dataset("DATASET NAME").Table(TABLE NAME).LoaderFrom(gcsRef)
    loader.WriteDisposition = bigquery.WriteTruncate

    job, err := loader.Run(ctx)
    if err != nil {
        panic(err)
    }
    status, err := job.Wait(ctx)
    if err != nil {
        panic(err)
    }

    if status.Err() != nil {
        panic(status.Err)
    }
}
  • 写回答

1条回答 默认 最新

  • duanhui9840 2019-05-10 11:59
    关注

    If you have to use the Go client library, before changing the format you need to get the object from GCS. Then, re-upload to import it to BQ as you're doing. There is no method documented in https://godoc.org/cloud.google.com/go/storage to update the object in GCS directly, only its metadata.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看