Skip to content

Commit

Permalink
feat: ability to add custom meta data for measures, dimensions and se…
Browse files Browse the repository at this point in the history
…gments (#641)

* feat: ability to add custom meta data for measures, dimensions and segments

* remove .prettierrc

* updated dist files

Fixes #625
  • Loading branch information
vasilev-alex authored May 13, 2020
1 parent 656a12a commit 88d5c9b
Show file tree
Hide file tree
Showing 15 changed files with 18,202 additions and 27,396 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.0.0",
"@cubejs-client/core": "^0.17.10",
"@types/fs-extra": "^8.1.0",
"@types/jest" : "^25.2.1",
"prettier" : "^2.0.5",
"babel-runtime": "^6.26.0",
"babelrc-rollup": "^3.0.0",
"eslint": "6.8.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/cubejs-api-gateway/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module.exports = {
"rules": {
"import/no-unresolved": 0,
"comma-dangle": 0,
"no-trailing-spaces": ["error", {
"skipBlankLines": true
}],
"no-console": 0,
"arrow-parens": 0,
"import/extensions": 0,
Expand Down
15 changes: 11 additions & 4 deletions packages/cubejs-api-gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ const prepareAnnotation = (metaConfig, query) => {
const configMap = toConfigMap(metaConfig);

const annotation = (memberType) => (member) => {
const path = member.split('.');
const memberWithoutGranularity = [path[0], path[1]].join('.');
const config = configMap[path[0]][memberType].find(m => m.name === memberWithoutGranularity);
const [cubeName, fieldName] = member.split('.');
const memberWithoutGranularity = [cubeName, fieldName].join('.');
const config = configMap[cubeName][memberType].find(m => m.name === memberWithoutGranularity);

if (!config) {
return undefined;
}

return [member, {
title: config.title,
shortTitle: config.shortTitle,
description: config.description,
type: config.type,
format: config.format
format: config.format,
meta: config.meta
}];
};

Expand Down Expand Up @@ -396,6 +399,7 @@ class ApiGateway {
query,
sqlQuery
});

const annotation = prepareAnnotation(metaConfigResult, normalizedQuery);
const aliasToMemberNameMap = sqlQuery.aliasNameToMember;
const toExecute = {
Expand All @@ -409,11 +413,13 @@ class ApiGateway {
const response = await this.getAdapterApi({
...context, dataSource: sqlQuery.dataSource
}).executeQuery(toExecute);

const flattenAnnotation = {
...annotation.measures,
...annotation.dimensions,
...annotation.timeDimensions
};

const result = {
query: normalizedQuery,
data: transformData(aliasToMemberNameMap, flattenAnnotation, response.data, normalizedQuery),
Expand All @@ -424,6 +430,7 @@ class ApiGateway {
}),
annotation
};

this.log(context, {
type: 'Load Request Success',
query,
Expand Down
34 changes: 21 additions & 13 deletions packages/cubejs-client-core/dist/cubejs-client-core.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,21 +590,29 @@ function () {
var normalizedPivotConfig = this.normalizePivotConfig(pivotConfig);

var column = function column(field) {
return field === 'measures' ? (_this4.query().measures || []).map(function (m) {
var exractFields = function exractFields() {
var annotation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var title = annotation.title,
shortTitle = annotation.shortTitle,
format = annotation.format,
type = annotation.type,
meta = annotation.meta;
return {
key: m,
title: _this4.loadResponse.annotation.measures[m].title,
shortTitle: _this4.loadResponse.annotation.measures[m].shortTitle,
format: _this4.loadResponse.annotation.measures[m].format,
type: _this4.loadResponse.annotation.measures[m].type
title: title,
shortTitle: shortTitle,
format: format,
type: type,
meta: meta
};
}) : [{
key: field,
title: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).title,
shortTitle: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).shortTitle,
format: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).format,
type: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).type
}];
};

return field === 'measures' ? (_this4.query().measures || []).map(function (key) {
return _objectSpread2({
key: key
}, exractFields(_this4.loadResponse.annotation.measures[key]));
}) : [_objectSpread2({
key: field
}, exractFields(_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]))];
};

return normalizedPivotConfig.x.map(column).concat(normalizedPivotConfig.y.map(column)).reduce(function (a, b) {
Expand Down
34 changes: 21 additions & 13 deletions packages/cubejs-client-core/dist/cubejs-client-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,21 +596,29 @@ function () {
var normalizedPivotConfig = this.normalizePivotConfig(pivotConfig);

var column = function column(field) {
return field === 'measures' ? (_this4.query().measures || []).map(function (m) {
var exractFields = function exractFields() {
var annotation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var title = annotation.title,
shortTitle = annotation.shortTitle,
format = annotation.format,
type = annotation.type,
meta = annotation.meta;
return {
key: m,
title: _this4.loadResponse.annotation.measures[m].title,
shortTitle: _this4.loadResponse.annotation.measures[m].shortTitle,
format: _this4.loadResponse.annotation.measures[m].format,
type: _this4.loadResponse.annotation.measures[m].type
title: title,
shortTitle: shortTitle,
format: format,
type: type,
meta: meta
};
}) : [{
key: field,
title: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).title,
shortTitle: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).shortTitle,
format: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).format,
type: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).type
}];
};

return field === 'measures' ? (_this4.query().measures || []).map(function (key) {
return _objectSpread2({
key: key
}, exractFields(_this4.loadResponse.annotation.measures[key]));
}) : [_objectSpread2({
key: field
}, exractFields(_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]))];
};

return normalizedPivotConfig.x.map(column).concat(normalizedPivotConfig.y.map(column)).reduce(function (a, b) {
Expand Down
Loading

0 comments on commit 88d5c9b

Please sign in to comment.