cube icon indicating copy to clipboard operation
cube copied to clipboard

Data model generation with postgres and numeric types

Open mealonso opened this issue 1 year ago • 2 comments

Hi cube.js devs!

Using cube version 0.35.6, I am traying to generate a model for a postgres database using the playground. When generating model for tables with numeric types, ie:

onln=# \d acm_coin_in_statistics2
                      Table "public.acm_coin_in_statistics2"
        Column         |           Type           | Collation | Nullable | Default
-----------------------+--------------------------+-----------+----------+---------
 device_id             | numeric(10,0)            |           | not null |
 game_id               | numeric(5,0)             |           | not null |
 statistics_date       | timestamp with time zone |           | not null |
 hour_00               | numeric(10,0)            |           |          |
 hour_01               | numeric(10,0)            |           |          |
...
Indexes:
    "acm_coin_in_statistics2_pk" PRIMARY KEY, btree (device_id, game_id, statistics_date)

dimension for numeric values are generated as strings and primary key is not extracted correctly. If I use other data types (for example, integer, everithing works fine)

cubes:
  - name: acm_coin_in_statistics
    sql_table: public.acm_coin_in_statistics
    data_source: default

    joins: []

    dimensions:
      - name: game_id
        sql: game_id
        type: string

      - name: device_id
        sql: device_id
        type: string
		
      - name: statistics_date
        sql: statistics_date
        type: time

      - name: hour_02
        sql: hour_02
        type: string
		
	  - name: hour_01
        sql: hour_01
        type: string

Is this the expected behaviour of the current version?

Thank you in advance! Miguel

mealonso avatar Apr 15 '24 12:04 mealonso

Hi @mealonso 👋

I think this is how it's currently implemented. You can update the data model manually, if you'd like to, though.

I also agree that it would be nice if Cube did this automatically.

igorlukanin avatar Apr 18 '24 17:04 igorlukanin

If you are interested in working on this issue, please provide go ahead and provide PR for that. We'd be happy to review it and merge it. If this is the first time you are contributing a Pull Request to Cube, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube Slack.

github-actions[bot] avatar Apr 18 '24 17:04 github-actions[bot]