cube-js / cube-js/cube

Post-process result-set result

Open
#3,799 4 comments 4 reactions 1 assignee Claimed by @paveltiunov View on GitHub
help wanted
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Is your feature request related to a problem? Please describe.**
This issue has been opened in the past (Post processing results on server side #1286)
But the initial issuer rapidly changed is approach.

As for me, as a backend developer I would like to enhance/enrich ResultSet return by CubeJS (or by the cache).

I need to do more complex linear algebra operation over my ResultSet which requires math library, but CubeJS forces me to complexify my architecture by either:

- moving complex algorithm on the frontend side
- relying on other service that frontend call after cubejs returned an unusable resultset, which complexify my developement setup when testing locally or doing automatic testing. We try to enforce a "dumb frontend" philosophy where complex routine and processing should be handle on the backend to avoid overwhelming the frontend since frontend codebase tends to grow a lot faster and is much harder to test (in our case).

**Describe the solution you'd like**

IMO, the simplest and most flexible solution would simply be a hook in the `CreateOptions` interface called `resultSetRewrite` that could have the following signature:

```
type ResultSet = any
type ResultSetRewriteFn = (query: Query, context: RequestContext, resultSet: ResultSet) => Promise;
```

The `query: Query` is to allow the developer to have conditional ResultSet rewrite based on the input query
The `context: RequestContext` is additional context information that could be use for conditional rewrite and specific use-case.
The `resultSet: ResultSet` is of course the resultset returned by either Cubejs or Redis (cache), i.e. user should not worry about cache and should recompute it each time.

Furthermore, there could be tricky situation about caching whereas a user may want transparent caching or not at all. Integrating with cache could be done in another iteration, but one way to make caching integration explicit is by providing an additional function
in the `CreateOption` called `cachedResultSetRewrites: ResultSetRewriteFn`.

**Describe alternatives you've considered**

- Coding in PLV8 or PLPerl in Postgres, but my database is hosted in AWS so a lot of features are unavailable due to security issues and lack of superuser permissions. Moreover, it forces you to code in a procedural way that may leak cursor and plan, crashing runtime may cause database crashing also...
- Calling another service after the frontend received the result set.
- Putting the complex algorithm on the frontend side.
- Trying to intercept call the cubejs to hack my way in rewriting the resultset myself.

**Additional context**
Add any other context or screenshots about the feature request here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.