自动将谷歌云端存储中的Google Play控制台报告导入BigQuery

时间:2018-03-20 11:11:01

标签: powershell cmd google-bigquery google-cloud-storage google-play-console

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:\***\Scripts\gc\$csv_file2
& bq load --replace report.$table C:\***\Scripts\gc\$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.

1 个答案:

答案 0 :(得分: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`

this post

中的ajk有详细解答