Skip to content

Commit

Permalink
remove runningTotal related code
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Feb 3, 2025
1 parent ce7e593 commit 3020a96
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 280 deletions.
8 changes: 1 addition & 7 deletions packages/cubejs-schema-compiler/src/adapter/BaseMeasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => [
Expand Down Expand Up @@ -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(*)') {
Expand Down
6 changes: 3 additions & 3 deletions packages/cubejs-schema-compiler/src/compiler/CubeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ describe('ClickHouse JoinGraph', () => {
}]
},
per_visitor_revenue: perVisitorRevenueMeasure,
revenueRunning: {
type: 'runningTotal',
sql: 'amount'
},
revenueRolling: {
type: 'sum',
sql: 'amount',
Expand Down Expand Up @@ -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}\`
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ describe('MSSqlUngrouped', () => {
}]
},
per_visitor_revenue: perVisitorRevenueMeasure,
revenueRunning: {
type: 'runningTotal',
sql: 'amount'
},
revenueRolling: {
type: 'sum',
sql: 'amount',
Expand Down Expand Up @@ -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}\`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ describe('SQL Generation', () => {
}]
},
per_visitor_revenue: perVisitorRevenueMeasure,
revenueRunning: {
type: 'runningTotal',
sql: 'amount'
},
revenueRolling: {
type: 'sum',
sql: 'amount',
Expand Down Expand Up @@ -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}\`
Expand Down
Loading

0 comments on commit 3020a96

Please sign in to comment.