Search code examples
azure-data-explorerkqlazure-sentinelkusto-explorerazure-monitor

How do I print a tree using the Kusto Query Language?


Below is a quick and unglamorous solution.

If you have a better one, please include it in your answer.

let tree_height = 15;
range i from -1 to tree_height * 2 step 2
| extend side_width = tree_height + 1 - i / 2
| extend side_space = strrep(" ", side_width)
| extend tree_part = case(i > 0, strcat("/", strrep("*", i), @"\"), " ^ ")
| project ta_da = strcat(side_space, tree_part, side_space)
                 ^                 
                /*\                
               /***\               
              /*****\              
             /*******\             
            /*********\            
           /***********\           
          /*************\          
         /***************\         
        /*****************\        
       /*******************\       
      /*********************\      
     /***********************\     
    /*************************\    
   /***************************\   
  /*****************************\  

If you need some inspiration: a Kusto Christmas tree


Solution

  • Here's my Khristmas tree:

    let L=10;
    range x from 1 to L step 1
    | project t=strcat(strrep(' ', L-x), strrep('.', x), strrep('*', x-1))
    | summarize Tree=make_list(t)
    | project Tree=array_concat(pack_array(strcat(strrep(' ', L-3), make_string(127775))), Tree)
    | project HappyXmas=strcat_array(Tree, '\n')
    

    enter image description here