Skip to content

Commit d9ea038

Browse files
author
Liubov Didkivska
authored
Optimize quad tree index for GetData(TileRequest) (#820)
Change VersionedLayerData::GetData(TileRequest) to request quad tree for parrent tile. Relates-To: OLPEDGE-1894 Signed-off-by: Liubov Didkivska <[email protected]>
1 parent 3717ef2 commit d9ea038

File tree

6 files changed

+48
-47
lines changed

6 files changed

+48
-47
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,14 @@ client::CancellationToken VersionedLayerClientImpl::GetData(
447447
std::move(callback));
448448
}
449449

450+
if (!request.GetTileKey().IsValid()) {
451+
auto task = [](client::CancellationContext) -> DataResponse {
452+
return {{client::ErrorCode::InvalidArgument, "Tile key is invalid"}};
453+
};
454+
return AddTask(settings_.task_scheduler, pending_requests_, std::move(task),
455+
std::move(callback));
456+
}
457+
450458
auto schedule_get_data = [&](TileRequest request,
451459
DataResponseCallback callback) {
452460
auto catalog = catalog_;

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,10 @@ PartitionsResponse PartitionsRepository::QueryPartitionForVersionedTile(
316316
client::CancellationContext context, client::OlpClientSettings settings) {
317317
auto fetch_option = request.GetFetchOption();
318318
const auto& tile_key = request.GetTileKey();
319-
auto tile = tile_key.ToHereTile();
319+
const auto& parent_tile_key =
320+
tile_key.ChangedLevelBy(-kMaxQuadTreeIndexDepth);
321+
auto parent_tile = parent_tile_key.ToHereTile();
322+
320323
auto query_api = ApiClientLookup::LookupApi(
321324
catalog, context, "query", "v1", request.GetFetchOption(), settings);
322325

@@ -327,13 +330,13 @@ PartitionsResponse PartitionsRepository::QueryPartitionForVersionedTile(
327330
}
328331

329332
auto quad_tree = QueryApi::QuadTreeIndex(
330-
query_api.GetResult(), layer_id, version, tile, kMaxQuadTreeIndexDepth,
331-
boost::none, request.GetBillingTag(), context);
333+
query_api.GetResult(), layer_id, version, parent_tile,
334+
kMaxQuadTreeIndexDepth, boost::none, request.GetBillingTag(), context);
332335

333336
if (!quad_tree.IsSuccessful()) {
334337
OLP_SDK_LOG_ERROR_F(kLogTag,
335338
"QuadTreeIndex failed (%s, %" PRId64 ", %" PRId32 ")",
336-
tile.c_str(), version, kMaxQuadTreeIndexDepth);
339+
parent_tile.c_str(), version, kMaxQuadTreeIndexDepth);
337340
return quad_tree.GetError();
338341
}
339342
model::Partitions result;
@@ -346,8 +349,7 @@ PartitionsResponse PartitionsRepository::QueryPartitionForVersionedTile(
346349
subquads.size());
347350

348351
for (const auto& subquad : subquads) {
349-
auto subtile =
350-
request.GetTileKey().AddedSubHereTile(subquad->GetSubQuadKey());
352+
auto subtile = parent_tile_key.AddedSubHereTile(subquad->GetSubQuadKey());
351353
// add partitions for caching
352354
partitions_vector.emplace_back(
353355
PartitionFromSubQuad(*subquad, subtile.ToHereTile()));

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
#define URL_BLOB_DATA_5904591 \
4242
R"(https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/testlayer/data/e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1)"
4343

44-
#define URL_BLOB_DATA_23618364 \
45-
R"(https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/testlayer/data/f9a9fd8e-eb1b-48e5-bfdb-4392b3826443)"
44+
#define URL_BLOB_DATA_1476147 \
45+
R"(https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/testlayer/data/95c5c703-e00e-4c38-841e-e419367474f1)"
4646

4747
#define HTTP_RESPONSE_LOOKUP_BLOB \
4848
R"jsonString([{"api":"blob","version":"v1","baseURL":"https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2","parameters":{}}])jsonString"
@@ -52,27 +52,17 @@
5252

5353
#define BLOB_DATA_HANDLE R"(4eed6ed1-0d32-43b9-ae79-043cb4256432)"
5454

55-
#define BLOB_DATA_HANDLE_23618364 R"(f9a9fd8e-eb1b-48e5-bfdb-4392b3826443)"
56-
57-
#define BLOB_DATA_HANDLE_5904591 R"(e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1)"
58-
5955
#define URL_LOOKUP_QUERY \
6056
R"(https://api-lookup.data.api.platform.here.com/lookup/v1/resources/hrn:here:data::olp-here-test:hereos-internal-test-v2/apis/query/v1)"
6157

6258
#define HTTP_RESPONSE_LOOKUP_QUERY \
6359
R"jsonString([{"api":"query","version":"v1","baseURL":"https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2","parameters":{}}])jsonString"
6460

6561
#define QUERY_TREE_INDEX \
66-
R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/testlayer/versions/4/quadkeys/5904591/depths/4)"
62+
R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/testlayer/versions/4/quadkeys/23064/depths/4)"
6763

