observablehq / stdlib

The Observable standard library.
https://observablehq.com/@observablehq/standard-library
ISC License
970 stars 83 forks source link

Derived columns #367

Closed annie closed 1 year ago

annie commented 1 year ago

Part of https://github.com/observablehq/observablehq/issues/11623

Description

This PR adds support for derived columns in the __table function. In this first version, we won't support derived columns for database sources.

Notable changes:

Review notes

I would love some feedback on the .fullSchema change! I'm not sure if it's the best way to make all the column types available, and I'm also not sure if I'm missing any major pitfalls with switching to use the cell value to fetch the table schema, instead of looking at the original data source as we do today. The main pitfall I experienced when testing is that, if there's an error in a derived formula, we no longer have a table schema available because the cell throws an error. I addressed that in the monorepo PR by adding a fallback that goes back to using the loaded data source + an approximation of the derived columns schema, which I think is the best we can do in that case. But perhaps there are other issues with this approach that I'm missing...

annie commented 1 year ago

just pushed up a new commit that catches runtime errors and returns them in the function output (although it seems like i need to update tests!). will put up a corresponding monorepo PR shortly!

update: monorepo PR here