-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from scotthart/add_default_policy_options
impl: add policy option defaults
- Loading branch information
Showing
9 changed files
with
459 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ | |
|
||
bigquery_unified_client_unit_tests = [ | ||
"client_test.cc", | ||
"internal/default_options_test.cc", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/bigquery_unified/idempotency_policy.h" | ||
#include "google/cloud/bigquery_unified/version.h" | ||
|
||
namespace google::cloud::bigquery_unified { | ||
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN | ||
using ::google::cloud::Idempotency; | ||
|
||
/// Create a new copy of this object. | ||
std::unique_ptr<IdempotencyPolicy> IdempotencyPolicy::clone() const { | ||
return std::make_unique<IdempotencyPolicy>(*this); | ||
} | ||
|
||
Idempotency IdempotencyPolicy::CancelJob( | ||
google::cloud::bigquery::v2::CancelJobRequest const&, Options) { | ||
return Idempotency::kIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::CancelJob( | ||
google::cloud::NoAwaitTag, | ||
google::cloud::bigquery::v2::CancelJobRequest const&, Options) { | ||
return Idempotency::kIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::CancelJob( | ||
google::cloud::bigquery::v2::JobReference const&, Options) { | ||
return Idempotency::kIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::GetJob( | ||
google::cloud::bigquery::v2::GetJobRequest const&, Options) { | ||
return Idempotency::kIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::DeleteJob( | ||
google::cloud::bigquery::v2::DeleteJobRequest const&, Options) { | ||
return Idempotency::kIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::InsertJob( | ||
google::cloud::bigquery::v2::InsertJobRequest const&, Options) { | ||
return Idempotency::kNonIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::InsertJob( | ||
google::cloud::NoAwaitTag, | ||
google::cloud::bigquery::v2::InsertJobRequest const&, Options) { | ||
return Idempotency::kNonIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::InsertJob( | ||
google::cloud::bigquery::v2::JobReference const&, Options) { | ||
return Idempotency::kNonIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::ListJobs( | ||
google::cloud::bigquery::v2::ListJobsRequest, Options) { | ||
return Idempotency::kIdempotent; | ||
} | ||
|
||
Idempotency IdempotencyPolicy::ReadArrow( | ||
google::cloud::bigquery::storage::v1::CreateReadSessionRequest const&, | ||
Options) { | ||
return Idempotency::kIdempotent; | ||
} | ||
|
||
std::unique_ptr<IdempotencyPolicy> MakeDefaultIdempotencyPolicy() { | ||
return std::make_unique<IdempotencyPolicy>(); | ||
} | ||
|
||
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END | ||
} // namespace google::cloud::bigquery_unified |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_IDEMPOTENCY_POLICY_H | ||
#define GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_IDEMPOTENCY_POLICY_H | ||
|
||
#include "google/cloud/bigquery/storage/v1/bigquery_read_connection.h" | ||
#include "google/cloud/bigquery_unified/version.h" | ||
#include "google/cloud/bigquerycontrol/v2/job_connection.h" | ||
#include "google/cloud/idempotency.h" | ||
#include "google/cloud/no_await_tag.h" | ||
|
||
namespace google::cloud::bigquery_unified { | ||
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN | ||
|
||
class IdempotencyPolicy { | ||
public: | ||
virtual ~IdempotencyPolicy() = default; | ||
|
||
/// Create a new copy of this object. | ||
virtual std::unique_ptr<IdempotencyPolicy> clone() const; | ||
|
||
virtual google::cloud::Idempotency CancelJob( | ||
google::cloud::bigquery::v2::CancelJobRequest const& request, | ||
Options opts); | ||
|
||
virtual google::cloud::Idempotency CancelJob( | ||
google::cloud::NoAwaitTag no_await_tag, | ||
google::cloud::bigquery::v2::CancelJobRequest const& request, | ||
Options opts); | ||
|
||
virtual google::cloud::Idempotency CancelJob( | ||
google::cloud::bigquery::v2::JobReference const& job_reference, | ||
Options opts); | ||
|
||
virtual google::cloud::Idempotency DeleteJob( | ||
google::cloud::bigquery::v2::DeleteJobRequest const& request, | ||
Options opts); | ||
|
||
virtual google::cloud::Idempotency GetJob( | ||
google::cloud::bigquery::v2::GetJobRequest const& request, Options opts); | ||
|
||
virtual google::cloud::Idempotency InsertJob( | ||
google::cloud::bigquery::v2::InsertJobRequest const& request, | ||
Options opts); | ||
|
||
virtual google::cloud::Idempotency InsertJob( | ||
google::cloud::NoAwaitTag, | ||
google::cloud::bigquery::v2::InsertJobRequest const& request, | ||
Options opts); | ||
|
||
virtual google::cloud::Idempotency InsertJob( | ||
google::cloud::bigquery::v2::JobReference const& job_reference, | ||
Options opts); | ||
|
||
virtual google::cloud::Idempotency ListJobs( | ||
google::cloud::bigquery::v2::ListJobsRequest request, Options opts); | ||
|
||
virtual google::cloud::Idempotency ReadArrow( | ||
google::cloud::bigquery::storage::v1::CreateReadSessionRequest const& | ||
read_session, | ||
Options opts); | ||
}; | ||
|
||
std::unique_ptr<IdempotencyPolicy> MakeDefaultIdempotencyPolicy(); | ||
|
||
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END | ||
} // namespace google::cloud::bigquery_unified | ||
|
||
#endif // GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_IDEMPOTENCY_POLICY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
google/cloud/bigquery_unified/internal/default_options_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/bigquery_unified/internal/default_options.h" | ||
#include "google/cloud/bigquery_unified/job_options.h" | ||
#include "google/cloud/bigquery_unified/version.h" | ||
#include <gmock/gmock.h> | ||
|
||
namespace google::cloud::bigquery_unified_internal { | ||
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN | ||
namespace { | ||
|
||
TEST(BigQueryUnifiedDefaultOptionsTest, AllOptionsDefaulted) { | ||
auto empty_options = google::cloud::Options{}; | ||
auto options_result = DefaultOptions(empty_options); | ||
EXPECT_TRUE(options_result.has<bigquery_unified::RetryPolicyOption>()); | ||
EXPECT_TRUE(options_result.has<bigquery_unified::BackoffPolicyOption>()); | ||
EXPECT_TRUE(options_result.has<bigquery_unified::PollingPolicyOption>()); | ||
EXPECT_TRUE(options_result.has<bigquery_unified::IdempotencyPolicyOption>()); | ||
} | ||
|
||
} // namespace | ||
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END | ||
} // namespace google::cloud::bigquery_unified_internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_JOB_OPTIONS_H | ||
#define GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_JOB_OPTIONS_H | ||
|
||
#include "google/cloud/bigquery_unified/idempotency_policy.h" | ||
#include "google/cloud/bigquery_unified/retry_policy.h" | ||
#include "google/cloud/bigquery_unified/version.h" | ||
#include "google/cloud/backoff_policy.h" | ||
#include "google/cloud/options.h" | ||
#include "google/cloud/polling_policy.h" | ||
#include <memory> | ||
|
||
namespace google::cloud::bigquery_unified { | ||
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN | ||
|
||
struct BackoffPolicyOption { | ||
using Type = std::shared_ptr<BackoffPolicy>; | ||
}; | ||
|
||
struct BillingProjectOption { | ||
using Type = std::string; | ||
}; | ||
|
||
struct IdempotencyPolicyOption { | ||
using Type = std::shared_ptr<bigquery_unified::IdempotencyPolicy>; | ||
}; | ||
|
||
struct PollingPolicyOption { | ||
using Type = std::shared_ptr<PollingPolicy>; | ||
}; | ||
|
||
struct RetryPolicyOption { | ||
using Type = std::shared_ptr<bigquery_unified::RetryPolicy>; | ||
}; | ||
|
||
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END | ||
} // namespace google::cloud::bigquery_unified | ||
|
||
#endif // GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_JOB_OPTIONS_H |
Oops, something went wrong.