Skip to content

Commit 4980310

Browse files
Update the read example and documentation to reflect the latest changes.
Relates-To: OLPEDGE-840 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent defb939 commit 4980310

File tree

3 files changed

+44
-49
lines changed

3 files changed

+44
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* `KeyValueCache` instance was added to `OlpClientSetting`.
1212
* Boost download source was changed.
1313
* Added `Condition` class helping repositories sync wait on the OLP response.
14+
* Updated read example and documentation to reflect recent changes in API.
1415

1516
**olp-cpp-sdk-authentication**
1617

docs/dataservice-read-catalog-example.md

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ client_settings.cache =
167167
olp::client::OlpClientSettingsFactory::CreateDefaultCache({});
168168

169169
// Create a CatalogClient with appropriate HRN and settings.
170-
auto service_client = std::make_unique<olp::dataservice::read::CatalogClient>(
171-
olp::client::HRN(kCatalogHRN), std::move(client_settings));
170+
olp::dataservice::read::CatalogClient catalog_client(
171+
olp::client::HRN(kCatalogHRN), client_settings);
172172
```
173173
174174
The `OlpClientSettings` class pulls together all the different settings for customization of the client library behavior.
@@ -196,7 +196,7 @@ Then pass it to the `CatalogClient` via `GetCatalog` method:
196196

197197
```cpp
198198
// Run the CatalogRequest
199-
auto future = serviceClient->GetCatalog(request);
199+
auto future = catalog_client.GetCatalog(request);
200200
```
201201

202202
The execution result is a `CancellableFuture` that contains `CatalogResponse` object. The `CatalogResponse` class holds details of the completed operation and is used to determine operation success and access resultant data.
@@ -207,18 +207,16 @@ The execution result is a `CancellableFuture` that contains `CatalogResponse` ob
207207

208208
```cpp
209209
// Wait for the CatalogResponse response
210-
olp::dataservice::read::CatalogResponse catalogResponse =
210+
olp::dataservice::read::CatalogResponse catalog_response =
211211
future.GetFuture().get();
212212

