Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for unnest group by #107

Merged
merged 4 commits into from
Sep 30, 2024
Merged
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
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
Loading