6864
#define SUB_QUADS \
69-
R"jsonString({"subQuads": [{"subQuadKey":"4","version":4,"dataHandle":"f9a9fd8e-eb1b-48e5-bfdb-4392b3826443"},{"subQuadKey":"5","version":4,"dataHandle":"e119d20e-c7c6-4563-ae88-8aa5c6ca75c3"},{"subQuadKey":"6","version":4,"dataHandle":"a7a1afdf-db7e-4833-9627-d38bee6e2f81"},{"subQuadKey":"7","version":4,"dataHandle":"9d515348-afce-44e8-bc6f-3693cfbed104"},{"subQuadKey":"1","version":4,"dataHandle":"e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1"}],"parentQuads": [{"partition":"1476147","version":4,"dataHandle":"95c5c703-e00e-4c38-841e-e419367474f1"}]})jsonString"
70-
71-
#define QUERY_PARTITION_23618364 \
72-
R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/testlayer/partitions?partition=23618364&version=4)"
73-
74-
#define RESPONSE_PARTITION_23618364 \
75-
R"jsonString({ "partitions": [{"version":4,"partition":"23618364","layer":"testlayer","dataHandle":"f9a9fd8e-eb1b-48e5-bfdb-4392b3826443"}]})jsonString"
65+
R"jsonString({"subQuads": [{"subQuadKey":"115","version":4,"dataHandle":"95c5c703-e00e-4c38-841e-e419367474f1"},{"subQuadKey":"463","version":4,"dataHandle":"e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1"}],"parentQuads": []})jsonString"
7666

7767
namespace {
7868

@@ -328,13 +318,13 @@ TEST_F(DataRepositoryTest, GetVersionedDataTile) {
328318
HTTP_RESPONSE_LOOKUP_BLOB));
329319

330320
EXPECT_CALL(*network_mock_,
331-
Send(IsGetRequest(URL_BLOB_DATA_23618364), _, _, _, _))
321+
Send(IsGetRequest(URL_BLOB_DATA_1476147), _, _, _, _))
332322
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
333323
olp::http::HttpStatusCode::OK),
334324
"someData"));
335325

336326
auto request = olp::dataservice::read::TileRequest().WithTileKey(
337-
olp::geo::TileKey::FromHereTile("23618364"));
327+
olp::geo::TileKey::FromHereTile("1476147"));
338328
olp::client::CancellationContext context;
339329
auto response =
340330
olp::dataservice::read::repository::DataRepository::GetVersionedTile(

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const std::string
107107

108108
const std::string kOlpSdkUrlLookupMetadata2 =
109109
R"(https://api-lookup.data.api.platform.here.com/lookup/v1/resources/hrn:here:data::olp-here-test:hereos-internal-test-v2/apis/metadata/v1)";
110+
110111
const std::string kOlpSdkHttpResponseLookupMetadata2 =
111112
R"jsonString([{"api":"metadata","version":"v1","baseURL":"https://metadata.data.api.platform.here.com/metadata/v1/catalogs/hereos-internal-test-v2","parameters":{}}])jsonString";
112113

@@ -128,13 +129,13 @@ const std::string kHttpResponceLookupQuery =
128129
R"jsonString([{"api":"query","version":"v1","baseURL":"https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2","parameters":{}}])jsonString";
129130

130131
const std::string kQueryTreeIndex =
131-
R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/testlayer/versions/4/quadkeys/5904591/depths/4)";
132+
R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/testlayer/versions/4/quadkeys/23064/depths/4)";
132133

133134
const std::string kSubQuads =
134-
R"jsonString({"subQuads": [{"subQuadKey":"4","version":4,"dataHandle":"f9a9fd8e-eb1b-48e5-bfdb-4392b3826443"},{"subQuadKey":"5","version":4,"dataHandle":"e119d20e-c7c6-4563-ae88-8aa5c6ca75c3"},{"subQuadKey":"6","version":4,"dataHandle":"a7a1afdf-db7e-4833-9627-d38bee6e2f81"},{"subQuadKey":"7","version":4,"dataHandle":"9d515348-afce-44e8-bc6f-3693cfbed104"},{"subQuadKey":"1","version":4,"dataHandle":"e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1"}],"parentQuads": [{"partition":"1476147","version":4,"dataHandle":"95c5c703-e00e-4c38-841e-e419367474f1"}]})jsonString";
135+
R"jsonString({"subQuads": [{"subQuadKey":"115","version":4,"dataHandle":"95c5c703-e00e-4c38-841e-e419367474f1"},{"subQuadKey":"463","version":4,"dataHandle":"e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1"}],"parentQuads": []})jsonString";
135136

