Skip to content

Commit 8ecdff6

Browse files
authored
impl(bigquery): Benchmark program for InsertJob api (#12755)
1 parent 631c00e commit 8ecdff6

5 files changed

Lines changed: 306 additions & 23 deletions

File tree

google/cloud/bigquery/v2/minimal/benchmarks/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ endforeach ()
6767
# Runs benchmark integration tests.
6868
set(experimental_bigquery_rest_client_benchmark_programs
6969
# cmake-format: sort
70-
dataset_benchmark_programs.cc job_readonly_benchmark_programs.cc
71-
project_benchmark_programs.cc table_benchmark_programs.cc)
70+
dataset_benchmark_programs.cc
71+
job_insert_benchmark_programs.cc
72+
job_readonly_benchmark_programs.cc
73+
project_benchmark_programs.cc
74+
table_benchmark_programs.cc)
7275

7376
# Export the list of benchmark integration tests to a .bzl file so we do not
7477
# need to maintain the list in two places.

google/cloud/bigquery/v2/minimal/benchmarks/benchmark.cc

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/bigquery/v2/minimal/benchmarks/benchmark.h"
16+
#include "google/cloud/bigquery/v2/minimal/internal/common_v2_resources.h"
1617
#include "google/cloud/common_options.h"
18+
#include "google/cloud/internal/absl_str_cat_quiet.h"
1719
#include "google/cloud/internal/getenv.h"
1820
#include "google/cloud/internal/make_status.h"
21+
#include "google/cloud/internal/random.h"
1922
#include "google/cloud/options.h"
2023
#include "google/cloud/stream_range.h"
2124
#include "absl/time/time.h"
@@ -34,14 +37,17 @@ using ::google::cloud::bigquery_v2_minimal_internal::Dataset;
3437
using ::google::cloud::bigquery_v2_minimal_internal::DatasetClient;
3538
using ::google::cloud::bigquery_v2_minimal_internal::
3639
DatasetConnectionPoolSizeOption;
40+
using ::google::cloud::bigquery_v2_minimal_internal::EvaluationKind;
3741
using ::google::cloud::bigquery_v2_minimal_internal::GetDatasetRequest;
3842
using ::google::cloud::bigquery_v2_minimal_internal::GetJobRequest;
3943
using ::google::cloud::bigquery_v2_minimal_internal::GetQueryResults;
4044
using ::google::cloud::bigquery_v2_minimal_internal::GetQueryResultsRequest;
4145
using ::google::cloud::bigquery_v2_minimal_internal::GetTableRequest;
46+
using ::google::cloud::bigquery_v2_minimal_internal::IndexUsageMode;
4247
using ::google::cloud::bigquery_v2_minimal_internal::InsertJobRequest;
4348
using ::google::cloud::bigquery_v2_minimal_internal::Job;
4449
using ::google::cloud::bigquery_v2_minimal_internal::JobClient;
50+
using ::google::cloud::bigquery_v2_minimal_internal::KeyResultStatementKind;
4551
using ::google::cloud::bigquery_v2_minimal_internal::ListDatasetsRequest;
4652
using ::google::cloud::bigquery_v2_minimal_internal::ListFormatDataset;
4753
using ::google::cloud::bigquery_v2_minimal_internal::ListFormatJob;
@@ -87,6 +93,20 @@ std::chrono::milliseconds ToChronoMillis(int m) {
8793
return std::chrono::milliseconds(m);
8894
}
8995

96+
std::string GenerateJobId(std::string const& prefix = "") {
97+
auto constexpr kJobPrefix = "bqOdbcJob_benchmark_test_";
98+
std::string job_prefix = kJobPrefix;
99+
if (!prefix.empty()) {
100+
absl::StrAppend(&job_prefix, "_", prefix);
101+
}
102+
auto generator = google::cloud::internal::MakeDefaultPRNG();
103+
auto id = google::cloud::internal::Sample(generator, 32,
104+
"abcdefghijklmnopqrstuvwxyz");
105+
std::string job_id;
106+
absl::StrAppend(&job_id, job_prefix, "_", id);
107+
return job_id;
108+
}
109+
90110
} // anonymous namespace
91111

