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

How to use the parse command when possible empty value between separators

AurelienGravier
DynaMight Champion
DynaMight Champion

Hello,

 

I have to extract data from a line of log using a specific format :

provider;id;name;bu;domaine;app;amount;env

My DQL request below works when there is no empty value on my record :

data record(a = "GCP;128773868256;ICDO-KISS;PLFCHAP;PLATE;MYVALUE;DEV;5")
| parse a, ("LD:provider ';' LD:id ';' LD:name ';' LD:bu ';' LD:domaine ';' LD:app ';' LD:amount ';' LD:env")

AurelienGravier_0-1729196726574.png

 

But it doesn't work if there is an empty value :

data record(a = "GCP;128773868256;ICDO-KISS;PLFCHAP;PLATE;;DEV;5")
| parse a, ("LD:provider ';' LD:id ';' LD:name ';' LD:bu ';' LD:domaine ';' LD:app ';' LD:amount ';' LD:env")

AurelienGravier_2-1729197388820.png

 

How to manage empty value on parse command please ?

 

Thank you.

Regards Aurelien

Observability consultant - Dynatrace Associate/Pro/Services certified
2 REPLIES 2

Fin_Ubels
Dynatrace Champion
Dynatrace Champion

Hey @AurelienGravier 

For your specific example you can use "Optional Modifier" as documented here. Using your query, that would look something like the below:

data record(a = "GCP;128773868256;ICDO-KISS;PLFCHAP;PLATE;;DEV;5")
| parse a, ("WORD:provider ';' WORD:id ';' LD:name ';' WORD:bu ';' WORD:domaine ';' WORD?:app ';' WORD:amount ';' WORD:env")

One thing to note though is that I have change the above to use WORD instead of LD. This is because LD matches to semicolons which means if the value in-between is missing it will just match to the second semicolon and the parsing will fail. For the given example you could use WORD for all fields except for name. For name I cam up with a character class that looks like [0-9a-zA-Z-] and the use of which is documented here but the character class doesn't seem to work. Testing the character class in regex works but within the DQL parse command it doesn't seem to work even though it's supposed to be supported, potentially it requires some more tweaking.

Hope the above helps!

Hello @Fin_Ubels ,

 

Thank you for your help, I tried "Optional Modifier" without success because I didn't try to change the LD type.

FYI, with a character group character-group the name field is parsed with success :

data record(a = "GCP;128773868256;;PLFCHAP;PLATE;;DEV;5")
| parse a, ("WORD:provider ';' WORD:id ';' [0-9a-zA-Z-]{1,100}?:name ';' WORD:bu ';' WORD:domaine ';' WORD?:app ';' WORD:amount ';' WORD:env")

AurelienGravier_0-1729236123232.png

Regards Aurélien

 

 

 

Observability consultant - Dynatrace Associate/Pro/Services certified

Featured Posts