Google 大查询 - 加载 csv 文件 - 读取时出错 table

Google Big Query - loading a csv file - Error while reading table

我正在尝试将 CSV 格式的报告上传到 Google Big Query。 该报告包含以下列名称:

Adjustment Type; Day; Country; Asset ID; Asset Title; Asset Labels; Asset Channel ID; Asset Type; Custom ID; TMS; EIDR; UPC; Season; Episode Title; Episode Number; Director; Studio; Owned Views; YouTube Revenue Split : Auction; YouTube Revenue Split : Reserved; YouTube Revenue Split : Partner Sold YouTube Served; YouTube Revenue Split : Partner Sold Partner Served; YouTube Revenue Split; Partner Revenue : Auction; Partner Revenue : Reserved; Partner Revenue : Partner Sold YouTube Served; Partner Revenue : Partner Sold Partner Served; Partner Revenue

为此报告创建 table 后,列名称和类型如下所示:

[
 {
   "name": "Adjustment_Type",
   "type": "STRING"
 },
 {
   "name": "Day",
   "type": "STRING"
 },
 {
   "name": "Country",
   "type": "STRING"
 },
 {
   "name": "Asset_ID",
   "type": "STRING"
 },
 {
   "name": "Asset_Title",
   "type": "STRING"
 },
 {
   "name": "Asset_Labels",
   "type": "STRING"
 },
 {
   "name": "Asset_Channel_ID",
   "type": "STRING"
 },
 {
   "name": "Asset_Type",
   "type": "STRING"
 },
 {
   "name": "Custom_ID",
   "type": "STRING"
 },
 {
   "name": "TMS",
   "type": "STRING"
 },
 {
   "name": "EIDR",
   "type": "STRING"
 },
 {
   "name": "UPC",
   "type": "STRING"
 },
 {
   "name": "Season",
   "type": "STRING"
 },
 {
   "name": "Episode_Title",
   "type": "STRING"
 },
 {
   "name": "Episode_Number",
   "type": "STRING"
 },
 {
   "name": "Director",
   "type": "STRING"
 },
 {
   "name": "Studio",
   "type": "STRING"
 },
 {
   "name": "Owned_Views",
   "type": "STRING"
 },
 {
   "name": "YouTube_Revenue_Split___Auction",
   "type": "FLOAT"
 },
 {
   "name": "YouTube_Revenue_Split___Reserved",
   "type": "FLOAT"
 },
 {
   "name": "YouTube_Revenue_Split___Partner_Sold_YouTube_Served",
   "type": "FLOAT"
 },
 {
   "name": "YouTube_Revenue_Split___Partner_Sold_Partner_Served",
   "type": "FLOAT"
 },
 {
   "name": "YouTube_Revenue_Split",
   "type": "FLOAT"
 },
 {
   "name": "Partner_Revenue___Auction",
   "type": "FLOAT"
 },
 {
   "name": "Partner_Revenue___Reserved",
   "type": "FLOAT"
 },
 {
   "name": "Partner_Revenue___Partner_Sold_YouTube_Served",
   "type": "FLOAT"
 },
 {
   "name": "Partner_Revenue___Partner_Sold_Partner_Served",
   "type": "FLOAT"
 },
 {
   "name": "Partner_Revenue",
   "type": "FLOAT"
 }
]

在尝试查询 table 时,我收到以下错误消息:

Could not parse 'YouTube Revenue Split : Auction' as double for field YouTube_Revenue_Split___Auction (position 18) starting at location 0 (error code: invalid)

知道吗,这个错误的原因是什么?

我已经能够重现错误。在我的例子中,它出现在尝试将 CSV 加载到 BigQuery 时。 CSV 有 string YouTube Revenue Split : Auction 应该是 float.

我怀疑发生的情况是您的 CSV 文件中包含 headers 列,并且您在将文件加载到 BigQuery 时没有跳过它们。这会导致,当导入过程到达 YouTube_Revenue_Split___Auction 字段(位置 18)时,预计会插入 float,但它会尝试插入列 header、YouTube Revenue Split : Auction ,这是一个无法正确解析的string

尝试 re-loading CSV,但先删除 header(或使用 Header rows to skip 选项跳过它们)。

如果我的假设是错误的并且这不适用,请通过添加产生错误的查询来更新您的问题。

除了 Guillermo 所说的,您还可以让 Big Query 在您以 CSV

格式上传文件时自动识别 headers 和字段类型

我有一个类似的错误并通过将 semi-colons 替换为逗号来解决它。

您可以为此使用正则表达式或使用我发现的这个很棒的在线文本替换工具 - https://onlinetexttools.com/replace-text