0
votes

My query returns a bunch of columns that I can't manually rename (using project-rename) one by one. Also the input query is fixed , I can't change it and it may return different number of columns each time I run it, so I can't have a fixed project-rename statement. For example lets say for one of the runs of the input query the result is the following columns:-

fixedstring_region
fixedstring_state
fixedstring_level
fixedstring_reach
fixedstring_mode
fixedstring_something
fixedstring_otherthing
... etc

These can be hundreds. I want to remove 'fixedstring_' from all of these. Is there some wild card technique for this?

1

1 Answers

1
votes

There's no built-in way to do it.

The best I can think of is a very non-efficient way, that also changes the order of the columns:

datatable(fixedstring_region:string, fixedstring_state:string, fixedstring_level:string, fixedstring_reach:string)
[
    "a1", "b1", "c1", "d1",
    "a2", "b2", "c2", "d2"
]
| project PackedRecord = todynamic(replace('"fixedstring_([a-zA-Z0-9_]*)":"', @'"\1":"', tostring(pack_all())))
| evaluate bag_unpack(PackedRecord)

Output:

datatable(fixedstring_region:string, fixedstring_state:string, fixedstring_level:string, fixedstring_reach:string)
[
    "a1", "b1", "c1", "d1",
    "a2", "b2", "c2", "d2"
]
| project PackedRecord = todynamic(replace('"fixedstring_([a-zA-Z0-9_]*)":"', @'"\1":"', tostring(pack_all())))
| evaluate bag_unpack(PackedRecord)

Output:

level reach region state
c1 d1 a1 b1
c2 d2 a2 b2