如何使用 Kusto 查询语言打印树?

Yon*_*i L 10 kql azure-data-explorer azure-sentinel azure-monitor kusto-explorer

下面是一个快速而乏味的解决方案。

如果您有更好的,请将其包含在您的答案中。

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)
Run Code Online (Sandbox Code Playgroud)
                 ^                 
                /*\                
               /***\               
              /*****\              
             /*******\             
            /*********\            
           /***********\           
          /*************\          
         /***************\         
        /*****************\        
       /*******************\       
      /*********************\      
     /***********************\     
    /*************************\    
   /***************************\   
  /*****************************\  
Run Code Online (Sandbox Code Playgroud)

如果您需要一些灵感:一棵库斯托圣诞树

Mic*_*tor 5

这是我的圣诞树:

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

在此输入图像描述

\n

\xc2\xa0

\n


Guy*_*ano 5

基于 Yoni 的答案 - Kusto Web Explorer 的类似实现(Web UI 从结果网格中删除前导空格)

 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))
Run Code Online (Sandbox Code Playgroud)

结果

在此输入图像描述