Skip to content

Commit 2648111

Browse files
committedSep 29, 2024
added support for unnest group by
1 parent 6dcaea0 commit 2648111

File tree

11 files changed

+944
-294
lines changed

11 files changed

+944
-294
lines changed
 

‎meerkat-core/src/get-projection-clause/get-projection-clause.spec.ts

Lines changed: 0 additions & 137 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { TableSchema } from '../../types/cube-types/table';
2+
import { getDimensionProjection, getFilterMeasureProjection } from '../get-aliased-columns-from-filters';
3+
4+
const TABLE_SCHEMA: TableSchema = {
5+
dimensions: [
6+
{ name: 'a', sql: 'others', type: 'number' },
7+
{ name: 'c', sql: 'any', type: 'string' },
8+
],
9+
measures: [
10+
{ name: 'x', sql: 'x', type: 'number' },
11+
{ name: 'y', sql: 'y', type: 'number' },
12+
{ name: 'z', sql: 'z', type: 'number' },
13+
{ name: 'total_rows', sql: 'count(test.id)', type: 'number' },
14+
],
15+
name: 'test',
16+
sql: 'SELECT * from test',
17+
// Define your table schema here
18+
};
19+
20+
describe('get-aliased-columns-from-filters', () => {
21+
describe('getFilterMeasureProjection', () => {
22+
it('should return the member projection when the key exists in the table schema', () => {
23+
const key = 'test.x';
24+
const result = getFilterMeasureProjection({
25+
key,
26+
tableSchema: TABLE_SCHEMA,
27+
measures: ['test.a'],
28+
});
29+
expect(result).toEqual({
30+
aliasKey: 'test__x',
31+
foundMember: { name: 'x', sql: 'x', type: 'number' },
32+
sql: 'test.x AS test__x',
33+
});
34+
});
35+
36+
it('should not create alias when item in measure list', () => {
37+
const key = 'test.x';
38+
const result = getFilterMeasureProjection({
39+
key,
40+
tableSchema: TABLE_SCHEMA,
41+
measures: ['test.x'],
42+
});
43+
expect(result).toEqual({
44+
aliasKey: undefined,
45+
foundMember: undefined,
46+
sql: undefined,
47+
});
48+
});
49+
50+
it("should return the object with undefined values when the key doesn't exist in the table schema", () => {
51+
const key = 'test.a';
52+
const tableSchema: TableSchema = {
53+
...TABLE_SCHEMA,
54+
measures: [{ name: 'b', sql: 'others', type: 'number' }],
55+
};
56+
57+
const result = getFilterMeasureProjection({
58+
key,
59+
tableSchema,
60+
measures: ['test.b'],
61+
});
62+
expect(result).toEqual({
63+
aliasKey: undefined,
64+
foundMember: undefined,
65+
sql: undefined,
66+
});
67+
});
68+
});
69+
70+
describe('getDimensionProjection', () => {
71+
it('should return the member projection when the key exists in the table schema', () => {
72+
const key = 'test.a';
73+
74+
const result = getDimensionProjection({ key, tableSchema: TABLE_SCHEMA, modifiers: [] });
75+
expect(result).toEqual({
76+
aliasKey: 'test__a',
77+
foundMember: { name: 'a', sql: 'others', type: 'number' },
78+
sql: 'others AS test__a',
79+
});
80+
});
81+
82+
it("should return the object with undefined values when the key doesn't exist in the table schema", () => {
83+
const key = 'test.a';
84+
const tableSchema: TableSchema = {
85+
...TABLE_SCHEMA,
86+
dimensions: [{ name: 'b', sql: 'others', type: 'number' }],
87+
};
88+
89+
const result = getDimensionProjection({ key, tableSchema, modifiers: [] });
90+
expect(result).toEqual({
91+
aliasKey: undefined,
92+
foundMember: undefined,
93+
sql: undefined,
94+
});
95+
});
96+
});
97+
})
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { TableSchema } from '../../types/cube-types/table';
2+
import { getProjectionClause } from '../get-projection-clause';
3+
const TABLE_SCHEMA: TableSchema = {
4+
dimensions: [
5+
{ name: 'a', sql: 'others', type: 'number' },
6+
{ name: 'c', sql: 'any', type: 'string' },
7+
],
8+
measures: [
9+
{ name: 'x', sql: 'x', type: 'number' },
10+
{ name: 'y', sql: 'y', type: 'number' },
11+
{ name: 'z', sql: 'z', type: 'number' },
12+
{ name: 'total_rows', sql: 'count(test.id)', type: 'number' },
13+
],
14+
name: 'test',
15+
sql: 'SELECT * from test',
16+
// Define your table schema here
17+
};
18+
describe('get-projection-clause', () => {
19+
describe('getProjectionClause', () => {
20+
it('should return the projection clause when the members are present in the table schema', () => {
21+
const members = ['test.a', 'test.c'];
22+
const aliasedColumnSet = new Set<string>();
23+
const result = getProjectionClause(
24+
{
25+
dimensions: members, measures: []
26+
},
27+
TABLE_SCHEMA,
28+
aliasedColumnSet
29+
);
30+
expect(result).toEqual('others AS test__a, any AS test__c');
31+
});
32+
it('should skip aliased items present in already seen', () => {
33+
const members = ['test.a', 'test.c'];
34+
const aliasedColumnSet = new Set<string>(['test.c']);
35+
const result = getProjectionClause(
36+
{
37+
dimensions: members, measures: []
38+
},
39+
TABLE_SCHEMA,
40+
aliasedColumnSet
41+
);
42+
expect(result).toEqual('others AS test__a');
43+
});
44+
45+
it('should project columns used inside the measure string', () => {
46+
const members = ['test.a', 'test.c'];
47+
const aliasedColumnSet = new Set<string>(['test.c']);
48+
const result = getProjectionClause(
49+
{
50+
measures: ['test.total_rows'],
51+
dimensions: members
52+
},
53+
TABLE_SCHEMA,
54+
aliasedColumnSet
55+
);
56+
expect(result).toEqual('others AS test__a, test.id AS test__id');
57+
});
58+
});
59+
});

0 commit comments

Comments
 (0)