observablehq / framework

A static site generator for data apps, dashboards, reports, and more. Observable Framework combines JavaScript on the front-end for interactive graphics with any language on the back-end for data analysis.
https://observablehq.com/framework/
ISC License
2.58k stars 125 forks source link

DuckDB window function returns tuple instead of value #1712

Closed angrytongan closed 1 month ago

angrytongan commented 1 month ago

Not exactly sure where the problem is, so trying here first.

When running a DuckDB window function, the return value of the function is a tuple in Observable Framework:

WITH
    data AS (
        SELECT 1 AS val
        UNION ALL SELECT 2
        UNION ALL SELECT 3
        UNION ALL SELECT 4
        UNION ALL SELECT 5
        ORDER BY val
    )

SELECT
    val,
    sum(val) OVER (
        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
    ) AS cumulative
FROM
    data
ORDER BY
    val

This query yields:

Screenshot 2024-10-02 at 16 38 53

Casting inside the query does return the right value:

WITH
    data AS (
        SELECT 1 AS val
        UNION ALL SELECT 2
        UNION ALL SELECT 3
        UNION ALL SELECT 4
        UNION ALL SELECT 5
        ORDER BY val
    )

SELECT
    val,
    CAST(sum(val) OVER (
        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
    ) AS INTEGER) AS cumulative
FROM
    data
ORDER BY
    val
Screenshot 2024-10-02 at 16 40 41

Not sure if it's DuckDB or Observable Framework. Would be good if someone could point me in the right direction 👍