DataBrewery / cubes

[NOT MAINTAINED] Light-weight Python OLAP framework for multi-dimensional data analysis
http://cubes.databrewery.org
Other
1.49k stars 313 forks source link

How can I use the cubes and sum a json column? #505

Open matheusbento opened 1 year ago

matheusbento commented 1 year ago

Hello guys, I'm working with Postgresql + Cubes.

I have a JSONB column, which is a array of numbers. how can I modify the cubes to accept the sum of this pattern?

image

I already found a way to do the SUM in the SQL:

SELECT index
    , (SELECT sum(nr::numeric) FROM jsonb_array_elements(snx_wavelengths) nr) AS wavelength_sum
FROM   tbl
ORDER  BY 1;

but I don't know how to implement this part in existent code: (SELECT sum(nr::numeric) FROM jsonb_array_elements(snx_wavelengths) nr) AS wavelength_sum

I already tried to put the SQL direct on the functions, but no success.

image

In the future, I would like to create new functions like avg, standard deviation, etc..

Anyone can give me some path how to do that?

@Stiivi @pktippa