92112
void Benchmark::PrintThroughputResult(std::ostream& os,
@@ -352,15 +372,50 @@ StatusOr<Job> JobBenchmark::InsertJob() {
352372
// Set request body.
353373
Job job;
354374
std::string request_body;
375+
std::string job_id;
355376
if (config_.dry_run) {
356377
request_body = JobConfig::GetInsertJobDryRunRequestBody();
378+
job_id = GenerateJobId("dry-run");
357379
} else {
358380
request_body = JobConfig::GetInsertJobRequestBody();
381+
job_id = GenerateJobId("real-run");
359382
}
360383
auto json = nlohmann::json::parse(request_body, nullptr, false);
384+
if (!json.is_object()) {
385+
return internal::InternalError(
386+
"Invalid JSON: Unable to parse request body: " + request_body,
387+
GCP_ERROR_INFO());
388+
}
361389
from_json(json, job);
362-
request.set_job(job);
363390

391+
// Set Job Id;
392+
job.job_reference.job_id = job_id;
393+
394+
// Make sure some of the required enum fields are not empty.
395+
if (job.configuration.query.script_options.key_result_statement.value
396+
.empty()) {
397+
job.configuration.query.script_options.key_result_statement =
398+
KeyResultStatementKind::UnSpecified();
399+
}
400+
if (job.statistics.job_query_stats.search_statistics.index_usage_mode.value
401+
.empty()) {
402+
job.statistics.job_query_stats.search_statistics.index_usage_mode =
403+
IndexUsageMode::UnSpecified();
404+
}
405+
if (job.statistics.script_statistics.evaluation_kind.value.empty()) {
406+
job.statistics.script_statistics.evaluation_kind =
407+
EvaluationKind::UnSpecified();
408+
}
409+
request.set_job(job);
410+
// Remove Json fields that shouldn't be part of the InsertJob payload for
411+
// this test case.
412+
request.set_json_filter_keys(
413+
{"statistics", "status", "labels", "destinationTable",
414+
"maximumBytesBilled", "userDefinedFunctionResources", "defaultDataset",
415+
"schemaUpdateOptions", "timePartitioning", "rangePartitioning",
416+
"clustering", "destinationEncryptionConfiguration", "scriptOptions",
417+
"connectionProperties", "systemVariables", "structTypes",
418+
"structValues"});
364419
return job_client_->InsertJob(request);
365420
}
366421

google/cloud/bigquery/v2/minimal/benchmarks/benchmarks_config.cc

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,52 +41,42 @@ auto invalid_argument = [](std::string msg) {
4141

4242
auto status_ok = google::cloud::Status(StatusCode::kOk, "");
4343

44-
std::string GenerateJobId() {
45-
auto constexpr kJobPrefix = "bqOdbcJob_benchmark_test_";
46-
auto generator = google::cloud::internal::MakeDefaultPRNG();
47-
auto job_id = kJobPrefix + google::cloud::internal::Sample(
48-
generator, 32, "abcdefghijklmnopqrstuvwxyz");
49-
return job_id;
50-
}
51-
5244
std::string insert_job_dr_request_body =
5345
R"({"jobReference":{"projectId":"bigquery-devtools-drivers")"
54-
R"(,"jobId":")" +
55-
GenerateJobId() +
56-
R"("})"
46+
R"(,"location":"US")"
47+
R"(})"
5748
R"(,"configuration":{"dryRun":true)"
58-
R"(,"query":{"query":'insert into ODBCTESTDATASET.ODBCTESTTABLE VALUES(?)')"
49+
R"(,"query":{"query":"insert into ODBCTESTDATASET.ODBCTESTTABLE_INSERT VALUES\u0028\u003f\u0029")"
5950
R"(,"useQueryCache":true,"useLegacySql":false,"createSession":false,"parameterMode":"POSITIONAL"}}})";
6051

6152
std::string insert_job_request_body =
6253
R"({"jobReference":{"projectId":"bigquery-devtools-drivers")"
63-
R"(,"jobId":")" +
64-
GenerateJobId() +
65-
R"("})"
54+
R"(,"location":"US")"
55+
R"(})"
6656
R"(,"configuration":{"dryRun":false)"
67-
R"(,"query":{"query":'insert into ODBCTESTDATASET.ODBCTESTTABLE VALUES(?)')"
57+
R"(,"query":{"query":"insert into ODBCTESTDATASET.ODBCTESTTABLE_INSERT VALUES\u0028\u003f\u0029")"
6858
R"(,"useQueryCache":true,"useLegacySql":false)"
6959
R"(,"createSession":false,"parameterMode":"POSITIONAL")"
7060
R"(,"queryParameters":[{"parameterType":{"type":"STRING"},"parameterValue":{"value":"testdata"}}]}}})";
7161

7262
std::string query_create_replace_dr_request_body =
73-
R"({"query":'create or replace table ODBCTESTDATASET.ODBCTESTTABLE (name STRING)')"
63+
R"({"query":"create or replace table ODBCTESTDATASET.ODBCTESTTABLE_QUERY \u0028name STRING\u0029")"
7464
R"(,"dryRun":true,"maxResults":100000,"useLegacySql":false)"
7565
R"(,"timeoutMs":10000,"useQueryCache":true,"createSession":false,"parameterMode":"POSITIONAL"})";
7666

7767
std::string query_create_replace_request_body =
78-
R"({"query":'create or replace table ODBCTESTDATASET.ODBCTESTTABLE (name STRING)')"
68+
R"({"query":"create or replace table ODBCTESTDATASET.ODBCTESTTABLE_QUERY \u0028name STRING\u0029")"
7969
R"(,"dryRun":false,"maxResults":100000,"useLegacySql":false)"
8070
R"(,"timeoutMs":10000,"useQueryCache":true,"createSession":false})";
8171

8272
std::string query_drop_dr_request_body =
83-
R"({"query":"drop table if exists ODBCTESTDATASET.ODBCTESTTABLE")"
73+
R"({"query":"drop table if exists ODBCTESTDATASET.ODBCTESTTABLE_QUERY")"
8474
R"(,"dryRun":true,"maxResults":100000)"
8575
R"(,"useLegacySql":false,"timeoutMs":10000)"
8676
R"(,"useQueryCache":true,"createSession":false,"parameterMode":"POSITIONAL"})";
8777

8878
std::string query_drop_request_body =
89-
R"({"query":"drop table if exists ODBCTESTDATASET.ODBCTESTTABLE")"
79+
R"({"query":"drop table if exists ODBCTESTDATASET.ODBCTESTTABLE_QUERY")"
9080
R"(,"dryRun":false,"maxResults":100000)"
9181
R"(,"useLegacySql":false,"timeoutMs":10000)"
9282
R"(,"useQueryCache":true,"createSession":false})";

google/cloud/bigquery/v2/minimal/benchmarks/experimental_bigquery_rest_client_benchmark_programs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
experimental_bigquery_rest_client_benchmark_programs = [
2020
"dataset_benchmark_programs.cc",
21+
"job_insert_benchmark_programs.cc",
2122
"job_readonly_benchmark_programs.cc",
2223
"project_benchmark_programs.cc",
2324
"table_benchmark_programs.cc",

0 commit comments

Comments
 (0)