cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.74k stars 1.75k forks source link

Min measure for a Date field throws "Float cannot represent non numeric value" #5652

Open iiq374 opened 1 year ago

iiq374 commented 1 year ago

Describe the bug When using a min measure type on a DateTime field there is a casting error when querying via GraphQL

To Reproduce

  1. Have a Cube with a min measure type on a DateTime field (we are using PostGres):

    minDate: {
      sql: `created_at`,
      type: `min`,
    },
  2. Query for the field using GraphQL:

    query CubeQuery  { 
    cube {
    generalLedger_Income {
      minDate
     } 
    }
    }
  3. {"errors":[{"message":"**Float cannot represent non numeric value: \"2020-06-25T14:00:00.000\**"","locations":[{"line":6,"column":7}],"path":["cube",0,"generalLedger_Income","minDate"]}],"data":{"cube":[{"generalLedger_Income":{"minDate":null,"__typename":"GeneralLedger_IncomeMembers"},"__typename":"Result"}]}}

Expected behavior Min and Max should be able to be used on Date fields as well

Screenshots If applicable, add screenshots to help explain your problem.

Minimally reproducible Cube Schema In case your bug report is data modelling related please put your minimally reproducible Cube Schema here. You can use selects without tables in order to achieve that as follows.

cube(`generalLedger_Income`, {
  sql: `
  select now() as created_at
  UNION ALL
  select now() as created_at
  `,
  measures: {
minDate: {
      sql: `created_at`,
      type: `min`,
    },
  },
});

Version: 0.31.11

Additional context

pauldheinrichs commented 5 months ago

This also seems to be a problem with SQL API exposing the underlying aggregation as numeric