Skip to content

Commit

Permalink
feat: added support for unnest group by (#107)
Browse files Browse the repository at this point in the history
* added support for unnest group by

* bumped package.json

* added test for filter projection unnest

* updated config name
  • Loading branch information
zaidjan-devrev authored Sep 30, 2024
1 parent 6dcaea0 commit 534fcc3
Show file tree
Hide file tree
Showing 15 changed files with 996 additions and 298 deletions.
2 changes: 1 addition & 1 deletion meerkat-browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devrev/meerkat-browser",
"version": "0.0.77",
"version": "0.0.78",
"dependencies": {
"@swc/helpers": "~0.5.0",
"@devrev/meerkat-core": "*",
Expand Down
2 changes: 1 addition & 1 deletion meerkat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devrev/meerkat-core",
"version": "0.0.77",
"version": "0.0.78",
"dependencies": {
"@swc/helpers": "~0.5.0"
},
Expand Down
137 changes: 0 additions & 137 deletions meerkat-core/src/get-projection-clause/get-projection-clause.spec.ts

This file was deleted.

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,
});
});
});
})
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');
});
});
});
Loading

0 comments on commit 534fcc3

Please sign in to comment.