Apache Superset tree chart doesn't display hierarchy correctly

1.7k Views Asked by At

I'm trying to present a hierarchy query in the tree chart in 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. 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.

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 queriesenter image description here

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;
1

There are 1 best solutions below

0
On

Just in case this is of help, you can go through this particular example and adapt it to your own data.

First, we need to create a chart. I've run this query on SQL Lab and created a chart from it:

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: enter image description here

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.