Skip to content
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.102",
"version": "0.0.103",
"dependencies": {
"tslib": "^2.3.0",
"@devrev/meerkat-core": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface CubeQueryToSQLWithResolutionParams {
query: Query;
tableSchemas: TableSchema[];
resolutionConfig: ResolutionConfig;
columnProjections?: string[];
contextParams?: ContextParams;
}

Expand All @@ -27,6 +28,7 @@ export const cubeQueryToSQLWithResolution = async ({
query,
tableSchemas,
resolutionConfig,
columnProjections,
contextParams,
}: CubeQueryToSQLWithResolutionParams) => {
const baseSql = await cubeQueryToSQL({
Expand Down Expand Up @@ -59,7 +61,11 @@ export const cubeQueryToSQLWithResolution = async ({
connection: connection,
query: {
measures: [],
dimensions: generateResolvedDimensions(query, resolutionConfig),
dimensions: generateResolvedDimensions(
query,
resolutionConfig,
columnProjections
),
joinPaths: generateResolutionJoinPaths(resolutionConfig, tableSchemas),
},
tableSchemas: [baseTable, ...resolutionSchemas],
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.102",
"version": "0.0.103",
"dependencies": {
"tslib": "^2.3.0"
},
Expand Down
42 changes: 42 additions & 0 deletions meerkat-core/src/resolution/resolution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,48 @@ describe('Generate resolved dimensions', () => {
'__base_query.base_table__column1',
]);
});

it('only include projected columns', () => {
const query = {
measures: ['base_table.count', 'base_table.total'],
dimensions: ['base_table.column1', 'base_table.column2'],
};
const resolutionConfig = {
columnConfigs: [
{
name: 'base_table.column1',
source: 'resolution_table',
joinColumn: 'id',
resolutionColumns: ['display_id'],
},
{
name: 'base_table.column2',
source: 'resolution_table',
joinColumn: 'id',
resolutionColumns: ['id', 'display_name'],
},
],
tableSchemas: [],
};
const projections = [
'base_table.count',
'base_table.column2',
'base_table.total',
];

const resolvedDimensions = generateResolvedDimensions(
query,
resolutionConfig,
projections
);

expect(resolvedDimensions).toEqual([
'__base_query.base_table__count',
'base_table__column2.base_table__column2__id',
'base_table__column2.base_table__column2__display_name',
'__base_query.base_table__total',
]);
});
});

describe('Generate resolution join paths', () => {
Expand Down
45 changes: 28 additions & 17 deletions meerkat-core/src/resolution/resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,38 @@ export const generateResolutionSchemas = (

export const generateResolvedDimensions = (
query: Query,
config: ResolutionConfig
config: ResolutionConfig,
columnProjections?: string[]
): Member[] => {
const resolvedDimensions: Member[] = [
...query.measures,
...(query.dimensions || []),
].flatMap((dimension) => {
const columnConfig = config.columnConfigs.find((c) => c.name === dimension);
// If column projections are provided, use those.
// Otherwise, use all measures and dimensions from the original query.
const aggregatedDimensions = columnProjections
? columnProjections
: [...query.measures, ...(query.dimensions || [])];

if (!columnConfig) {
return [
getNamespacedKey(BASE_DATA_SOURCE_NAME, memberKeyToSafeKey(dimension)),
];
} else {
return columnConfig.resolutionColumns.map((col) =>
getNamespacedKey(
memberKeyToSafeKey(dimension),
memberKeyToSafeKey(getNamespacedKey(columnConfig.name, col))
)
const resolvedDimensions: Member[] = aggregatedDimensions.flatMap(
(dimension) => {
const columnConfig = config.columnConfigs.find(
(c) => c.name === dimension
);

if (!columnConfig) {
return [
getNamespacedKey(
BASE_DATA_SOURCE_NAME,
memberKeyToSafeKey(dimension)
),
];
} else {
return columnConfig.resolutionColumns.map((col) =>
getNamespacedKey(
memberKeyToSafeKey(dimension),
memberKeyToSafeKey(getNamespacedKey(columnConfig.name, col))
)
);
}
}
});
);
return resolvedDimensions;
};

Expand Down
2 changes: 1 addition & 1 deletion meerkat-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devrev/meerkat-node",
"version": "0.0.102",
"version": "0.0.103",
"dependencies": {
"@swc/helpers": "~0.5.0",
"@devrev/meerkat-core": "*",
Expand Down
43 changes: 43 additions & 0 deletions meerkat-node/src/__tests__/resolution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,47 @@ describe('Resolution Tests', () => {
expectedSQL.replace(/\s+/g, ' ').trim()
);
});

it('Resolution With Column Projections', async () => {
const query = {
measures: [],
dimensions: [
'base_table.part_id_1',
'base_table.random_column',
'base_table.work_id',
'base_table.part_id_2',
],
};

const sql = await cubeQueryToSQLWithResolution({
query,
tableSchemas: [BASE_TABLE_SCHEMA],
resolutionConfig: {
columnConfigs: [
{
name: 'base_table.part_id_1',
source: 'dim_part',
joinColumn: 'id',
resolutionColumns: ['display_id'],
},
],
tableSchemas: [DIM_PART_SCHEMA, DIM_WORK_SCHEMA],
},
columnProjections: ['base_table.random_column', 'base_table.part_id_1'],
});
console.info(`SQL: `, sql);
const expectedSQL = `
SELECT
"base_table__random_column",
"base_table__part_id_1 - display_id"
FROM
(SELECT __base_query.base_table__random_column AS "base_table__random_column", * FROM (SELECT base_table__part_id_1, base_table__random_column, base_table__work_id, base_table__part_id_2 FROM (SELECT base_table.part_id_1 AS base_table__part_id_1, base_table.random_column AS base_table__random_column, base_table.work_id AS base_table__work_id, base_table.part_id_2 AS base_table__part_id_2, * FROM (select * from base_table) AS base_table) AS base_table) AS __base_query
LEFT JOIN (SELECT base_table__part_id_1.display_id AS "base_table__part_id_1 - display_id", * FROM (select id, display_id from system.dim_feature UNION ALL select id, display_id from system.dim_product) AS base_table__part_id_1) AS base_table__part_id_1
ON __base_query.base_table__part_id_1 = base_table__part_id_1.id)
AS MEERKAT_GENERATED_TABLE
`;
expect(sql.replace(/\s+/g, ' ').trim()).toBe(
expectedSQL.replace(/\s+/g, ' ').trim()
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ export interface CubeQueryToSQLWithResolutionParams {
query: Query;
tableSchemas: TableSchema[];
resolutionConfig: ResolutionConfig;
columnProjections?: string[];
contextParams?: ContextParams;
}

export const cubeQueryToSQLWithResolution = async ({
query,
tableSchemas,
resolutionConfig,
columnProjections,
contextParams,
}: CubeQueryToSQLWithResolutionParams) => {
const baseSql = await cubeQueryToSQL({
Expand Down Expand Up @@ -54,7 +56,11 @@ export const cubeQueryToSQLWithResolution = async ({
const resolveParams: CubeQueryToSQLParams = {
query: {
measures: [],
dimensions: generateResolvedDimensions(query, resolutionConfig),
dimensions: generateResolvedDimensions(
query,
resolutionConfig,
columnProjections
),
joinPaths: generateResolutionJoinPaths(resolutionConfig, tableSchemas),
},
tableSchemas: [baseTable, ...resolutionSchemas],
Expand Down