【问题标题】:How To upload datastore data to csv file in google cloud storage?如何将数据存储数据上传到谷歌云存储中的 csv 文件?
【发布时间】:2014-06-30 04:19:52
【问题描述】:

https://developers.google.com/bigquery/articles/datastoretobigquery#ingestionjob

如何将datastore数据上传到谷歌云存储中的csv文件?

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    我认为没有一种开箱即用的方法可以做到这一点。如果您可以逐步执行此操作,则可以使用类似于以下的代码:

    /** GCS Service */
    private static GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()
            .initialRetryDelayMillis(10).retryMaxAttempts(10).totalRetryPeriodMillis(15000).build());
    
    /**
     * Create a file on a specified bucket
     */
    public static void writeFile(String bucketName, String filename, String fileContent) throws IOException {
        GcsFilename gcsFile = new GcsFilename(bucketName, filename);
        GcsOutputChannel outputChannel = gcsService.createOrReplace(gcsFile, 
                new GcsFileOptions.Builder().mimeType("text/csv").build());
        DataOutputStream out = new DataOutputStream(Channels.newOutputStream(outputChannel));
        out.write(fileContent.getBytes(Charset.forName("UTF-8")));
        out.flush();
        out.close();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      • 2022-10-30
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多