Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export class MssqlQuery extends BaseQuery {
') AS {{ from_alias }}{% elif from_prepared %}\n' +
'FROM {{ from_prepared }}' +
'{% endif %}' +
'{% for join in joins %}\n{{ join }}{% endfor %}' +
'{% if filter %}\nWHERE {{ filter }}{% endif %}' +
'{% if group_by %}\nGROUP BY {{ group_by }}{% endif %}' +
'{% if having %}\nHAVING {{ having }}{% endif %}' +
Expand Down
17 changes: 17 additions & 0 deletions packages/cubejs-schema-compiler/test/unit/mssql-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ describe('MssqlQuery', () => {

const joinedSchemaCompilers = prepareJsCompiler(createJoinedCubesSchema());

it('renders SQL API pushdown joins after FROM and before WHERE', async () => {
await compiler.compile();

const query = new MssqlQuery({ joinGraph, cubeEvaluator, compiler }, {
measures: ['visitors.count'],
});

// The SQL API supplies already-rendered joins to statements.select.
// Omitting this loop leaves projected columns referring to absent aliases.
const { select } = query.sqlTemplates().statements;
const joins = '{% for join in joins %}\n{{ join }}{% endfor %}';
expect(select).toContain(joins);
expect(select.indexOf(joins)).toBeGreaterThan(select.indexOf('FROM {{ from_prepared }}'));
expect(select.indexOf(joins)).toBeGreaterThan(select.indexOf(') AS {{ from_alias }}'));
expect(select.indexOf(joins)).toBeLessThan(select.indexOf('{% if filter %}'));
});

it('should group by the created_at field on the calculated granularity for unbounded trailing windows',
() => compiler.compile().then(() => {
const query = new MssqlQuery(
Expand Down
Loading