cube-js / cube

📊 Cube — Universal semantic layer platform for AI, BI, spreadsheets, and embedded analytics
https://cube.dev
Other
17.96k stars 1.78k forks source link

Pre-aggregations would not build if they only contain `count_distinct_approx` measures #8916

Open igorlukanin opened 2 weeks ago

igorlukanin commented 2 weeks ago

Describe the bug If a pre-aggregation contains only count_distinct_approx measures (one, two, etc.) and no other dimensions or measures, it will not build. Instead, the an error is shown.

To Reproduce Steps to reproduce the behavior:

  1. Take the data model below.
  2. Run a query to the mes measure in Playground so that a p-reaggregation build is triggered.
  3. See the following error:
    Error during create table:
    CREATE TABLE prod_pre_aggregations.my_cube_test_main_qilx5vis_ieu50pzh_1jimlbg (`my_cube_test__mes` BYTES) LOCATION ?:
    Sort key size can't be 0 for default, columns: [Column { name: "my_cube_test__mes", column_type: Bytes, column_index: 0 }]

Expected behavior The pre-aggregation builds.

Screenshots

Screenshot 2024-11-06 at 12 39 45

Minimally reproducible Cube data model

cube(`my_cube_test`, {
  sql: `
    SELECT 123 AS abc UNION ALL
    SELECT 234 AS abc UNION ALL
    SELECT 345 AS abc
  `,

  measures: {
    mes: {
      sql: `abc`,
      type: `count_distinct_approx`
    }
  },

  pre_aggregations: {
    main: {
      measures: [ mes ]
    }
  }
})

Version: v1.1.2

Additional context Adding a count measure or a dimension to the pre-aggregation definition makes the error go away.