Skip to main content
Seasoned ⭐️⭐️
Nov 23, 2023 12:20 PM UTC
Solved

Hosted Extractors - added string functionality

I’m getting results from several topics using the # function at the end of my topic path-tree.

e.g. ‘~/Installations/Location/Vessel/Seapath/#’
where ‘~/Installations/Location/Vessel/Seapath/acceleration_x’ is an example path

The problem now is that: when I get “context.topic” I get the full path (~/Installations/Location/Vessel/Seapath/acceleration_x) instead of the last path (acceleration_x) and I can’t seem to find a way to extract only the last path as there is barely any functionality in Functions | Cognite Documentation.

Is there a way to get past this?

sample data: {"timestamp":1700740159863,"values":[-0.013358482159674168]}
here is my transformation:
{
  "externalId": concat("installation.vessel.seapath.", context.topic_last_part), # where I can e.g. do split, substring, slice, regexp_extract or any string manipulation on context.topic
  "timestamp": input.timestamp,
  "value": input.values[0],
  "type": "datapoint"
}
sample output;

{
    "externalId": "installation.vessel.seapath.acceleration_x",
    "timestamp": 1700740159863,
    "type": "datapoint",
    "value": -0.013358482159674168
}

mathialoAnswer
Practitioner ⭐️⭐️⭐️
Nov 24, 2023 10:06 AM UTC

Hi! And thanks for the question.

Currently, there are no way of doing this, but we are currently in the process of adding several features for string manipulation, including both a split and substring function.

So very soon you will be able to do

"externalId": concat("installation.vessel.seapath.", context.topic.split("/")[5])

or

"externalId": concat("installation.vessel.seapath.", context.topic.substring(40))

 

3 replies

mathialoAnswer
Practitioner ⭐️⭐️⭐️
Nov 24, 2023 10:06 AM UTC

Hi! And thanks for the question.

Currently, there are no way of doing this, but we are currently in the process of adding several features for string manipulation, including both a split and substring function.

So very soon you will be able to do

"externalId": concat("installation.vessel.seapath.", context.topic.split("/")[5])

or

"externalId": concat("installation.vessel.seapath.", context.topic.substring(40))

 

Seasoned ⭐️⭐️⭐️
Nov 30, 2023 11:21 AM UTC

We’re seeing similar cases, so +1 for this feature.

Practitioner ⭐️⭐️⭐️
Dec 5, 2023 12:25 PM UTC

You can now use “substring”, “split”, “tail”, and “slice”, documentation for all these coming shortly.

 

In this case you could do

 

context.topic.split("/").tail(1)

or

context.topic.split("/").slice(-1)[0]