cube-js / cube

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

FILTER_PARAMS throws "Query parameter number 1 is not defined (0 provided)" error when used in refreshKey #8727

Open itestyoy opened 2 months ago

itestyoy commented 2 months ago

Hi! Pre-aggregations throw an error when we use FILTER_PARAMS in the refreshKey

Error:

cube  | Error: Query parameter number 1 is not defined (0 provided) at [3:63]
cube  |     at QueryQueue.parseResult (/cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/QueryQueue.js:394:13)
cube  |     at QueryQueue.executeInQueue (/cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/QueryQueue.js:366:19)
cube  |     at processTicksAndRejections (node:internal/process/task_queues:95:5)
cube  |     at PreAggregationLoadCache.keyQueryResult (/cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/PreAggregations.ts:439:75)
cube  |     at async Promise.all (index 0)
cube  |     at PreAggregationPartitionRangeLoader.loadRangeQuery (/cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/PreAggregations.ts:1573:38)
cube  |     at /cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/PreAggregations.ts:1879:11
cube  |     at async Promise.all (index 0)
cube  |     at PreAggregationPartitionRangeLoader.loadBuildRange (/cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/PreAggregations.ts:1876:36)
cube  |     at PreAggregationPartitionRangeLoader.partitionRanges (/cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/PreAggregations.ts:1835:24)
cube  |     at PreAggregationPartitionRangeLoader.partitionPreAggregations (/cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/PreAggregations.ts:1827:47)
cube  |     at async Promise.all (index 0)
cube  |     at PreAggregations.expandPartitionsInPreAggregations (/cube/node_modules/@cubejs-backend/query-orchestrator/src/orchestrator/PreAggregations.ts:2322:68)
cube  |     at OrchestratorApi.expandPartitionsInPreAggregations (/cube/node_modules/@cubejs-backend/server-core/src/core/OrchestratorApi.ts:277:14)
cube  |     at RefreshScheduler.refreshQueriesForPreAggregation (/cube/node_modules/@cubejs-backend/server-core/src/core/RefreshScheduler.ts:178:24)

Model:

cube('model', {
      public: false,
      title: 'model',
      sql: `select timestamp('2024-01-01') as created_at, 'hello' as dim, timestamp('2024-01-01') updated_at`,

      dimensions: {
          created_at: {
              sql: `created_at`,
              type: `time`
          },

          dim: {
              sql: `dim`,
              type: `string`
          }
      },

      measures: {
          metric: {
              sql: `(1)`,
              type: 'max'
          }
      },

      pre_aggregations: {
          model_0_0_rollup: {
              measures: [
                  CUBE.metric
              ],
              dimensions: [
                  CUBE.dim,
              ],
              time_dimension: CUBE.created_at,
              granularity: `day`,
              external: false,
              partition_granularity: `month`,
              refresh_key: {
                  sql: `SELECT max(updated_at)
                           FROM (select timestamp('2024-01-01') as created_at, 'hello' as dim, timestamp('2024-01-01') updated_at)
                        WHERE ${FILTER_PARAMS.model.created_at.filter("created_at")}`,
              },
          },
      }
});

Version: 0.36.0

sanromeo commented 2 months ago

Still present in 0.36.3

sanromeo commented 2 months ago

8721 didn't solve problem for refresh_key in pre-aggregations :(