evidence-dev / evidence

Business intelligence as code: build fast, interactive data visualizations in pure SQL and markdown
https://evidence.dev
MIT License
3.44k stars 167 forks source link

Invalid date being rendered #1983

Open mr-karan opened 1 week ago

mr-karan commented 1 week ago

Steps To Reproduce

Steps we can take to reproduce the issue you're seeing. Sample data is helpful.

I have a local sqlite3 DB, with the following schema:

CREATE TABLE transactions (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    created_at DATE NOT NULL,
    currency TEXT NOT NULL DEFAULT 'INR',
    amount FLOAT NOT NULL,
    category TEXT NOT NULL,
    mode TEXT NOT NULL DEFAULT 'CASH',
    description TEXT
);

Querying the table, I can see the dates being shown properly:

SELECT DATE(created_at) AS transaction_date, SUM(amount) AS total_spent
FROM transactions
GROUP BY transaction_date
ORDER BY transaction_date;
2024-05-02|2499.0
2024-05-05|2400.0
2024-05-06|1515.0
2024-05-07|3060.0
2024-05-08|1967.0

However, with evidence.dev, I am puzzled as to why created_at is coming as epoch.

image

Here's the index.md:

---
title: ExpenseAI
---

sql transactions
  select
      *
  from expenses.all

<DataTable data={transactions}/>

And I have one .sql file in sources/expenses/all.sql:

SELECT * FROM transactions;

Environment

jpambrun commented 1 week ago

I have the same issue with the trino datasource.

jpambrun commented 1 week ago

I think I have traced the issue to

https://github.com/evidence-dev/evidence/blob/a1a9338a648b8efbbfbc1ea328c7951b2426cb3b/packages/lib/universal-sql/src/build-parquet.js#L36-L38

Here the date (rawValues) is still a string and it results in '0' being inserted in the parquet file. For my case new date() is happy with the string so I could move forward with

    const values = rawValues.map((v) => (Math.floor(new Date(v).getTime())));
    return vectorFromArray(values, new TimestampMillisecond());