How to get partition metadata from an index layer
This example shows how to read partition metadata and partition data from an index 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 an index 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 IndexLayerClient
IndexLayerClientYou can use the IndexLayerClient object to request any data and partition metadata from an index layer.
To create the IndexLayerClient object:
- Create the
OlpClientSettingsobject.
For instructions, see Create platform client settings.
- Create a
IndexLayerClientinstance withIndexLayerClientParamsthat contains the HERE Resource Name (HRN) of the catalog that contains the layer, layer ID, and platform client settings from step 1.
const indexLayerClient = await new IndexLayerClient({
catalogHrn: HRN.fromString("your-catalog-hrn"),
layerId: "your-layer-id",
settings: olpClientSettings,
});Get partition metadata from an index layer
Partition metadata from an index layer consists of the following information about the partition:
- ID (data handle)
- Data size
- Checksum
- Metadata
- Timestamp
To get partition metadata from the index layer:
- Create the
IndexLayerClientobject. - Create the
IndexQueryRequestobject with the RSQL query string and, if the query string is huge, set thehugeboolean parameter totrue.
Note
The
hugeparameter is optional, and its default value isfalse.
const request = new IndexQueryRequest()
.withQueryString("RSQL string query")
.withHugeResponse(true);- Call the
getPartitionsmethod with theIndexQueryRequestparameter.
const partitions = await indexLayerClient.getPartitions(request);You get the partition metadata filtered by the RSQL query.
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 indexLayerClient.getPartitions(request),
abortController.signal
);Get data from an index layer
For more information, see How to get data from an index layer.
Updated 9 days ago