How to get partition metadata from a volatile layer
This example shows how to read partition metadata and partition data from a volatile layer on Node.js using HERE Data SDK for TypeScript.
Build and run an app on Node.js
Before you build an app, make sure that you installed all of the dependencies.
To build and run an app on Node.js:
- Create an npm project.
mkdir example-app && cd example-app && npm init- Initialize a TypeScript project.
tsc --init- Install node types.
npm install --save-dev @types/node- Install the SDK modules.
npm install --save @here/olp-sdk-authentication @here/olp-sdk-dataservice-read @here/olp-sdk-dataservice-apiNow, everything is set to create the app.
5. Create the index.ts file and app skeleton.
/**
* Example of the Node.js app used for reading a volatile layer from the datastore.
*/
class App {
run() {
console.log("App works!");
}
}
const app = new App();
app.run();- Compile and run the app.
tsc && node .After a successful run, the console displays the following message:
App works!
Create VolatileLayerClient
VolatileLayerClientYou can use the VolatileLayerClient object to get the latest published data and partition metadata from a volatile layer.
To create the VolatileLayerClient object:
- Create the
OlpClientSettingsobject.
For instructions, see Create platform client settings.
- Create a
VolatileLayerClientinstance withVolatileLayerClientParamsthat contains the HERE Resource Name (HRN) of the catalog, the layer ID, and the platform client settings from step 1.
const volatileLayerClient = new VolatileLayerClient({
catalogHrn: HRN.fromString("your-catalog-hrn"),
layerId: "your-layer-id",
settings: olpClientSettings,
});Get partition metadata from a volatile layer
Partition metadata from a volatile layer consists of the following information about the partition:
- Data handle
- ID
- Data size
- Checksum
- Compressed data size
You can get partition metadata in one of the following ways:
- Using the Metadata Service API
- Using the Query Service API
You can get partition metadata using the Query Service API only if the partition has the HERE tile scheme. For more information on the HERE tile scheme, see Partitions.
For performance reasons, it is best to use the Query Service API only to get metadata for a specific partition. For batch processes, and to get metadata for many partitions or all partitions in a layer, use the Metadata Service API.
To get partition metadata from the volatile layer:
- Create the
VolatileLayerClientobject. - Do one of the following:
-
(For partitions with the HERE tile scheme) To get partition metadata using the Metadata Service API:
- Create the
QuadKeyPartitionsRequestobject with the quadkey and the number of child partitions (from 0 to 4).
const requestByQuadKey = new QuadKeyPartitionsRequest() .withQuadKey("QuadKey") .withDepth("NumberOfChildPartitions") .withBillingTag("MyBillingTag");- Call the
getPartitionsmethod with theRequestByQuadKeyparameter.
const partitionsByQuadKey = await volatileLayerClient.getPartitions( requestByQuadKey );You get the quadkey tree index with metadata for the requested partition and its parent and children partitions.
- Create the
-
To get partition metadata using the Metadata Service API:
- Create the
PartitionsRequestobject with the fetch option.
The default fetch option is
OnlineIfNotFound. It queries the network if the requested resource is not found in the cache. If you want to skip cache lookups and query the network right away, set thewithFetchOptionmethod toOnlineOnly.const partitionsRequest = new PartitionsRequest() .withBillingTag("MyBillingTag") .withFetchOption(FetchOptions.OnlineOnly);- Call the
getPartitionsmethod with thePartitionsRequestparameter.
const partitions = await volatileLayerClient.getPartitions( partitionsRequest );You get metadata for all the partitions in the layer.
- Create the
-
In browser and Node.js, to abort requests before they have completed, you can create the AbortController object, and then add the AbortController.signal property to your requests. For more information, see the AbortController documentation.
Example:
const abortController = new AbortController();
const partitions = await volatileLayerClient.getPartitions(
partitionsRequest,
abortController.signal
);Get data from a volatile layer
For information on how to get data from a volatile layer, see how to get data from a volatile layer.
Updated 10 days ago