Skip to content

Commit a9730c2

Browse files
Add additional fields support to PartitionsRequest (#696)
Add CRC field support to partition model. Change QueryApi and MetadataApi to accept additional headers by const ref. This gives to user functionality to access partition metadata fields: * data size * compressed data size * checksum * crc Resolves: OLPEDGE-1019 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 227b34c commit a9730c2

File tree

12 files changed

+190
-23
lines changed

12 files changed

+190
-23
lines changed

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/PartitionsRequest.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ class DATASERVICE_READ_API PartitionsRequest final {
4141
/// The alias type of the vector of partitions ids
4242
using PartitionIds = std::vector<std::string>;
4343

44+
/// Additional field to request partition data size, see GetPartitions
45+
static constexpr const char* kDataSize = "dataSize";
46+
47+
/// Additional field to request partition checksum, see GetPartitions
48+
static constexpr const char* kChecksum = "checksum";
49+
50+
/// Additional field to request partition compressed data size, see
51+
/// GetPartitions
52+
static constexpr const char* kCompressedDataSize = "compressedDataSize";
53+
54+
/// Additional field to request partition crc, see GetPartitions
55+
static constexpr const char* kCrc = "crc";
56+
57+
/// The alias type of the set of additional fields
58+
using AdditionalFields = std::vector<std::string>;
59+
4460
/**
4561
* @brief Sets the list of partitions.
4662
*
@@ -64,6 +80,35 @@ class DATASERVICE_READ_API PartitionsRequest final {
6480
*/
6581
inline const PartitionIds& GetPartitionIds() const { return partition_ids_; }
6682

83+
/**
84+
* @brief Sets the list of additional fields.
85+
*
86+
* When specified, the result metadata will include the additional information
87+
* requested. The supported fields are:
88+
* - dataSize
89+
* - checksum
90+
* - compressedDataSize
91+
* - crc
92+
*
93+
* @param fields The list of additional fields.
94+
*
95+
* @return A reference to the updated `PartitionsRequest` instance.
96+
*/
97+
inline PartitionsRequest& WithAdditionalFields(
98+
AdditionalFields additional_fields) {
99+
additional_fields_ = std::move(additional_fields);
100+
return *this;
101+
}
102+
103+
/**
104+
* @brief Gets the list of additional fields.
105+
*
106+
* @return The set of additional fields.
107+
*/
108+
inline const AdditionalFields& GetAdditionalFields() const {
109+
return additional_fields_;
110+
}
111+
67112
/**
68113
* @brief Sets the catalog metadata version.
69114
*
@@ -187,6 +232,7 @@ class DATASERVICE_READ_API PartitionsRequest final {
187232

188233
private:
189234
PartitionIds partition_ids_;
235+
AdditionalFields additional_fields_;
190236
boost::optional<int64_t> catalog_version_;
191237
boost::optional<std::string> billing_tag_;
192238
FetchOptions fetch_option_{OnlineIfNotFound};

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/model/Partitions.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class DATASERVICE_READ_API Partition {
4444
boost::optional<int64_t> compressed_data_size_;
4545
std::string data_handle_;
4646
boost::optional<int64_t> data_size_;
47+
boost::optional<std::string> crc_;
4748
std::string partition_;
4849
boost::optional<int64_t> version_;
4950

@@ -182,6 +183,35 @@ class DATASERVICE_READ_API Partition {
182183
this->data_size_ = value;
183184
}
184185

186+
/**
187+
* Optional value for the CRC of the partition data in bytes.
188+
*
189+
* The response only includes the data size if you specify crc in the
190+
* additionalFields query parameter, and if crc was specified in the partition
191+
* metadata when it was published.
192+
*
193+
* @return The partition CRC.
194+
*/
195+
const boost::optional<std::string>& GetCrc() const { return crc_; }
196+
/**
197+
* @brief (Optional) Gets a mutable reference to the partition crc.
198+
*
199+
* @see `GetCrc` for information on the crc.
200+
*
201+
* @return The mutable reference to the partition crc.
202+
*/
203+
boost::optional<std::string>& GetMutableCrc() { return crc_; }
204+
/**
205+
* @brief (Optional) Sets the partition crc.
206+
*
207+
* @see `GetCrc` for information on the crc.
208+
*
209+
* @param value The partition crc.
210+
*/
211+
void SetCrc(boost::optional<std::string> value) {
212+
this->crc_ = std::move(value);
213+
}
214+
185215
/**
186216
* @brief Gets the partition key.
187217
*

olp-cpp-sdk-dataservice-read/src/generated/api/MetadataApi.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ MetadataApi::LayerVersionsResponse MetadataApi::GetLayerVersions(
8484
MetadataApi::PartitionsResponse MetadataApi::GetPartitions(
8585
const OlpClient& client, const std::string& layer_id,
8686
boost::optional<int64_t> version,
87-
boost::optional<std::vector<std::string>> additional_fields,
87+
const std::vector<std::string>& additional_fields,
8888
boost::optional<std::string> range,
8989
boost::optional<std::string> billing_tag,
9090
const client::CancellationContext& context) {
@@ -95,9 +95,9 @@ MetadataApi::PartitionsResponse MetadataApi::GetPartitions(
9595
}
9696

9797
std::multimap<std::string, std::string> query_params;
98-
if (additional_fields) {
98+
if (!additional_fields.empty()) {
9999
query_params.emplace("additionalFields",
100-
concatStringArray(*additional_fields, ","));
100+
concatStringArray(additional_fields, ","));
101101
}
102102
if (billing_tag) {
103103
query_params.emplace("billingTag", *billing_tag);

olp-cpp-sdk-dataservice-read/src/generated/api/MetadataApi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class MetadataApi {
9393
static PartitionsResponse GetPartitions(
9494
const client::OlpClient& client, const std::string& layerId,
9595
boost::optional<int64_t> version,
96-
boost::optional<std::vector<std::string>> additional_fields,
96+
const std::vector<std::string>& additional_fields,
9797
boost::optional<std::string> range,
9898
boost::optional<std::string> billing_tag,
9999
const client::CancellationContext& context);

olp-cpp-sdk-dataservice-read/src/generated/api/QueryApi.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ QueryApi::PartitionsResponse QueryApi::GetPartitionsbyId(
6060
const client::OlpClient& client, const std::string& layer_id,
6161
const std::vector<std::string>& partitions,
6262
boost::optional<int64_t> version,
63-
boost::optional<std::vector<std::string>> additional_fields,
63+
const std::vector<std::string>& additional_fields,
6464
boost::optional<std::string> billing_tag,
6565
client::CancellationContext context) {
6666
std::multimap<std::string, std::string> header_params;
@@ -70,9 +70,9 @@ QueryApi::PartitionsResponse QueryApi::GetPartitionsbyId(
7070
for (const auto& partition : partitions) {
7171
query_params.emplace("partition", partition);
7272
}
73-
if (additional_fields) {
73+
if (!additional_fields.empty()) {
7474
query_params.insert(std::make_pair(
75-
"additionalFields", ConcatStringArray(*additional_fields, ",")));
75+
"additionalFields", ConcatStringArray(additional_fields, ",")));
7676
}
7777
if (billing_tag) {
7878
query_params.insert(std::make_pair("billingTag", *billing_tag));

olp-cpp-sdk-dataservice-read/src/generated/api/QueryApi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class QueryApi {
7272
const client::OlpClient& client, const std::string& layer_id,
7373
const std::vector<std::string>& partition,
7474
boost::optional<int64_t> version,
75-
boost::optional<std::vector<std::string>> additional_fields,
75+
const std::vector<std::string>& additional_fields,
7676
boost::optional<std::string> billing_tag,
7777
client::CancellationContext context);
7878

olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void from_json(const rapidjson::Value& value, model::Partition& x) {
3131
parse<boost::optional<int64_t>>(value, "compressedDataSize"));
3232
x.SetDataHandle(parse<std::string>(value, "dataHandle"));
3333
x.SetDataSize(parse<boost::optional<int64_t>>(value, "dataSize"));
34+
x.SetCrc(parse<boost::optional<std::string>>(value, "crc"));
3435
x.SetPartition(parse<std::string>(value, "partition"));
3536
x.SetVersion(parse<boost::optional<int64_t>>(value, "version"));
3637
}

olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void to_json(const dataservice::read::model::Partition& x,
3333
serialize("compressedDataSize", x.GetCompressedDataSize(), value, allocator);
3434
serialize("dataHandle", x.GetDataHandle(), value, allocator);
3535
serialize("dataSize", x.GetDataSize(), value, allocator);
36+
serialize("crc", x.GetCrc(), value, allocator);
3637
serialize("partition", x.GetPartition(), value, allocator);
3738
serialize("version", x.GetVersion(), value, allocator);
3839
}

olp-cpp-sdk-dataservice-read/src/repositories/PartitionsRepository.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ PartitionsResponse PartitionsRepository::GetPartitions(
141141
PartitionsResponse response;
142142

143143
const auto& partition_ids = request.GetPartitionIds();
144-
144+
145145
if (partition_ids.empty()) {
146146
auto metadata_api =
147147
ApiClientLookup::LookupApi(catalog, cancellation_context, "metadata",
@@ -152,8 +152,9 @@ PartitionsResponse PartitionsRepository::GetPartitions(
152152
}
153153

154154
response = MetadataApi::GetPartitions(
155-
metadata_api.GetResult(), layer, request.GetVersion(), boost::none,
156-
boost::none, request.GetBillingTag(), cancellation_context);
155+
metadata_api.GetResult(), layer, request.GetVersion(),
156+
request.GetAdditionalFields(), boost::none, request.GetBillingTag(),
157+
cancellation_context);
157158
} else {
158159
auto query_api =
159160
ApiClientLookup::LookupApi(catalog, cancellation_context, "query", "v1",
@@ -165,7 +166,8 @@ PartitionsResponse PartitionsRepository::GetPartitions(
165166

166167
response = QueryApi::GetPartitionsbyId(
167168
query_api.GetResult(), layer, partition_ids, request.GetVersion(),
168-
boost::none, request.GetBillingTag(), cancellation_context);
169+
request.GetAdditionalFields(), request.GetBillingTag(),
170+
cancellation_context);
169171
}
170172

171173
// Save all partitions only when downloaded via metadata API
@@ -235,8 +237,8 @@ PartitionsResponse PartitionsRepository::GetPartitionById(
235237
const client::OlpClient& client = query_api.GetResult();
236238

237239
PartitionsResponse query_response = QueryApi::GetPartitionsbyId(
238-
client, layer, partitions, version, boost::none,
239-
data_request.GetBillingTag(), cancellation_context);
240+
client, layer, partitions, version, {}, data_request.GetBillingTag(),
241+
cancellation_context);
240242

241243
if (query_response.IsSuccessful()) {
242244
OLP_SDK_LOG_INFO_F(kLogTag, "put '%s' to cache",

olp-cpp-sdk-dataservice-read/tests/ParserTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ TEST(ParserTest, Partitions) {
296296
\"compressedDataSize\": 1024,\
297297
\"dataHandle\": \"1b2ca68f-d4a0-4379-8120-cd025640510c\",\
298298
\"dataSize\": 1024,\
299+
\"crc\": \"291f66\",\
299300
\"partition\": \"314010583\",\
300301
\"version\": 2\
301302
}\
@@ -318,6 +319,8 @@ TEST(ParserTest, Partitions) {
318319
ASSERT_EQ(1024, *partitions.GetPartitions().at(0).GetCompressedDataSize());
319320
ASSERT_EQ("1b2ca68f-d4a0-4379-8120-cd025640510c",
320321
partitions.GetPartitions().at(0).GetDataHandle());
322+
ASSERT_TRUE(partitions.GetPartitions().at(0).GetCrc());
323+
ASSERT_EQ("291f66", *partitions.GetPartitions().at(0).GetCrc());
321324
ASSERT_TRUE(partitions.GetPartitions().at(0).GetDataSize());
322325
ASSERT_EQ(1024, *partitions.GetPartitions().at(0).GetDataSize());
323326
ASSERT_EQ("314010583", partitions.GetPartitions().at(0).GetPartition());

0 commit comments

Comments
 (0)