Manikanta Dornala
Manikanta Dornala

Reputation: 1101

Kusto: Projecting all columns as string

What would I do if I want to cast all columns to string during project?

T
| project tostring(a), tostring(b), tostring(c), ...

Is the only way to cast each of them separately?

Upvotes: 3

Views: 4887

Answers (1)

zlmonroe
zlmonroe

Reputation: 360

I am not aware of any great way to cast multiple columns and I don't think project alone can do this, but you could do something like this to move the values to a single column and then back into their own columns after casting that single column. I feel like a better way might be possible using lists, but I can't see any off the top of my head.

let Example = datatable(AnInteger: int, ATimestamp:datetime, AString:string)
[
1, datetime(1910-06-11), "test",
2, datetime(1910-06-12), "test2"
];
Example
| evaluate narrow()
| extend p = pack(Column, Value)
| summarize bag=make_bag(p) by Row
| project-away Row
| evaluate bag_unpack(bag)
| extend type1=gettype(ATimestamp),
         type2=gettype(AnInteger),
         type3=gettype(AString) // just to show the values really are strings. Delete for your case

enter image description here

Upvotes: 3

Related Questions