How to get partition metadata from a versioned layer
This example shows how to read partition metadata and partition data from a versioned 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 versioned 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 VersionedLayerClient
VersionedLayerClientYou can use the VersionedLayerClient object to request any data and partition metadata version from a versioned layer. When you request a particular version of data from the versioned layer, the partition you receive in the response may have a lower version number than you requested. The version of a layer or partition represents the catalog version in which the layer or partition was last updated.
To create the VersionedLayerClient object:
- Create the
OlpClientSettingsobject.
For instructions, see Create platform client settings.
- Create a
VersionedLayerClientinstance withVersionedLayerClientParamsthat contains the catalog HRN, the layer ID, the platform client settings from step 1, and the layer version.
You do not need to specify a version number if you want to get metadata for the latest version of the versioned layer.
Note
If the version is not specified, the latest version is used.
const versionedLayerClient = new VersionedLayerClient({
catalogHrn: HRN.fromString("your-catalog-hrn"),
layerId: "your-layer-id",
settings: olpClientSettings,
version: number,
});Get partition metadata from a versioned layer
Partition metadata from a versioned layer consists of the following information about the partition:
- Data handle
- ID
- Version
- 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 versioned layer:
- Create the
VersionedLayerClientobject. - Do one of the following:
-
(For partitions with the HERE tile scheme) To get partition metadata using the Metadata Service API:
- Create the QuadKeyPartitionsRequest object with the version number of the layer for which you want to get the metadata, the quadkey, and the number of child partitions (from 0 to 4).
The version specified in the request overrides the version specified in the VersionedLayerClient object.
Note
You do not need to specify a version number if you want to get metadata for the latest version of a versioned layer.
const requestByQuadKey = new QuadKeyPartitionsRequest() .withVersion("VersionNumber") .withQuadKey("QuadKey") .withDepth("NumberOfChildPartitions") .withBillingTag("MyBillingTag");- Call the getPartitions method with the
RequestByQuadKeyparameter.
const partitionsByQuadKey = await versionedLayerClient.getPartitions( requestByQuadKey );You get the quadkey tree index with metadata for the requested partition and its parent and children partitions.
-
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 versionedLayerClient.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 versionedLayerClient.getPartitions(
partitionsRequest,
abortController.signal
);Get data from a versioned layer
For information on how to get data from a versioned layer, see how to get data from a versioned layer.
Updated 10 days ago