Parse Operator In Kusto Query | Kusto Query Language Tutorial KQL 2022

Topic: How to Use Parse Operator in Kusto Query Language. 


In This article, we are going to learn about Parse operator, parse operator evaluates string expression and parses it value into one or more calculated columns so this is a very powerful operator that can help us to break the data into multiple columns Kusto Query Language is a powerful tool to explore your data and discover patterns, identify anomalies and outliers, create statistical modeling, and more. The query uses schema entities that are organized in a hierarchy similar to SQL's: databases, tables, and columns.
 // Parse Operator : Evaluates a string expression and parses its value into one or more calculated columns.   
   
 .create table Customer (  
   id: int ,FName:string ,LName: string,address: string   
   )  
   
       .ingest inline into table Customer <|  
 1,Aamir,Shahzad,"streetAddress:126,city:San Jone,state:CA,postalCode:394221,othernote: this is fake address,weather:Good"  
 2,Raza,Ali,"streetAddress:1401 Anderson St,city:Charlotte,state:NC,postalCode:28205,othernote: this is fake address,weather:Ok"  
 3,List,Robert,"streetAddress:5817 Hunters Crossing Ln #19,city:Charlotte,state:NC,postalCode:28215,othernote: this is fake address,weather:Ok"  
   
 //.drop table Customer  
   
 //Check all records  
 Customer  
   
 // Let's parse Add Column into multiple columns House#,City,StateZip  
 Customer  
 | parse address with "streetAddress:" StreedAddress  
            ",city:" cityName  
            ",state:" stateCode  
            ",postalCode:" ZipCode  
            ",othernote:" othernote   
 | project id,FName,LName,StreedAddress,cityName,stateCode,ZipCode,othernote  
   
   
 .drop table Customer  
 //Let's add some garbage data into good data and try to parse  
 .create table Customer (  
   id: int ,FName:string ,LName: string,address: string   
   )  
   
       .ingest inline into table Customer <|  
 1,Aamir,Shahzad," This is address streetAddress:126,city:San Jone,state:CA,Some people call it zip code postalCode:394221,othernote: this is fake address,weather:Good"  
 2,Raza,Ali,"streetAddress:1401 Anderson St,city:Charlotte,state:NC,postalCode:28205,othernote: this is fake address,weather:Ok"  
 3,List,Robert,"This is downloaded from zillowstreetAddress:5817 Hunters Crossing Ln #19,city:Charlotte,state:NC,Some Countries don't use zipcode postalCode:28215,othernote: this is fake address,weather:Ok"  
   
   
 Customer  
 | parse address with * "streetAddress:" StreedAddress ",city:" cityName ",state:" stateCode:string "," * "postalCode:" ZipCode ",othernote:" othernote   
 | project id,FName,LName,StreedAddress,cityName,stateCode,ZipCode,othernote  

Video Demo: Parse Operator In Kusto Query | Kusto Query Language Tutorial KQL 2022

No comments:

Post a Comment