简体   繁体   English

Apache Superset 树形图未正确显示层次结构

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

I'm trying to present a hierarchy query in the tree chart in Apache Superset.我正在尝试在 Apache Superset 的树形图中呈现层次结构查询。 For some reason, it always displays it as a single dot or a straight line.由于某种原因,它总是将其显示为单个点或一条直线。 I've originally tried to use it for presenting the structure of pgBackRest information for PostgreSQL backups, but when that didn't work, I tried a simple hierarchy query for employees and managers and that didn't work as well.我最初尝试用它来显示 PostgreSQL 备份的 pgBackRest 信息的结构,但当它不起作用时,我尝试了一个简单的员工和经理层次结构查询,但也没有用。 If someone has worked with tree chart, please assist.如果有人使用过树形图,请提供帮助。 My Apache Superset version is 1.3.2 Attached are the queries I've tried to make it work.我的 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;

Employees queries员工查询在此处输入图像描述

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;

Just in case this is of help, you can go through this particular example and adapt it to your own data.以防万一这有帮助,您可以 go 通过这个特定示例并使其适应您自己的数据。

First, we need to create a chart.首先,我们需要创建一个图表。 I've run this query on SQL Lab and created a chart from it:我在 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

Then configured that chart like this:然后像这样配置该图表: 在此处输入图像描述

As you can see, I'm not using a column name since the ones I'm putting together are strings already, and I'm setting a root id value to the entry that should come as a root.如您所见,我没有使用列名,因为我放在一起的那些已经是字符串,并且我正在为应该作为根出现的条目设置根 id 值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM