olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
PartitionsRequest.h
1/*
2 * Copyright (C) 2019-2020 HERE Europe B.V.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * License-Filename: LICENSE
18 */
19
20#pragma once
21
22#include <sstream>
23#include <string>
24#include <utility>
25#include <vector>
26
27#include <olp/core/porting/optional.h>
28#include <olp/dataservice/read/DataServiceReadApi.h>
29#include <olp/dataservice/read/FetchOptions.h>
30
31namespace olp {
32namespace dataservice {
33namespace read {
34
39class DATASERVICE_READ_API PartitionsRequest final {
40 public:
42 using PartitionIds = std::vector<std::string>;
43
45 static constexpr const char* kDataSize = "dataSize";
46
48 static constexpr const char* kChecksum = "checksum";
49
52 static constexpr const char* kCompressedDataSize = "compressedDataSize";
53
55 static constexpr const char* kCrc = "crc";
56
58 using AdditionalFields = std::vector<std::string>;
59
72 partition_ids_ = std::move(partition_ids);
73 return *this;
74 }
75
81 const PartitionIds& GetPartitionIds() const { return partition_ids_; }
82
98 additional_fields_ = std::move(additional_fields);
99 return *this;
100 }
101
108 return additional_fields_;
109 }
110
121 const porting::optional<std::string>& GetBillingTag() const {
122 return billing_tag_;
123 }
124
134 template <class T = porting::optional<std::string>>
136 billing_tag_ = std::forward<T>(billingTag);
137 return *this;
138 }
139
148 FetchOptions GetFetchOption() const { return fetch_option_; }
149
160 PartitionsRequest& WithFetchOption(FetchOptions fetch_option) {
161 fetch_option_ = fetch_option;
162 return *this;
163 }
164
173 std::string CreateKey(
174 const std::string& layer_id,
175 porting::optional<int64_t> version = porting::none) const {
176 std::stringstream out;
177 out << layer_id;
178 if (version) {
179 out << "@" << *version;
180 }
181 if (GetBillingTag()) {
182 out << "$" << *GetBillingTag();
183 }
184 out << "^" << GetFetchOption();
185 return out.str();
186 }
187
188 private:
189 PartitionIds partition_ids_;
190 AdditionalFields additional_fields_;
191 porting::optional<std::string> billing_tag_;
192 FetchOptions fetch_option_{OnlineIfNotFound};
193};
194
195} // namespace read
196} // namespace dataservice
197} // namespace olp
Encapsulates the fields required to request a list of partitions for the given catalog and layer.
Definition PartitionsRequest.h:39
PartitionsRequest & WithFetchOption(FetchOptions fetch_option)
Sets the fetch option that you can use to set the source from which data should be fetched.
Definition PartitionsRequest.h:160
PartitionsRequest & WithBillingTag(T &&billingTag)
Sets the billing tag for the request.
Definition PartitionsRequest.h:135
std::vector< std::string > AdditionalFields
An alias for the set of additional fields.
Definition PartitionsRequest.h:58
PartitionsRequest & WithAdditionalFields(AdditionalFields additional_fields)
Sets the list of additional fields.
Definition PartitionsRequest.h:97
const PartitionIds & GetPartitionIds() const
Gets the list of the partitions.
Definition PartitionsRequest.h:81
std::vector< std::string > PartitionIds
An alias for the vector of partitions IDs.
Definition PartitionsRequest.h:42
const porting::optional< std::string > & GetBillingTag() const
Gets the billing tag to group billing records together.
Definition PartitionsRequest.h:121
std::string CreateKey(const std::string &layer_id, porting::optional< int64_t > version=porting::none) const
Creates a readable format for the request.
Definition PartitionsRequest.h:173
const AdditionalFields & GetAdditionalFields() const
Gets the list of additional fields.
Definition PartitionsRequest.h:107
PartitionsRequest & WithPartitionIds(PartitionIds partition_ids)
Sets the list of partitions.
Definition PartitionsRequest.h:71
FetchOptions GetFetchOption() const
Gets the fetch option that controls how requests are handled.
Definition PartitionsRequest.h:148
Rules all the other namespaces.
Definition AppleSignInProperties.h:24