diff --git a/DEPRECATION.md b/DEPRECATION.md index 3c3268d637fd0..9c5aebfffb6b0 100644 --- a/DEPRECATION.md +++ b/DEPRECATION.md @@ -57,7 +57,7 @@ features: | Removed | [Node.js 14](#nodejs-14) | v0.32.0 | v0.35.0 | | Removed | [Using Redis for in-memory cache and queue](#using-redis-for-in-memory-cache-and-queue) | v0.32.0 | v0.36.0 | | Deprecated | [`SECURITY_CONTEXT`](#security_context) | v0.33.0 | | -| Deprecated | [`running_total` measure type](#running_total-measure-type) | v0.33.39 | | +| Removed | [`running_total` measure type](#running_total-measure-type) | v0.33.39 | v1.2.0 | | Deprecated | [Top-level `includes` parameter in views](#top-level-includes-parameter-in-views) | v0.34.34 | | | Removed | [Node.js 16](#nodejs-16) | v0.35.0 | v0.36.0 | | Removed | [MySQL-based SQL API](#mysql-based-sql-api) | v0.35.0 | v0.35.0 | @@ -341,11 +341,11 @@ instead. ### `running_total` measure type -**Deprecated in Release: v0.33.39** +**Removed in release: v1.2.0** -The `running_total` measure type is now deprecated, and we recommend using +The `running_total` measure type has been removed. Instead, we recommend using the [`rolling_window`](https://cube.dev/docs/product/data-modeling/reference/measures#rolling_window) -to calculate running totals instead. +parameter to calculate running totals. ### Top-level `includes` parameter in views diff --git a/packages/cubejs-schema-compiler/src/adapter/BaseMeasure.ts b/packages/cubejs-schema-compiler/src/adapter/BaseMeasure.ts index ea010dc0fd711..348e6df176945 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BaseMeasure.ts +++ b/packages/cubejs-schema-compiler/src/adapter/BaseMeasure.ts @@ -126,13 +126,10 @@ export class BaseMeasure { } public static isCumulative(definition) { - return definition.type === 'runningTotal' || !!definition.rollingWindow; + return !!definition.rollingWindow; } public rollingWindowDefinition() { - if (this.measureDefinition().type === 'runningTotal') { - throw new UserError('runningTotal rollups aren\'t supported. Please consider replacing runningTotal measure with rollingWindow.'); - } const { type } = this.measureDefinition().rollingWindow; if (type && type !== 'fixed') { throw new UserError(`Only fixed rolling windows are supported by Cube Store but got '${type}' rolling window`); @@ -142,9 +139,6 @@ export class BaseMeasure { public dateJoinCondition() { const definition = this.measureDefinition(); - if (definition.type === 'runningTotal') { - return this.query.runningTotalDateJoinCondition(); - } const { rollingWindow } = definition; if (rollingWindow.type === 'to_date') { return this.query.rollingWindowToDateJoinCondition(rollingWindow.granularity); diff --git a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js index f7154b203e0e6..f73477b3c8cbd 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js +++ b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js @@ -731,16 +731,6 @@ export class BaseQuery { }); } - runningTotalDateJoinCondition() { - return this.timeDimensions.map( - d => [ - d, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - (dateFrom, dateTo, dateField, dimensionDateFrom, dimensionDateTo) => `${dateField} >= ${dimensionDateFrom} AND ${dateField} <= ${dateTo}` - ] - ); - } - rollingWindowToDateJoinCondition(granularity) { return this.timeDimensions.map( d => [ @@ -2675,8 +2665,6 @@ export class BaseQuery { this.countDistinctApprox(evaluateSql); } else if (symbol.type === 'countDistinct' || symbol.type === 'count' && !symbol.sql && multiplied) { return `count(distinct ${evaluateSql})`; - } else if (symbol.type === 'runningTotal') { - return `sum(${evaluateSql})`; // TODO } if (multiplied) { if (symbol.type === 'number' && evaluateSql === 'count(*)') { diff --git a/packages/cubejs-schema-compiler/src/compiler/CubeValidator.ts b/packages/cubejs-schema-compiler/src/compiler/CubeValidator.ts index 6652d29ca6df0..9f180c9d8b034 100644 --- a/packages/cubejs-schema-compiler/src/compiler/CubeValidator.ts +++ b/packages/cubejs-schema-compiler/src/compiler/CubeValidator.ts @@ -549,15 +549,15 @@ const CubeRefreshKeySchema = condition( ); const measureType = Joi.string().valid( - 'number', 'string', 'boolean', 'time', 'sum', 'avg', 'min', 'max', 'countDistinct', 'runningTotal', 'countDistinctApprox' + 'number', 'string', 'boolean', 'time', 'sum', 'avg', 'min', 'max', 'countDistinct', 'countDistinctApprox' ); const measureTypeWithCount = Joi.string().valid( - 'count', 'number', 'string', 'boolean', 'time', 'sum', 'avg', 'min', 'max', 'countDistinct', 'runningTotal', 'countDistinctApprox' + 'count', 'number', 'string', 'boolean', 'time', 'sum', 'avg', 'min', 'max', 'countDistinct', 'countDistinctApprox' ); const multiStageMeasureType = Joi.string().valid( - 'count', 'number', 'string', 'boolean', 'time', 'sum', 'avg', 'min', 'max', 'countDistinct', 'runningTotal', 'countDistinctApprox', + 'count', 'number', 'string', 'boolean', 'time', 'sum', 'avg', 'min', 'max', 'countDistinct', 'countDistinctApprox', 'rank' ); diff --git a/packages/cubejs-schema-compiler/test/integration/clickhouse/clickhouse-graph-builder.test.ts b/packages/cubejs-schema-compiler/test/integration/clickhouse/clickhouse-graph-builder.test.ts index 599d764f0cdbf..f49c6d4c9302e 100644 --- a/packages/cubejs-schema-compiler/test/integration/clickhouse/clickhouse-graph-builder.test.ts +++ b/packages/cubejs-schema-compiler/test/integration/clickhouse/clickhouse-graph-builder.test.ts @@ -50,10 +50,6 @@ describe('ClickHouse JoinGraph', () => { }] }, per_visitor_revenue: perVisitorRevenueMeasure, - revenueRunning: { - type: 'runningTotal', - sql: 'amount' - }, revenueRolling: { type: 'sum', sql: 'amount', @@ -85,14 +81,6 @@ describe('ClickHouse JoinGraph', () => { offset: 'start' } }, - runningCount: { - type: 'runningTotal', - sql: '1' - }, - runningRevenuePerCount: { - type: 'number', - sql: \`round(\${revenueRunning} / \${runningCount})\` - }, averageCheckins: { type: 'avg', sql: \`\${doubledCheckings}\` @@ -385,68 +373,6 @@ describe('ClickHouse JoinGraph', () => { visitors__per_visitor_revenue: '60' }])); - // FAILS - need to finish query to override ::timestamptz - it.skip('running total', () => { - const result = compiler.compile().then(() => { - const query = new ClickHouseQuery({ joinGraph, cubeEvaluator, compiler }, { - measures: [ - 'visitors.revenueRunning' - ], - timeDimensions: [{ - dimension: 'visitors.created_at', - granularity: 'day', - dateRange: ['2017-01-01', '2017-01-10'] - }], - order: [{ - id: 'visitors.created_at' - }], - timezone: 'America/Los_Angeles' - }); - - logSqlAndParams(query); - - // TODO ordering doesn't work for running total - return dbRunner.testQuery(query.buildSqlAndParams()).then(res => { - debugLog(JSON.stringify(res)); - expect(res).toEqual( - [{ - visitors__created_at_day: '2017-01-01T00:00:00.000Z', - visitors__revenue_running: null - }, { - visitors__created_at_day: '2017-01-02T00:00:00.000Z', - visitors__revenue_running: '100' - }, { - visitors__created_at_day: '2017-01-03T00:00:00.000Z', - visitors__revenue_running: '100' - }, { - visitors__created_at_day: '2017-01-04T00:00:00.000Z', - visitors__revenue_running: '300' - }, { - visitors__created_at_day: '2017-01-05T00:00:00.000Z', - visitors__revenue_running: '600' - }, { - visitors__created_at_day: '2017-01-06T00:00:00.000Z', - visitors__revenue_running: '1500' - }, { - visitors__created_at_day: '2017-01-07T00:00:00.000Z', - visitors__revenue_running: '1500' - }, { - visitors__created_at_day: '2017-01-08T00:00:00.000Z', - visitors__revenue_running: '1500' - }, { - visitors__created_at_day: '2017-01-09T00:00:00.000Z', - visitors__revenue_running: '1500' - }, { - visitors__created_at_day: '2017-01-10T00:00:00.000Z', - visitors__revenue_running: '1500' - }] - ); - }); - }); - - return result; - }); - // FAILS - need to finish query to override ::timestamptz it.skip('rolling', () => runQueryTest({ measures: [ @@ -577,51 +503,6 @@ describe('ClickHouse JoinGraph', () => { { visitors__created_at_sql_utils_day: '2017-01-06T00:00:00.000', visitors__visitor_count: '2' } ])); - it('running total total', () => runQueryTest({ - measures: [ - 'visitors.revenueRunning' - ], - timeDimensions: [{ - dimension: 'visitors.created_at', - dateRange: ['2017-01-01', '2017-01-10'] - }], - order: [{ - id: 'visitors.created_at' - }], - timezone: 'America/Los_Angeles' - }, [ - { - visitors__revenue_running: '1500' - } - ])); - - // FAILS Unmatched parentheses - it.skip('running total ratio', () => runQueryTest({ - measures: [ - 'visitors.runningRevenuePerCount' - ], - timeDimensions: [{ - dimension: 'visitors.created_at', - granularity: 'day', - dateRange: ['2017-01-01', '2017-01-10'] - }], - order: [{ - id: 'visitors.created_at' - }], - timezone: 'America/Los_Angeles' - }, [ - { visitors__created_at_day: '2017-01-01T00:00:00.000Z', visitors__running_revenue_per_count: null }, - { visitors__created_at_day: '2017-01-02T00:00:00.000Z', visitors__running_revenue_per_count: '100' }, - { visitors__created_at_day: '2017-01-03T00:00:00.000Z', visitors__running_revenue_per_count: '100' }, - { visitors__created_at_day: '2017-01-04T00:00:00.000Z', visitors__running_revenue_per_count: '150' }, - { visitors__created_at_day: '2017-01-05T00:00:00.000Z', visitors__running_revenue_per_count: '200' }, - { visitors__created_at_day: '2017-01-06T00:00:00.000Z', visitors__running_revenue_per_count: '300' }, - { visitors__created_at_day: '2017-01-07T00:00:00.000Z', visitors__running_revenue_per_count: '300' }, - { visitors__created_at_day: '2017-01-08T00:00:00.000Z', visitors__running_revenue_per_count: '300' }, - { visitors__created_at_day: '2017-01-09T00:00:00.000Z', visitors__running_revenue_per_count: '300' }, - { visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__running_revenue_per_count: '300' } - ])); - // FAILS ClickHouse supports multiple approximate aggregators: // uniq, uniqCombined, uniqHLL12, need to pick one to use and implement it in query it.skip('hll rolling', () => { diff --git a/packages/cubejs-schema-compiler/test/integration/mssql/mssql-ungrouped.test.ts b/packages/cubejs-schema-compiler/test/integration/mssql/mssql-ungrouped.test.ts index 9aab36c0cfcb8..734b1ddcb6394 100644 --- a/packages/cubejs-schema-compiler/test/integration/mssql/mssql-ungrouped.test.ts +++ b/packages/cubejs-schema-compiler/test/integration/mssql/mssql-ungrouped.test.ts @@ -50,10 +50,6 @@ describe('MSSqlUngrouped', () => { }] }, per_visitor_revenue: perVisitorRevenueMeasure, - revenueRunning: { - type: 'runningTotal', - sql: 'amount' - }, revenueRolling: { type: 'sum', sql: 'amount', @@ -85,14 +81,6 @@ describe('MSSqlUngrouped', () => { offset: 'start' } }, - runningCount: { - type: 'runningTotal', - sql: '1' - }, - runningRevenuePerCount: { - type: 'number', - sql: \`round(\${revenueRunning} / \${runningCount})\` - }, averageCheckins: { type: 'avg', sql: \`\${doubledCheckings}\` diff --git a/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation-logic.test.ts b/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation-logic.test.ts index c902b7d1faf37..5089d0ce4b1ef 100644 --- a/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation-logic.test.ts +++ b/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation-logic.test.ts @@ -45,10 +45,6 @@ describe('SQL Generation', () => { }] }, per_visitor_revenue: perVisitorRevenueMeasure, - revenueRunning: { - type: 'runningTotal', - sql: 'amount' - }, revenueRolling: { type: 'sum', sql: 'amount', @@ -80,14 +76,6 @@ describe('SQL Generation', () => { offset: 'start' } }, - runningCount: { - type: 'runningTotal', - sql: '1' - }, - runningRevenuePerCount: { - type: 'number', - sql: \`round(\${revenueRunning} / \${runningCount})\` - }, averageCheckins: { type: 'avg', sql: \`\${doubledCheckings}\` diff --git a/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts b/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts index 03740b7088b68..ad3eda2755011 100644 --- a/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts +++ b/packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts @@ -52,10 +52,6 @@ describe('SQL Generation', () => { }] }, per_visitor_revenue: perVisitorRevenueMeasure, - revenueRunning: { - type: 'runningTotal', - sql: 'amount' - }, revenueRolling: { type: 'sum', sql: 'amount', @@ -110,14 +106,6 @@ describe('SQL Generation', () => { offset: 'start' } }, - runningCount: { - type: 'runningTotal', - sql: '1' - }, - runningRevenuePerCount: { - type: 'number', - sql: \`round(\${revenueRunning} / \${runningCount})\` - }, averageCheckins: { type: 'avg', sql: \`\${doubledCheckings}\` @@ -656,65 +644,6 @@ describe('SQL Generation', () => { visitors__str_case: 'More than 1' }])); - it('running total', async () => { - await compiler.compile(); - - const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, { - measures: [ - 'visitors.revenueRunning' - ], - timeDimensions: [{ - dimension: 'visitors.created_at', - granularity: 'day', - dateRange: ['2017-01-01', '2017-01-10'] - }], - order: [{ - id: 'visitors.created_at' - }], - timezone: 'America/Los_Angeles' - }); - - console.log(query.buildSqlAndParams()); - - // TODO ordering doesn't work for running total - return dbRunner.testQuery(query.buildSqlAndParams()).then(res => { - console.log(JSON.stringify(res)); - expect(res).toEqual( - [{ - visitors__created_at_day: '2017-01-01T00:00:00.000Z', - visitors__revenue_running: null - }, { - visitors__created_at_day: '2017-01-02T00:00:00.000Z', - visitors__revenue_running: '100' - }, { - visitors__created_at_day: '2017-01-03T00:00:00.000Z', - visitors__revenue_running: '100' - }, { - visitors__created_at_day: '2017-01-04T00:00:00.000Z', - visitors__revenue_running: '300' - }, { - visitors__created_at_day: '2017-01-05T00:00:00.000Z', - visitors__revenue_running: '600' - }, { - visitors__created_at_day: '2017-01-06T00:00:00.000Z', - visitors__revenue_running: '1500' - }, { - visitors__created_at_day: '2017-01-07T00:00:00.000Z', - visitors__revenue_running: '1500' - }, { - visitors__created_at_day: '2017-01-08T00:00:00.000Z', - visitors__revenue_running: '1500' - }, { - visitors__created_at_day: '2017-01-09T00:00:00.000Z', - visitors__revenue_running: '1500' - }, { - visitors__created_at_day: '2017-01-10T00:00:00.000Z', - visitors__revenue_running: '1500' - }] - ); - }); - }); - it('rolling', async () => runQueryTest({ measures: [ 'visitors.revenueRolling' @@ -883,50 +812,6 @@ describe('SQL Generation', () => { { visitors__created_at_sql_utils_day: '2017-01-06T00:00:00.000Z', visitors__visitor_count: '2' } ])); - it('running total total', async () => runQueryTest({ - measures: [ - 'visitors.revenueRunning' - ], - timeDimensions: [{ - dimension: 'visitors.created_at', - dateRange: ['2017-01-01', '2017-01-10'] - }], - order: [{ - id: 'visitors.created_at' - }], - timezone: 'America/Los_Angeles' - }, [ - { - visitors__revenue_running: '1500' - } - ])); - - it('running total ratio', async () => runQueryTest({ - measures: [ - 'visitors.runningRevenuePerCount' - ], - timeDimensions: [{ - dimension: 'visitors.created_at', - granularity: 'day', - dateRange: ['2017-01-01', '2017-01-10'] - }], - order: [{ - id: 'visitors.created_at' - }], - timezone: 'America/Los_Angeles' - }, [ - { visitors__created_at_day: '2017-01-01T00:00:00.000Z', visitors__running_revenue_per_count: null }, - { visitors__created_at_day: '2017-01-02T00:00:00.000Z', visitors__running_revenue_per_count: '100' }, - { visitors__created_at_day: '2017-01-03T00:00:00.000Z', visitors__running_revenue_per_count: '100' }, - { visitors__created_at_day: '2017-01-04T00:00:00.000Z', visitors__running_revenue_per_count: '150' }, - { visitors__created_at_day: '2017-01-05T00:00:00.000Z', visitors__running_revenue_per_count: '200' }, - { visitors__created_at_day: '2017-01-06T00:00:00.000Z', visitors__running_revenue_per_count: '300' }, - { visitors__created_at_day: '2017-01-07T00:00:00.000Z', visitors__running_revenue_per_count: '300' }, - { visitors__created_at_day: '2017-01-08T00:00:00.000Z', visitors__running_revenue_per_count: '300' }, - { visitors__created_at_day: '2017-01-09T00:00:00.000Z', visitors__running_revenue_per_count: '300' }, - { visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__running_revenue_per_count: '300' } - ])); - it('hll rolling (BigQuery)', async () => { await compiler.compile();