-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@cubejs-schema-compilter): MSSQL rollingWindow with granularity (#…
…1169) Thanks to @JoshMentzer! Co-authored-by: Joshua D. Mentzer <mentzerj@trinity-health.org>
- Loading branch information
1 parent
f82b84d
commit 16e6a9e
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/cubejs-schema-compiler/test/unit/MssqlQueryTest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* globals it, describe, after */ | ||
/* eslint-disable quote-props */ | ||
const MssqlQuery = require('../../adapter/MssqlQuery'); | ||
const PrepareCompiler = require('./PrepareCompiler'); | ||
require('should'); | ||
|
||
const { prepareCompiler } = PrepareCompiler; | ||
|
||
describe('MssqlQuery', () => { | ||
const { compiler, joinGraph, cubeEvaluator } = prepareCompiler(` | ||
cube(\`visitors\`, { | ||
sql: \` | ||
select * from visitors | ||
\`, | ||
measures: { | ||
count: { | ||
type: 'count' | ||
}, | ||
unboundedCount: { | ||
type: 'count', | ||
rollingWindow: { | ||
trailing: 'unbounded' | ||
} | ||
} | ||
}, | ||
dimensions: { | ||
createdAt: { | ||
type: 'time', | ||
sql: 'created_at' | ||
} | ||
} | ||
}); | ||
`); | ||
|
||
it('group by the date_from field on unbounded trailing windows', () => | ||
compiler.compile().then(() => { | ||
const query = new MssqlQuery( | ||
{ joinGraph, cubeEvaluator, compiler }, | ||
{ | ||
measures: ['visitors.count', 'visitors.unboundedCount'], | ||
timeDimensions: [ | ||
{ | ||
dimension: 'visitors.createdAt', | ||
granularity: 'week', | ||
dateRange: ['2017-01-01', '2017-01-30'], | ||
}, | ||
], | ||
timezone: 'America/Los_Angeles', | ||
order: [ | ||
{ | ||
id: 'visitors.createdAt', | ||
}, | ||
], | ||
} | ||
); | ||
|
||
const queryAndParams = query.buildSqlAndParams(); | ||
|
||
const queryString = queryAndParams[0]; | ||
const lastGroupByIdx = queryString.lastIndexOf('GROUP BY'); | ||
const queryCloseIdx = queryString.indexOf(')', lastGroupByIdx + 1); | ||
const finalGroupBy = queryString.substring(lastGroupByIdx, queryCloseIdx); | ||
|
||
finalGroupBy.should.equal('GROUP BY "visitors.createdAt_series"."date_from"'); | ||
})); | ||
}); |