Skip to content

Commit b3a7ec8

Browse files
authored
VersionLayerClient adding GetAggregatedData API (#891)
New API fetches data of a tile or its closest ancestor. It can be useful when need to load most detailed available data for specified tile. Added integration tests to cover the API.� Resolves: OLPEDGE-1932 Signed-off-by: Kostiantyn Zvieriev <ext-kostiantyn.zvieriev@here.com>
1 parent 7a0c7d6 commit b3a7ec8

8 files changed

Lines changed: 870 additions & 76 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (C) 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 <utility>
23+
24+
#include <olp/core/geo/tiling/TileKey.h>
25+
#include <olp/dataservice/read/DataServiceReadApi.h>
26+
#include <olp/dataservice/read/model/Data.h>
27+
28+
namespace olp {
29+
namespace dataservice {
30+
namespace read {
31+
32+
/**
33+
* @brief Represents the result of a aggregated data operation.
34+
*/
35+
class DATASERVICE_READ_API AggregatedDataResult {
36+
public:
37+
AggregatedDataResult() = default;
38+
39+
virtual ~AggregatedDataResult() = default;
40+
41+
/**
42+
* @brief Sets the `TileKey` instance of this content.
43+
*
44+
* @param tile_key The fetched tile key.
45+
*/
46+
void SetTile(const geo::TileKey& tile_key) { tile_key_ = tile_key; }
47+
48+
/**
49+
* @brief Gets the requested TileKey or any of it's closest ancestor which
50+
* contains the related data.
51+
*
52+
* @return The fetched tile key.
53+
*/
54+
const geo::TileKey& GetTile() const { return tile_key_; }
55+
56+
/**
57+
* @brief Sets the data of the tile.
58+
*
59+
* @param data of the prefetched tile.
60+
*/
61+
void SetData(model::Data data) { data_ = std::move(data); }
62+
63+
/**
64+
* @brief Gets the data of the tile.
65+
*
66+
* @return The prefetched data of the tile.
67+
*/
68+
const model::Data& GetData() const { return data_; }
69+
70+
/**
71+
* @brief Moves the data.
72+
*
73+
* @return The forwarding reference to the data.
74+
*/
75+
model::Data&& MoveData() { return std::move(data_); }
76+
77+
private:
78+
geo::TileKey tile_key_;
79+
model::Data data_;
80+
};
81+
82+
} // namespace read
83+
} // namespace dataservice
84+
} // namespace olp

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <olp/core/client/ApiError.h>
2727
#include <olp/core/client/ApiResponse.h>
2828

29+
#include <olp/dataservice/read/AggregatedDataResult.h>
2930
#include <olp/dataservice/read/model/Catalog.h>
3031
#include <olp/dataservice/read/model/Data.h>
3132
#include <olp/dataservice/read/model/Messages.h>
@@ -75,6 +76,11 @@ using DataResponse = Response<DataResult>;
7576
/// The callback type of the data response.
7677
using DataResponseCallback = Callback<DataResult>;
7778

79+
/// The aggregated data response alias.
80+
using AggregatedDataResponse = Response<AggregatedDataResult>;
81+
/// The callback type of the aggregated data response.
82+
using AggregatedDataResponseCallback = Callback<AggregatedDataResult>;
83+
7884
/// The alias of the prefetch tiles result.
7985
using PrefetchTilesResult = std::vector<std::shared_ptr<PrefetchTileResult>>;
8086
/// The prefetch tiles response type.

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

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ class DATASERVICE_READ_API VersionedLayerClient final {
160160
* result and an error). If a partition ID or data handle is not set in
161161
* the request, the callback is invoked with the following error:
162162
* `ErrorCode::InvalidRequest`. If the version is not specified, an additional
163-
* request to the HERE platform is created to retrieve the latest available partition
164-
* version.
163+
* request to the HERE platform is created to retrieve the latest available
164+
* partition version.
165165
*
166166
* @param data_request The `DataRequest` instance that contains a complete set
167167
* of request parameters.
168-
* @note CacheWithUpdate fetch option is not suported.
168+
* @note CacheWithUpdate fetch option is not supported.
169169
* @param callback The `DataResponseCallback` object that is invoked if
170170
* the `DataResult` object is available or an error is encountered.
171171
*
@@ -185,7 +185,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
185185
*
186186
* @param data_request The `DataRequest` instance that contains a complete set
187187
* of request parameters.
188-
* @note CacheWithUpdate fetch option is not suported.
188+
* @note CacheWithUpdate fetch option is not supported.
189189
*
190190
* @return `CancellableFuture` that contains the `DataResponse` instance
191191
* or an error. You can also use `CancellableFuture` to cancel this request.
@@ -208,7 +208,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
208208
*
209209
* @param request The `TileRequest` instance that contains a complete set
210210
* of request parameters.
211-
* @note CacheWithUpdate fetch option is not suported.
211+
* @note CacheWithUpdate fetch option is not supported.
212212
* @param callback The `DataResponseCallback` object that is invoked if
213213
* the `DataResult` object is available or an error is encountered.
214214
*
@@ -232,12 +232,42 @@ class DATASERVICE_READ_API VersionedLayerClient final {
232232
*
233233
* @param request The `TileRequest` instance that contains a complete set
234234
* of request parameters.
235-
* @note CacheWithUpdate fetch option is not suported.
235+
* @note CacheWithUpdate fetch option is not supported.
236236
*
237237
* @return `CancellableFuture` that contains the `DataResponse` instance
238238
* or an error. You can also use `CancellableFuture` to cancel this request.
239239
*/
240240
client::CancellableFuture<DataResponse> GetData(TileRequest request);
241+
242+
/**
243+
* @brief Fetches data of a tile or its closest ancestor.
244+
*
245+
* @param request The `TileRequest` instance that contains a complete set
246+
* of request parameters.
247+
* @note CacheWithUpdate fetch option is not supported.
248+
* @param callback The `AggregatedDataResponseCallback` object that is invoked
249+
* if the `AggregatedDataResult` object is available or an error is
250+
* encountered.
251+
*
252+
* @return A token that can be used to cancel this request.
253+
*/
254+
client::CancellationToken GetAggregatedData(
255+
TileRequest request, AggregatedDataResponseCallback callback);
256+
257+
/**
258+
* @brief Fetches data of a tile or its closest ancestor.
259+
*
260+
* @param request The `TileRequest` instance that contains a complete set
261+
* of request parameters.
262+
* @note CacheWithUpdate fetch option is not supported.
263+
*
264+
* @return `CancellableFuture` that contains the `AggregatedDataResponse`
265+
* instance or an error. You can also use `CancellableFuture` to cancel this
266+
* request.
267+
*/
268+
client::CancellableFuture<AggregatedDataResponse> GetAggregatedData(
269+
TileRequest request);
270+
241271
/**
242272
* @brief Fetches a list of partitions of the given generic layer
243273
* asynchronously.
@@ -248,7 +278,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
248278
*
249279
* @param partitions_request The `PartitionsRequest` instance that contains
250280
* a complete set of request parameters.
251-
* @note CacheWithUpdate fetch option is not suported.
281+
* @note CacheWithUpdate fetch option is not supported.
252282
* @param callback The `PartitionsResponseCallback` object that is invoked if
253283
* the list of partitions is available or an error is encountered.
254284
*
@@ -267,7 +297,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
267297
*
268298
* @param partitions_request The `PartitionsRequest` instance that contains
269299
* a complete set of request parameters.
270-
* @note CacheWithUpdate fetch option is not suported.
300+
* @note CacheWithUpdate fetch option is not supported.
271301
*
272302
* @return `CancellableFuture` that contains the `PartitionsResponse` instance
273303
* with data or an error. You can also use `CancellableFuture` to cancel this

olp-cpp-sdk-dataservice-read/src/VersionedLayerClient.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ bool VersionedLayerClient::RemoveFromCache(const geo::TileKey& tile) {
102102
return impl_->RemoveFromCache(tile);
103103
}
104104

105+
client::CancellationToken VersionedLayerClient::GetAggregatedData(
106+
TileRequest request, AggregatedDataResponseCallback callback) {
107+
return impl_->GetAggregatedData(std::move(request), std::move(callback));
108+
}
109+
110+
client::CancellableFuture<AggregatedDataResponse>
111+
VersionedLayerClient::GetAggregatedData(TileRequest request) {
112+
return impl_->GetAggregatedData(std::move(request));
113+
}
105114

106115
} // namespace read
107116
} // namespace dataservice

olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#include <olp/core/logging/Log.h>
2828
#include <olp/core/thread/TaskScheduler.h>
2929
#include <olp/dataservice/read/CatalogVersionRequest.h>
30+
#include "ApiClientLookup.h"
3031
#include "Common.h"
32+
#include "generated/api/QueryApi.h"
3133
#include "repositories/CatalogRepository.h"
3234
#include "repositories/DataCacheRepository.h"
3335
#include "repositories/DataRepository.h"
@@ -517,6 +519,80 @@ bool VersionedLayerClientImpl::RemoveFromCache(const geo::TileKey& tile) {
517519
return RemoveFromCache(partition_id);
518520
}
519521

522+
client::CancellationToken VersionedLayerClientImpl::GetAggregatedData(
523+
TileRequest request, AggregatedDataResponseCallback callback) {
524+
auto catalog = catalog_;
525+
auto layer_id = layer_id_;
526+
auto settings = settings_;
527+
auto pending_requests = pending_requests_;
528+
529+
auto data_task =
530+
[=](client::CancellationContext context) -> AggregatedDataResponse {
531+
if (request.GetFetchOption() == CacheWithUpdate) {
532+
return {{client::ErrorCode::InvalidArgument,
533+
"CacheWithUpdate option can not be used for versioned "
534+
"layer"}};
535+
}
536+
537+
if (!request.GetTileKey().IsValid()) {
538+
return {{client::ErrorCode::InvalidArgument, "Tile key is invalid"}};
539+
}
540+
541+
auto version_response =
542+
GetVersion(request.GetBillingTag(), request.GetFetchOption(), context);
543+
if (!version_response.IsSuccessful()) {
544+
return version_response.GetError();
545+
}
546+
547+
auto version = version_response.GetResult().GetVersion();
548+
auto partition_response =
549+
repository::PartitionsRepository::GetAggregatedTile(
550+
catalog, layer_id, context, request, version, settings);
551+
if (!partition_response.IsSuccessful()) {
552+
return partition_response.GetError();
553+
}
554+
555+
const auto& fetch_partition = partition_response.GetResult();
556+
const auto fetch_tile_key =
557+
geo::TileKey::FromHereTile(fetch_partition.GetPartition());
558+
559+
auto data_request = DataRequest()
560+
.WithDataHandle(fetch_partition.GetDataHandle())
561+
.WithFetchOption(request.GetFetchOption());
562+
auto data_response = repository::DataRepository::GetVersionedData(
563+
std::move(catalog), std::move(layer_id), data_request, context,
564+
std::move(settings));
565+
566+
if (!data_response.IsSuccessful()) {
567+
OLP_SDK_LOG_WARNING_F(
568+
kLogTag,
569+
"GetAggregatedData: failed to load data, key=%s, data_hanndle=%s",
570+
fetch_tile_key.ToHereTile().c_str(),
571+
fetch_partition.GetDataHandle().c_str());
572+
return data_response.GetError();
573+
}
574+
575+
AggregatedDataResult result;
576+
result.SetTile(fetch_tile_key);
577+
result.SetData(data_response.MoveResult());
578+
579+
return std::move(result);
580+
};
581+
582+
return AddTask(settings.task_scheduler, pending_requests,
583+
std::move(data_task), std::move(callback));
584+
}
585+
586+
client::CancellableFuture<AggregatedDataResponse>
587+
VersionedLayerClientImpl::GetAggregatedData(TileRequest request) {
588+
auto promise = std::make_shared<std::promise<AggregatedDataResponse>>();
589+
auto cancel_token = GetAggregatedData(
590+
std::move(request), [promise](AggregatedDataResponse response) {
591+
promise->set_value(std::move(response));
592+
});
593+
return client::CancellableFuture<AggregatedDataResponse>(
594+
std::move(cancel_token), std::move(promise));
595+
}
520596
PORTING_POP_WARNINGS()
521597
} // namespace read
522598
} // namespace dataservice

olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ class VersionedLayerClientImpl {
8585

8686
virtual bool RemoveFromCache(const geo::TileKey& tile);
8787

88+
virtual client::CancellationToken GetAggregatedData(
89+
TileRequest request, AggregatedDataResponseCallback callback);
90+
91+
virtual client::CancellableFuture<AggregatedDataResponse> GetAggregatedData(
92+
TileRequest request);
93+
8894
private:
8995
CatalogVersionResponse GetVersion(boost::optional<std::string> billing_tag,
9096
const FetchOptions& fetch_options,

tests/integration/olp-cpp-sdk-dataservice-read/HttpResponses.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@
201201
#define URL_QUADKEYS_92259 \
202202
R"(https://query.data.api.platform.here.com/query/v1/catalogs/hereos-internal-test-v2/layers/hype-test-prefetch/versions/4/quadkeys/92259/depths/4)"
203203

204+
#define URL_QUADKEYS_AGGREGATE_92259 \
205+
R"(https://query.data.api.platform.here.com/query/v1/catalogs/hereos-internal-test-v2/layers/testlayer/versions/108/quadkeys/92259/depths/4)"
206+
204207
#define URL_QUADKEYS_VOLATILE_23618364 \
205208
R"(https://query.data.api.platform.here.com/query/v1/catalogs/hereos-internal-test-v2/layers/hype-test-prefetch/quadkeys/23618364/depths/0)"
206209

@@ -267,6 +270,9 @@
267270
#define URL_BLOB_DATA_VOLATILE_PREFETCH_7 \
268271
R"(https://volatile-blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/hype-test-prefetch/data/95c5c703-e00e-4c38-841e-e419367474f1)"
269272

273+
#define URL_BLOB_AGGREGATE_DATA \
274+
R"(https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/testlayer/data/f9a9fd8e-eb1b-48e5-bfdb-4392b3826443)"
275+
270276
#define URL_VOLATILE_BLOB_DATA \
271277
R"(https://volatile-blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/testlayer_volatile/data/4eed6ed1-0d32-43b9-ae79-043cb4256410)"
272278

@@ -288,6 +294,18 @@
288294
#define HTTP_RESPONSE_QUADKEYS_92259 \
289295
R"jsonString({"subQuads": [{"subQuadKey":"19","version":4,"dataHandle":"95c5c703-e00e-4c38-841e-e419367474f1"},{"subQuadKey":"311","version":4,"dataHandle":"2d696e1f-4145-4bc9-b2b0-7420d1bc78c2"},{"subQuadKey":"316","version":4,"dataHandle":"f9a9fd8e-eb1b-48e5-bfdb-4392b3826443"},{"subQuadKey":"317","version":4,"dataHandle":"e119d20e-c7c6-4563-ae88-8aa5c6ca75c3"},{"subQuadKey":"318","version":4,"dataHandle":"a7a1afdf-db7e-4833-9627-d38bee6e2f81"},{"subQuadKey":"319","version":4,"dataHandle":"9d515348-afce-44e8-bc6f-3693cfbed104"},{"subQuadKey":"79","version":4,"dataHandle":"e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1"}],"parentQuads": []})jsonString"
290296

297+
#define HTTP_RESPONSE_QUADKEYS_92259_ROOT_ONLY \
298+
R"jsonString({"subQuads": [{"subQuadKey":"1","version":4,"dataHandle":"f9a9fd8e-eb1b-48e5-bfdb-4392b3826443"}],"parentQuads": []})jsonString"
299+
300+
#define HTTP_RESPONSE_QUADKEYS_92259_NO_ANCESTORS \
301+
R"jsonString({"subQuads": [{"subQuadKey":"311","version":4,"dataHandle":"2d696e1f-4145-4bc9-b2b0-7420d1bc78c2"},{"subQuadKey":"317","version":4,"dataHandle":"e119d20e-c7c6-4563-ae88-8aa5c6ca75c3"},{"subQuadKey":"318","version":4,"dataHandle":"a7a1afdf-db7e-4833-9627-d38bee6e2f81"},{"subQuadKey":"319","version":4,"dataHandle":"9d515348-afce-44e8-bc6f-3693cfbed104"}],"parentQuads": []})jsonString"
302+
303+
#define HTTP_RESPONSE_QUADKEYS_92259_PARENT \
304+
R"jsonString({"subQuads": [{"subQuadKey":"311","version":4,"dataHandle":"2d696e1f-4145-4bc9-b2b0-7420d1bc78c2"},{"subQuadKey":"317","version":4,"dataHandle":"e119d20e-c7c6-4563-ae88-8aa5c6ca75c3"},{"subQuadKey":"318","version":4,"dataHandle":"a7a1afdf-db7e-4833-9627-d38bee6e2f81"},{"subQuadKey":"319","version":4,"dataHandle":"9d515348-afce-44e8-bc6f-3693cfbed104"}],"parentQuads": [{"partition":"22","version":282,"dataHandle":"f9a9fd8e-eb1b-48e5-bfdb-4392b3826443","dataSize":52438}]})jsonString"
305+
306+
#define HTTP_RESPONSE_NO_QUADS \
307+
R"jsonString({"subQuads": [],"parentQuads": []})jsonString"
308+
291309
#define HTTP_RESPONSE_BLOB_DATA_PREFETCH_1 \
292310
R"(--644ff000-704a-4f45-9988-c628602b7064)"
293311

0 commit comments

Comments
 (0)