簡體   English   中英

Apache Superset 樹形圖未正確顯示層次結構

[英]Apache Superset tree chart doesn't display hierarchy correctly

我正在嘗試在 Apache Superset 的樹形圖中呈現層次結構查詢。 由於某種原因,它總是將其顯示為單個點或一條直線。 我最初嘗試用它來顯示 PostgreSQL 備份的 pgBackRest 信息的結構,但當它不起作用時,我嘗試了一個簡單的員工和經理層次結構查詢,但也沒有用。 如果有人使用過樹形圖,請提供幫助。 我的 Apache Superset 版本是 1.3.2 附件是我試圖讓它工作的查詢。

with recursive cte as (
select 1 as level, ds.name, ds.backup_label, ds.backup_prior from (
select data->'name' as name, 
       (jsonb_array_elements(data->'backup')->>'label')::text as backup_label,
       (jsonb_array_elements(data->'backup')->>'prior')::text as backup_prior
from jsonb_array_elements(v2.pgbackrest_info()) as data
) as ds
where ds.backup_prior is null
union all
select c.level + 1 as level, ds2.name, ds2.backup_label, ds2.backup_prior from (
select data->'name' as name, 
       (jsonb_array_elements(data->'backup')->>'label')::text as backup_label,
       (jsonb_array_elements(data->'backup')->>'prior')::text as backup_prior
from jsonb_array_elements(v2.pgbackrest_info()) as data
) as ds2 join cte c on c.backup_label = ds2.backup_prior)
select * from cte;

員工查詢在此處輸入圖像描述

SELECT id, name, manager_id, 1 as depth FROM employees
         WHERE id = 2
  UNION
  SELECT e.id, e.name, e.manager_id, t.depth + 1
  FROM employees as e
  JOIN tree t
  ON t.id = e.manager_id
  )
  SELECT id, name, manager_id, depth FROM tree;

以防萬一這有幫助,您可以 go 通過這個特定示例並使其適應您自己的數據。

首先,我們需要創建一個圖表。 我在 SQL Lab 上運行了這個查詢並從中創建了一個圖表:

select 'Terror' as genre, 'IT' as movie
union
select 'Terror' as genre, 'The Shining' as movie
union
select 'Action' as genre, 'Terminator 2' as movie
union
select 'Comedy' as genre, 'Hot Fuzz' as movie
union
select 'Comedy' as genre, 'Bad Santa' as movie
union 
select 'Movies' as genre, 'Terror' as movie
union 
select 'Movies' as genre, 'Comedy' as movie
union 
select 'Movies' as genre, 'Action' as movie
union 
select '' as genre, 'Movies' as movie

然后像這樣配置該圖表: 在此處輸入圖像描述

如您所見,我沒有使用列名,因為我放在一起的那些已經是字符串,並且我正在為應該作為根出現的條目設置根 id 值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM