cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to convert array to String

deni
Advisor

Hi,

From one of the tasks of the DQL course in university:

Data Types

Starting with the below DQL Query, what data type are the following fields:

  • related_entity_ids
  • dt.davis.is_duplicate
  • event.start

Afterwards, modify the query to cast the k8s.container.name field to a String.

I checked the requested types and the type of the k8s.container.name is an array. I tried the following:

 

fetch events
| filter event.kind == "DAVIS_PROBLEM"
| fields k8s.container.name
| filterOut isNull(k8s.container.name)
| fieldsAdd test = asString(k8s.container.name)

 

The value of the test column is null. I searched in the documentation, but didn't find anything like arrayToString(arr, delimiter) or similar. 

Can you help me with this?

 

Regards, Deni

Dynatrace Integration Engineer at CodeAttest
2 REPLIES 2

krzysztof_hoja
Dynatrace Champion
Dynatrace Champion

Unfortunately there is no function where you can specify new delimiter. There is however toString function. This example should explain how it works and how to achieve what you need:

data record(arr=array("s1","s2","s3"))
| fieldsAdd merged = toString(arr)
| fieldsAdd merged2 = replaceString(merged,"""["""","")
| fieldsAdd merged2 = replaceString(merged2,""""]""","")
| fieldsAdd merged2 = replaceString(merged2,"""", """","/")

krzysztof_hoja_0-1755453841284.png

 

Ahaaa, I tried asString, but now I see in the documentation that all as... functions just verify the type and return null otherwise. If I want to cast, I need to use the to... functions — in this case toString.

Thanks also for the extra tips on how to set a custom delimiter 🙂

Dynatrace Integration Engineer at CodeAttest

Featured Posts