136-
const std::string kBlobDataHandle23618364 =
137-
R"(f9a9fd8e-eb1b-48e5-bfdb-4392b3826443)";
137+
const std::string kBlobDataHandle1476147 =
138+
R"(95c5c703-e00e-4c38-841e-e419367474f1)";
138139

139140
class PartitionsRepositoryTest : public ::testing::Test,
140141
protected repository::PartitionsRepository {};
@@ -866,13 +867,13 @@ TEST_F(PartitionsRepositoryTest, CheckCashedPartitions) {
866867
SCOPED_TRACE(
867868
"Check if all partitions stored in cache, request another tile");
868869
auto request = olp::dataservice::read::TileRequest().WithTileKey(
869-
olp::geo::TileKey::FromHereTile("23618364"));
870+
olp::geo::TileKey::FromHereTile("1476147"));
870871
auto partitions = GetTileFromCache(hrn, layer, request, version, settings);
871872

872873
// check if partition was stored to cache
873874
ASSERT_FALSE(partitions.GetPartitions().size() == 0);
874875
ASSERT_EQ(partitions.GetPartitions().front().GetDataHandle(),
875-
kBlobDataHandle23618364);
876+
kBlobDataHandle1476147);
876877
}
877878
}
878879

@@ -920,7 +921,7 @@ TEST_F(PartitionsRepositoryTest, GetPartitionForVersionedTile) {
920921
.Times(0);
921922

922923
auto request = olp::dataservice::read::TileRequest().WithTileKey(
923-
olp::geo::TileKey::FromHereTile("23618364"));
924+
olp::geo::TileKey::FromHereTile("1476147"));
924925
olp::client::CancellationContext context;
925926
auto response = PartitionsRepository::GetPartitionForVersionedTile(
926927
hrn, layer, request, version, context, settings);
@@ -929,7 +930,7 @@ TEST_F(PartitionsRepositoryTest, GetPartitionForVersionedTile) {
929930
ASSERT_TRUE(response.IsSuccessful());
930931
ASSERT_TRUE(response.GetResult().GetPartitions().size() == 1);
931932
ASSERT_EQ(response.GetResult().GetPartitions().front().GetDataHandle(),
932-
kBlobDataHandle23618364);
933+
kBlobDataHandle1476147);
933934
}
934935
}
935936
} // namespace

tests/functional/olp-cpp-sdk-dataservice-read/DataserviceReadVersionedLayerClientTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetTileEmptyField) {
850850
});
851851

852852
EXPECT_FALSE(data_response_compressed.IsSuccessful());
853-
ASSERT_EQ(olp::client::ErrorCode::NotFound,
853+
ASSERT_EQ(olp::client::ErrorCode::InvalidArgument,
854854
data_response_compressed.GetError().GetErrorCode());
855855
}
856856

tests/integration/olp-cpp-sdk-dataservice-read/VersionedLayerClientTest.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ constexpr char kHttpLookupQuery[] =
9898
constexpr char kHttpResponseLookupApiQuery[] =
9999
R"jsonString([{"api":"query","version":"v1","baseURL":"https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:here-optimized-map-for-visualization-2","parameters":{}}])jsonString";
100100

101-
constexpr char kHttpQueryTreeIndex[] =
102-
R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:here-optimized-map-for-visualization-2/layers/testlayer/versions/4/quadkeys/5904591/depths/4)";
101+
constexpr char kHttpQueryTreeIndex_23064[] =
102+
R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:here-optimized-map-for-visualization-2/layers/testlayer/versions/4/quadkeys/23064/depths/4)";
103103

104-
constexpr char kHttpSubQuads[] =
105-
R"jsonString({"subQuads": [{"subQuadKey":"4","version":4,"dataHandle":"f9a9fd8e-eb1b-48e5-bfdb-4392b3826443"},{"subQuadKey":"5","version":4,"dataHandle":"e119d20e-c7c6-4563-ae88-8aa5c6ca75c3"},{"subQuadKey":"6","version":4,"dataHandle":"a7a1afdf-db7e-4833-9627-d38bee6e2f81"},{"subQuadKey":"7","version":4,"dataHandle":"9d515348-afce-44e8-bc6f-3693cfbed104"},{"subQuadKey":"1","version":4,"dataHandle":"e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1"}],"parentQuads": [{"partition":"1476147","version":4,"dataHandle":"95c5c703-e00e-4c38-841e-e419367474f1"}]})jsonString";
104+
constexpr char kHttpSubQuads_23064[] =
105+
R"jsonString({"subQuads": [{"subQuadKey":"115","version":4,"dataHandle":"95c5c703-e00e-4c38-841e-e419367474f1"},{"subQuadKey":"463","version":4,"dataHandle":"e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1"}],"parentQuads": []})jsonString";
106106

