cube icon indicating copy to clipboard operation
cube copied to clipboard

Cast all numerical values as strings

Open hassankhan opened this issue 4 years ago • 7 comments

Is your feature request related to a problem? Please describe.

Cube.js can somewhat inconsistently cast numerical values as strings. This behaviour necessitates validation/conversion code on the client-side.

Describe the solution you'd like

The Cube.js API should cast all numerical values as strings (since JSON does not support BigInt) and the Cube.js Client should convert values back to Number/BigInt

Related issues https://github.com/cube-js/cube.js/issues/1849 https://github.com/cube-js/cube.js/issues/1835 https://github.com/cube-js/cube.js/issues/349

hassankhan avatar Jan 25 '21 19:01 hassankhan

Hey cube team, I'm facing this problem currently!

On the front end, resultSet.chartPivot() works as expected and returns numbers for number types, but upon inspecting resultSet.rawData() and resultSet.tablePivot(), the number types are returned as strings.

Db: Postgres 11.8

@cubejs-backend/postgres-driver": "^0.26.10 @cubejs-backend/server-core": "^0.26.10

@cubejs-client/core": "^0.26.0 @cubejs-client/react": "^0.26.7

zameschua avatar Feb 21 '21 22:02 zameschua

+1 on this. I actually assume it's numbers and add them together downstream of cube -- Imagine my surprise when I saw a "number" like

"12.5530566.1943.11.753.29"

joshk0 avatar Apr 08 '21 19:04 joshk0

i found that cubejs cast NULL timestamp to 1970-01-01T00:00:00.000 when using rollup. it return null correctly without rolllup

HJ29 avatar Jul 09 '21 03:07 HJ29

haha, just ran into this and yeah if I want to use preAgg the measures are converted to a string and it breaks all of our charts since calculations need to be done. Only way around it is to parse everything to a number in the UI.

robert-lara avatar Aug 08 '21 18:08 robert-lara

haha, just ran into this and yeah if I want to use preAgg the measures are converted to a string and it breaks all of our charts since calculations need to be done. Only way around it is to parse everything to a number in the UI.

We just had the opposite here whereby if we query a cube and a preaggregation is hit, the numbers are numbers but if it hits Athena instead of a preaggregation it comes back as a string.

benswinburne avatar Dec 24 '21 19:12 benswinburne

Just ran into this where a measure is a number when it results from a direct query and a string when it is calculated from a pre-aggregation. I guess the solution for now is to apply "parseInt" in our UI to every number returned by Cube.

TomMarquardt1 avatar Sep 08 '22 18:09 TomMarquardt1

+1 3 years later, still running into this bug when transitioning from direct queries to pre-aggregations. The lost development time is frustrating, tracking down a known issue. Any update?

shawno avatar Feb 14 '24 01:02 shawno

Hi @shawno and everyone —

Sorry this wasn't mentioned in this issue but we've released a relevant feature some time ago. So, now there's the castNumerics option in front-end SDKs that would do the conversion for you: https://cube.dev/blog/cube-core-v0-34-34-python-and-powerful-updates#castnumerics-in-front-end-sdks

I hope it helps.

igorlukanin avatar Feb 20 '24 12:02 igorlukanin