213213
// Check the response
214-
if (catalogResponse.IsSuccessful()) {
215-
const olp::dataservice::read::CatalogResult& responseResult =
216-
catalogResponse.GetResult();
217-
OLP_SDK_LOG_INFO_F("read-example", "Catalog description: %s",
218-
responseResult.GetDescription().c_str());
214+
if (catalog_response.IsSuccessful()) {
215+
const olp::dataservice::read::CatalogResult& response_result =
216+
catalog_response.GetResult();
217+
// Handle success
219218
} else {
220-
OLP_SDK_LOG_ERROR("read-example",
221-
"Request catalog metadata - Failure");
219+
// Handle fail
222220
}
223221
```
224222

@@ -250,20 +248,22 @@ The `ApiError` class contains details regarding to the incurred error, including
250248
To retrieve partition metadata, create a `PartitionsRequest`. The `PartitionsRequest` class allows to set the properties of the catalog request, including:
251249

252250
* `WithBillingTag`: Sets the billing tag used for this request.
253-
* `WithLayerId`: Sets the layer id that partition metadata is retrieved from.
254251

255252
```cpp
256253
// Create a PartitionsRequest with appropriate LayerId
257254
auto request = olp::dataservice::read::PartitionsRequest()
258-
.WithLayerId(gLayerId)
259255
.WithBillingTag(boost::none);
260256
```
261257

262-
Then pass it to the `CatalogClient` via `GetPartitions` method:
258+
Then pass it to the appropriate layer client, i.e. `VersionedLayerClient` via `GetPartitions` method:
263259

264260
```cpp
261+
// Create appropriate layer client with HRN, layer name and settings.
262+
olp::dataservice::read::VersionedLayerClient layer_client(
263+
olp::client::HRN(kCatalogHRN), first_layer_id, client_settings);
264+
265265
// Run the PartitionsRequest
266-
auto future = serviceClient->GetPartitions(request);
266+
auto future = layer_client.GetPartitions(request);
267267
```
268268
269269
The execution result is a `CancellableFuture` that contains `PartitionsResponse` object. The `PartitionsResponse` class holds the details of the completed operation and is used to determine operation success and access resultant data.
@@ -274,20 +274,16 @@ The execution result is a `CancellableFuture` that contains `PartitionsResponse`
274274
275275
```cpp
276276
// Wait for PartitionsResponse
277-
olp::dataservice::read::PartitionsResponse partitionsResponse =
277+
olp::dataservice::read::PartitionsResponse partitions_response =
278278
future.GetFuture().get();
279-
279+
280280
// Check the response
281-
if (partitionsResponse.IsSuccessful()) {
282-
const olp::dataservice::read::PartitionsResult& responseResult =
283-
partitionsResponse.GetResult();
284-
const std::vector<olp::dataservice::read::model::Partition>& partitions =
285-
responseResult.GetPartitions();
286-
OLP_SDK_LOG_INFO_F("read-example", "Layer contains %d partitions.",
287-
partitions.size());
281+
if (partitions_response.IsSuccessful()) {
282+
const olp::dataservice::read::PartitionsResult& response_result =
283+
partitions_response.GetResult();
284+
// Handle success
288285
} else {
289-
OLP_SDK_LOG_ERROR("read-example",
290-
"Request partition metadata - Failure");
286+
// Handle fail
291287
}
292288
```
293289

@@ -299,7 +295,7 @@ The `Partition` class contains partition metadata and exposes the following memb
299295

300296
* `GetChecksum`: Partition checksum.
301297
* `GetCompressedDataSize`: Returns the size of the compressed partition data.
302-
* `GetDataHandle`: Returns the handle that can be used by the `CatalogClient::GetData` function to retrieve the partition data.
298+
* `GetDataHandle`: Returns the handle that can be used by the `GetData` function to retrieve the partition data.
303299
* `GetDataSize`: Returns the size of the partition data.
304300
* `GetPartition`: Returns the partition Id.
305301
* `GetVersion`: Returns the latest catalog version for the partition.
@@ -308,43 +304,38 @@ The `Partition` class contains partition metadata and exposes the following memb
308304

309305
To retrieve partition data, create the `DataRequest`. The `DataRequest` class allows to specify the parameters of the `GetData` function, including:
310306

311-
* `WithLayerId`: Sets the layer id to use it for the request.
312307
* `WithPartitionId`: Sets the partition for the data request.
313308
* `WithDataHandle`: Sets the requested data handle, which can be found via the GetPartition call in the `olp::dataservice::read::model::Partition::GetDataHandle` member.
314309
* `WithBillingTag`: Sets the billing tag for the request.
315310

316311
```cpp
317312
// Create a DataRequest with appropriate LayerId and PartitionId
318313
auto request = olp::dataservice::read::DataRequest()
319-
.WithLayerId(gLayerId)
320314
.WithPartitionId(gPartitionId)
321315
.WithBillingTag(boost::none);
322316
```
323317

324-
Then pass it to the `CatalogClient` via `GetData` method:
318+
Then pass it to the `VersionedLayerClient` via `GetData` method:
325319

326320
```cpp
327321
// Run the DataRequest
328-
auto future = serviceClient->GetData(request);
322+
auto future = layer_client.GetData(request);
329323
```
330324

331325
The execution result is a `CancellableFuture` that contains `DataResponse` object.
332326

333327
```cpp
334328
// Wait for DataResponse
335-
olp::dataservice::read::DataResponse dataResponse =
329+
olp::dataservice::read::DataResponse data_response =
336330
future.GetFuture().get();
337331

338332
// Check the response
339-
if (dataResponse.IsSuccessful()) {
340-
const olp::dataservice::read::DataResult& responseResult =
341-
dataResponse.GetResult();
342-
OLP_SDK_LOG_INFO_F("read-example",
343-
"Request partition data - Success, data size - %d",
344-
responseResult->size());
333+
if (data_response.IsSuccessful()) {
334+
const olp::dataservice::read::DataResult& response_result =
335+
data_response.GetResult();
336+
// Handle success
345337
} else {
346-
OLP_SDK_LOG_ERROR("read-example",
347-
"Request partition data - Failure");
338+
// Handle fail
348339
}
349340
```
350341

examples/dataservice-read/example.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <olp/dataservice/read/CatalogRequest.h>
3434
#include <olp/dataservice/read/DataRequest.h>
3535
#include <olp/dataservice/read/PartitionsRequest.h>
36+
#include <olp/dataservice/read/VersionedLayerClient.h>
3637

3738
namespace {
3839
const std::string kKeyId(""); // your here.access.key.id
@@ -150,18 +151,18 @@ int RunExample() {
150151
client_settings.cache =
151152
olp::client::OlpClientSettingsFactory::CreateDefaultCache({});
152153

153-
// Create a CatalogClient with appropriate HRN and settings.
154-
auto service_client = std::make_unique<olp::dataservice::read::CatalogClient>(
155-
olp::client::HRN(kCatalogHRN), std::move(client_settings));
156-
157154
std::string first_layer_id;
158155
{ // Retrieve the catalog metadata
156+
// Create a CatalogClient with appropriate HRN and settings.
157+
olp::dataservice::read::CatalogClient catalog_client(
158+
olp::client::HRN(kCatalogHRN), client_settings);
159+
159160
// Create CatalogRequest
160161
auto request =
161162
olp::dataservice::read::CatalogRequest().WithBillingTag(boost::none);
162163

163164
// Run the CatalogRequest
164-
auto future = service_client->GetCatalog(request);
165+
auto future = catalog_client.GetCatalog(request);
165166

166167
// Wait for the CatalogResponse response
167168
olp::dataservice::read::CatalogResponse catalog_response =
@@ -171,16 +172,19 @@ int RunExample() {
171172
first_layer_id = HandleCatalogResponse(catalog_response);
172173
}
173174

175+
// Create appropriate layer client with HRN, layer name and settings.
176+
olp::dataservice::read::VersionedLayerClient layer_client(
177+
olp::client::HRN(kCatalogHRN), first_layer_id, client_settings);
178+
174179
std::string first_partition_id;
175180
if (!first_layer_id.empty()) {
176181
// Retrieve the partitions metadata
177182
// Create a PartitionsRequest with appropriate LayerId
178183
auto request = olp::dataservice::read::PartitionsRequest()
179-
.WithLayerId(first_layer_id)
180184
.WithBillingTag(boost::none);
181185

182186
// Run the PartitionsRequest
183-
auto future = service_client->GetPartitions(request);
187+
auto future = layer_client.GetPartitions(request);
184188

185189
// Wait for PartitionsResponse
186190
olp::dataservice::read::PartitionsResponse partitions_response =
@@ -197,12 +201,11 @@ int RunExample() {
197201
// Retrieve the partition data
198202
// Create a DataRequest with appropriate LayerId and PartitionId
199203
auto request = olp::dataservice::read::DataRequest()
200-
.WithLayerId(first_layer_id)
201204
.WithPartitionId(first_partition_id)
202205
.WithBillingTag(boost::none);
203206

204207
// Run the DataRequest
205-
auto future = service_client->GetData(request);
208+
auto future = layer_client.GetData(request);
206209

207210
// Wait for DataResponse
208211
olp::dataservice::read::DataResponse data_response =

0 commit comments

Comments
 (0)