自动将 Google Play 管理中心报告从 Google Cloud Storage 导入 BigQuery



Google Play 管理中心的报告使用 UTF-16 编码,BigQuery - UTF-8。

如何自动将 CSV 文件从 UTF-16 转换为 UTF-8?

我在PowerShell中的代码:

$date = (Get-Date).AddDays(-2).Date.ToString('yyyy-MM') 
$date2 = $date.Replace('-', '')
$typefile = 'app_version'
$table = $typefile + '$' + $date2 + '01'
$csv_file = 'gs://pubsite_prod_rev_******_'+ $date2 + '_' + $typefile + '.csv'
$csv_file2 = $date2 + '_' + $typefile + '.csv'
& gsutil cp $csv_file C:***Scriptsgc$csv_file2
& bq load --replace report.$table C:***Scriptsgc$csv_file2

错误:

BigQuery error in load operation: Error processing job
'majestic-cairn-****:bqjob_r171ebea2_*****_1': Error while reading
data, error message: CSV table encountered too many errors, giving up. Rows: 1;
errors: 1. Please look into the error stream for more details.
Failure details:
- file-00000000: Error while reading data, error message: Too many
values in row starting at position: 0.

TheIncorrigible1所述,可以使用Powershell进行编码转换

(Get-Content -Path $Path) | Out-File -FilePath $Path -Encoding UTF8 

此命令会将 CSV 文件从UTF-16转换为UTF-8。您可能必须在第一个命令中指定编码,如下所示

(Get-Content -Path $Path -Encoding UTF16) | Out-File -FilePath $Path -Encoding UTF8`

这篇文章中有ajk的详细答案

最新更新