107-
constexpr char kUrlBlobData_23618364[] =
108-
R"(https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/here-optimized-map-for-visualization-2/layers/testlayer/data/f9a9fd8e-eb1b-48e5-bfdb-4392b3826443)";
107+
constexpr char kUrlBlobData_1476147[] =
108+
R"(https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/here-optimized-map-for-visualization-2/layers/testlayer/data/95c5c703-e00e-4c38-841e-e419367474f1)";
109109

110110
constexpr auto kUrlPartitionsPrefix =
111111
R"(https://query.data.api.platform.here.com/query/v1/catalogs/here-optimized-map-for-visualization-2/layers/testlayer/partitions)";
@@ -2593,10 +2593,10 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetTile) {
25932593
kHttpResponseLookupApiQuery));
25942594

25952595
EXPECT_CALL(*network_mock_,
2596-
Send(IsGetRequest(kHttpQueryTreeIndex), _, _, _, _))
2596+
Send(IsGetRequest(kHttpQueryTreeIndex_23064), _, _, _, _))
25972597
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
25982598
olp::http::HttpStatusCode::OK),
2599-
kHttpSubQuads));
2599+
kHttpSubQuads_23064));
26002600

26012601
EXPECT_CALL(*network_mock_, Send(IsGetRequest(URL_LOOKUP_BLOB), _, _, _, _))
26022602
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
@@ -2633,7 +2633,7 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetTileCacheOnly) {
26332633
.Times(0);
26342634

26352635
EXPECT_CALL(*network_mock_,
2636-
Send(IsGetRequest(kHttpQueryTreeIndex), _, _, _, _))
2636+
Send(IsGetRequest(kHttpQueryTreeIndex_23064), _, _, _, _))
26372637
.Times(0);
26382638

26392639
EXPECT_CALL(*network_mock_, Send(IsGetRequest(URL_LOOKUP_BLOB), _, _, _, _))
@@ -2664,10 +2664,10 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetTileOnlineOnly) {
26642664
kHttpResponseLookupApiQuery));
26652665

26662666
EXPECT_CALL(*network_mock_,
2667-
Send(IsGetRequest(kHttpQueryTreeIndex), _, _, _, _))
2667+
Send(IsGetRequest(kHttpQueryTreeIndex_23064), _, _, _, _))
26682668
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
26692669
olp::http::HttpStatusCode::OK),
2670-
kHttpSubQuads));
2670+
kHttpSubQuads_23064));
26712671

26722672
EXPECT_CALL(*network_mock_, Send(IsGetRequest(URL_LOOKUP_BLOB), _, _, _, _))
26732673
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
@@ -2749,10 +2749,10 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetTileTwoSequentialCalls) {
27492749
kHttpResponseLookupApiQuery));
27502750

27512751
EXPECT_CALL(*network_mock_,
2752-
Send(IsGetRequest(kHttpQueryTreeIndex), _, _, _, _))
2752+
Send(IsGetRequest(kHttpQueryTreeIndex_23064), _, _, _, _))
27532753
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
27542754
olp::http::HttpStatusCode::OK),
2755-
kHttpSubQuads));
2755+
kHttpSubQuads_23064));
27562756

27572757
EXPECT_CALL(*network_mock_, Send(IsGetRequest(URL_LOOKUP_BLOB), _, _, _, _))
27582758
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
@@ -2784,20 +2784,20 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetTileTwoSequentialCalls) {
27842784
.Times(0);
27852785

27862786
EXPECT_CALL(*network_mock_,
2787-
Send(IsGetRequest(kHttpQueryTreeIndex), _, _, _, _))
2787+
Send(IsGetRequest(kHttpQueryTreeIndex_23064), _, _, _, _))
27882788
.Times(0);
27892789

27902790
EXPECT_CALL(*network_mock_, Send(IsGetRequest(URL_LOOKUP_BLOB), _, _, _, _))
27912791
.Times(0);
27922792

27932793
EXPECT_CALL(*network_mock_,
2794-
Send(IsGetRequest(kUrlBlobData_23618364), _, _, _, _))
2794+
Send(IsGetRequest(kUrlBlobData_1476147), _, _, _, _))
27952795
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
27962796
olp::http::HttpStatusCode::OK),
27972797
"someOtherData"));
27982798

27992799
auto request = olp::dataservice::read::TileRequest().WithTileKey(
2800-
olp::geo::TileKey::FromHereTile("23618364"));
2800+
olp::geo::TileKey::FromHereTile("1476147"));
28012801
auto future = client->GetData(request);
28022802
auto data_response = future.GetFuture().get();
28032803
ASSERT_TRUE(data_response.IsSuccessful())

0 commit comments

Comments
 (0)