【问题标题】:How to Select large dataset and loading datatable from bigquery using c# application如何使用 c# 应用程序从 bigquery 中选择大型数据集并加载数据表
【发布时间】:2015-06-23 13:23:36
【问题描述】:

我已经创建了 C#.NET 应用程序(使用服务身份验证)。

我正在尝试运行 select 语句(来自 Google BigQuery 的公共示例表)并将结果加载到数据表中,但无法实现,它会抛出错误

查询导致错误是:“SELECT * FROM [publicdata:samples.github_timeline]

Google.Apis.Requests.RequestError

Response too large to return. Consider setting allowLargeResults to true in your job configuration. For more information, see https://cloud.google.com/bigquery/troubleshooting-errors [403]

Errors [

Message[Response too large to return. Consider setting allowLargeResults to true in your job configuration. For more information, see https://cloud.google.com/bigquery/troubleshooting-errors] Location[ - ] Reason[responseTooLarge] Domain[global]

].

这是 C# 代码。

        String serviceAccountEmail = "SERVICE ACCOUNT EMAIL ADDRESS";

            var certificate = new X509Certificate2(@"KEY FILE NAME", "KEY SECRET", X509KeyStorageFlags.Exportable);

            ServiceAccountCredential credential = new ServiceAccountCredential(
               new ServiceAccountCredential.Initializer(serviceAccountEmail)
               {
                   Scopes = new[] { BigqueryService.Scope.Bigquery, BigqueryService.Scope.BigqueryInsertdata, BigqueryService.Scope.CloudPlatform, BigqueryService.Scope.DevstorageFullControl }
               }.FromCertificate(certificate));

            BigqueryService Service = new BigqueryService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "PROJECT NAME"
            });

            string query = "SELECT * FROM [publicdata:samples.github_timeline]";

            JobsResource j = Service.Jobs;

            QueryRequest qr = new QueryRequest();

            string ProjectID = "PROJECT ID";

            qr.Query = query;
            qr.MaxResults = Int32.MaxValue;
            qr.TimeoutMs = Int32.MaxValue;

            DataTable DT = new DataTable();
            int i = 0;

            QueryResponse response = j.Query(qr, ProjectID).Execute();

我们如何选择大型数据集并将结果以最佳方式加载到 Datatable 中?担心 BigQuery 会引发这些类型的错误,那么我们将如何相信我们的程序可以 100% 运行。

【问题讨论】:

    标签: google-api google-bigquery google-api-dotnet-client


    【解决方案1】:

    Returning large query results

    通常,查询具有最大响应大小。如果您打算运行 可能返回较大结果的查询,您可以设置 allowLargeResults 在您的工作配置中为 true。

    返回较大结果的查询将需要更长的时间来执行,即使 结果集很小,并且受到其他限制:

    您必须指定目标表。您不能指定顶级 ORDER BY、TOP 或 LIMIT 子句。这样做会否定使用的好处 allowLargeResults,因为无法再计算查询输出 在平行下。窗口函数只有在以下情况下才能返回大查询结果 与 PARTITION BY 子句一起使用。

    问题是 Google .net 客户端库是否支持在请求中添加 allowLargeResults。检查选项值。

    如果你幸运的话:

    qr.allowLargeResults = true

    【讨论】:

    • 不,我在 Google .net 客户端库中找不到 QueryRequest 的 allowLargeResults
    • 将其作为问题添加到客户端库github.com/google/google-api-dotnet-client/issues
    • 此功能是否在其他客户端库(如 Java 或 PHP)中可用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    相关资源
    最近更新 更多