Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 644
Yoni L. Avatar asked Dec 21 '21 17:12

Yoni L.


2 Answers

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

 

like image 115
Michael Spector Avatar answered Sep 21 '22 11:09

Michael Spector


Based on Yoni's answer - a similar implementation for Kusto Web Explorer (the web UI removes leading spaces from the result grid)

 let tree_height = 10;
 let invisible_space = '\u00AD';
 range i from 0 to tree_height*2  step 2   
 | extend side_width = tree_height + 1 - i /2
 | extend side_space = strcat_array(repeat(strcat(invisible_space,''),  side_width), " ")
 | project Happy_Holidays = case(i != 0, strcat(side_space, "O", strcat_array(repeat("-", i-1), ""), @"O", side_space), strcat(side_space, " O", side_space))

Result

like image 28
Guy Reginiano Avatar answered Sep 18 '22 11:09

Guy Reginiano