-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for unnest group by (#107)
* added support for unnest group by * bumped package.json * added test for filter projection unnest * updated config name
- Loading branch information
1 parent
6dcaea0
commit 534fcc3
Showing
15 changed files
with
996 additions
and
298 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
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
137 changes: 0 additions & 137 deletions
137
meerkat-core/src/get-projection-clause/get-projection-clause.spec.ts
This file was deleted.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
...et-wrapped-base-query-with-projections/__tests__/get-aliased-columns-from-filters.spec.ts
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,97 @@ | ||
import { TableSchema } from '../../types/cube-types/table'; | ||
import { getDimensionProjection, getFilterMeasureProjection } from '../get-aliased-columns-from-filters'; | ||
|
||
const TABLE_SCHEMA: TableSchema = { | ||
dimensions: [ | ||
{ name: 'a', sql: 'others', type: 'number' }, | ||
{ name: 'c', sql: 'any', type: 'string' }, | ||
], | ||
measures: [ | ||
{ name: 'x', sql: 'x', type: 'number' }, | ||
{ name: 'y', sql: 'y', type: 'number' }, | ||
{ name: 'z', sql: 'z', type: 'number' }, | ||
{ name: 'total_rows', sql: 'count(test.id)', type: 'number' }, | ||
], | ||
name: 'test', | ||
sql: 'SELECT * from test', | ||
// Define your table schema here | ||
}; | ||
|
||
describe('get-aliased-columns-from-filters', () => { | ||
describe('getFilterMeasureProjection', () => { | ||
it('should return the member projection when the key exists in the table schema', () => { | ||
const key = 'test.x'; | ||
const result = getFilterMeasureProjection({ | ||
key, | ||
tableSchema: TABLE_SCHEMA, | ||
measures: ['test.a'], | ||
}); | ||
expect(result).toEqual({ | ||
aliasKey: 'test__x', | ||
foundMember: { name: 'x', sql: 'x', type: 'number' }, | ||
sql: 'test.x AS test__x', | ||
}); | ||
}); | ||
|
||
it('should not create alias when item in measure list', () => { | ||
const key = 'test.x'; | ||
const result = getFilterMeasureProjection({ | ||
key, | ||
tableSchema: TABLE_SCHEMA, | ||
measures: ['test.x'], | ||
}); | ||
expect(result).toEqual({ | ||
aliasKey: undefined, | ||
foundMember: undefined, | ||
sql: undefined, | ||
}); | ||
}); | ||
|
||
it("should return the object with undefined values when the key doesn't exist in the table schema", () => { | ||
const key = 'test.a'; | ||
const tableSchema: TableSchema = { | ||
...TABLE_SCHEMA, | ||
measures: [{ name: 'b', sql: 'others', type: 'number' }], | ||
}; | ||
|
||
const result = getFilterMeasureProjection({ | ||
key, | ||
tableSchema, | ||
measures: ['test.b'], | ||
}); | ||
expect(result).toEqual({ | ||
aliasKey: undefined, | ||
foundMember: undefined, | ||
sql: undefined, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getDimensionProjection', () => { | ||
it('should return the member projection when the key exists in the table schema', () => { | ||
const key = 'test.a'; | ||
|
||
const result = getDimensionProjection({ key, tableSchema: TABLE_SCHEMA, modifiers: [] }); | ||
expect(result).toEqual({ | ||
aliasKey: 'test__a', | ||
foundMember: { name: 'a', sql: 'others', type: 'number' }, | ||
sql: 'others AS test__a', | ||
}); | ||
}); | ||
|
||
it("should return the object with undefined values when the key doesn't exist in the table schema", () => { | ||
const key = 'test.a'; | ||
const tableSchema: TableSchema = { | ||
...TABLE_SCHEMA, | ||
dimensions: [{ name: 'b', sql: 'others', type: 'number' }], | ||
}; | ||
|
||
const result = getDimensionProjection({ key, tableSchema, modifiers: [] }); | ||
expect(result).toEqual({ | ||
aliasKey: undefined, | ||
foundMember: undefined, | ||
sql: undefined, | ||
}); | ||
}); | ||
}); | ||
}) |
59 changes: 59 additions & 0 deletions
59
...-core/src/get-wrapped-base-query-with-projections/__tests__/get-projection-clause.spec.ts
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,59 @@ | ||
import { TableSchema } from '../../types/cube-types/table'; | ||
import { getProjectionClause } from '../get-projection-clause'; | ||
const TABLE_SCHEMA: TableSchema = { | ||
dimensions: [ | ||
{ name: 'a', sql: 'others', type: 'number' }, | ||
{ name: 'c', sql: 'any', type: 'string' }, | ||
], | ||
measures: [ | ||
{ name: 'x', sql: 'x', type: 'number' }, | ||
{ name: 'y', sql: 'y', type: 'number' }, | ||
{ name: 'z', sql: 'z', type: 'number' }, | ||
{ name: 'total_rows', sql: 'count(test.id)', type: 'number' }, | ||
], | ||
name: 'test', | ||
sql: 'SELECT * from test', | ||
// Define your table schema here | ||
}; | ||
describe('get-projection-clause', () => { | ||
describe('getProjectionClause', () => { | ||
it('should return the projection clause when the members are present in the table schema', () => { | ||
const members = ['test.a', 'test.c']; | ||
const aliasedColumnSet = new Set<string>(); | ||
const result = getProjectionClause( | ||
{ | ||
dimensions: members, measures: [] | ||
}, | ||
TABLE_SCHEMA, | ||
aliasedColumnSet | ||
); | ||
expect(result).toEqual('others AS test__a, any AS test__c'); | ||
}); | ||
it('should skip aliased items present in already seen', () => { | ||
const members = ['test.a', 'test.c']; | ||
const aliasedColumnSet = new Set<string>(['test.c']); | ||
const result = getProjectionClause( | ||
{ | ||
dimensions: members, measures: [] | ||
}, | ||
TABLE_SCHEMA, | ||
aliasedColumnSet | ||
); | ||
expect(result).toEqual('others AS test__a'); | ||
}); | ||
|
||
it('should project columns used inside the measure string', () => { | ||
const members = ['test.a', 'test.c']; | ||
const aliasedColumnSet = new Set<string>(['test.c']); | ||
const result = getProjectionClause( | ||
{ | ||
measures: ['test.total_rows'], | ||
dimensions: members | ||
}, | ||
TABLE_SCHEMA, | ||
aliasedColumnSet | ||
); | ||
expect(result).toEqual('others AS test__a, test.id AS test__id'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.