@cubejs-client/core
Advanced tools
Comparing version 0.28.6 to 0.28.9
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.28.9](https://github.com/cube-js/cube.js/compare/v0.28.8...v0.28.9) (2021-07-29) | ||
### Bug Fixes | ||
* **@cubejs-client/core:** data blending without date range ([#3161](https://github.com/cube-js/cube.js/issues/3161)) ([cc7c140](https://github.com/cube-js/cube.js/commit/cc7c1401b1d4e7d66fa4215997cfa4f19f8a5707)) | ||
## [0.28.6](https://github.com/cube-js/cube.js/compare/v0.28.5...v0.28.6) (2021-07-22) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@cubejs-client/core", | ||
"version": "0.28.6", | ||
"version": "0.28.9", | ||
"engines": {}, | ||
@@ -48,3 +48,3 @@ "repository": { | ||
}, | ||
"gitHead": "453a92cd048b64cdc5281bcdb417e1f0daa41d64" | ||
"gitHead": "55670c6445c570327c376b5804be2bd898889366" | ||
} |
@@ -8,2 +8,4 @@ import dayjs from 'dayjs'; | ||
import { aliasSeries } from './utils'; | ||
dayjs.locale({ | ||
@@ -306,3 +308,3 @@ ...en, | ||
timeSeries(timeDimension) { | ||
timeSeries(timeDimension, resultIndex) { | ||
if (!timeDimension.granularity) { | ||
@@ -319,3 +321,3 @@ return null; | ||
filter(Boolean) | ||
)(this.timeDimensionBackwardCompatibleData()); | ||
)(this.timeDimensionBackwardCompatibleData(resultIndex)); | ||
@@ -368,3 +370,3 @@ dateRange = dates.length && [ | ||
const series = this.loadResponses.map( | ||
(loadResponse) => this.timeSeries(loadResponse.query.timeDimensions[0]) | ||
(loadResponse) => this.timeSeries(loadResponse.query.timeDimensions[0], resultIndex) | ||
); | ||
@@ -477,12 +479,2 @@ | ||
const aliasSeries = (yValues, i) => { | ||
// manual alias | ||
if (pivotConfig && pivotConfig.aliasSeries && pivotConfig.aliasSeries[i]) { | ||
return [pivotConfig.aliasSeries[i], ...yValues]; | ||
} else if (duplicateMeasures.has(yValues[0])) { | ||
return [i, ...yValues]; | ||
} | ||
return [yValues]; | ||
}; | ||
return this.pivot(pivotConfig).map(({ xValues, yValuesArray }) => { | ||
@@ -493,3 +485,3 @@ const yValuesMap = {}; | ||
.forEach(([yValues, m], i) => { | ||
yValuesMap[this.axisValuesString(aliasSeries(yValues, i), ',')] = m && validate(m); | ||
yValuesMap[this.axisValuesString(aliasSeries(yValues, i, pivotConfig, duplicateMeasures), ',')] = m && validate(m); | ||
}); | ||
@@ -664,13 +656,4 @@ | ||
const aliasSeries = (yValues, i) => { | ||
if (pivotConfig && pivotConfig.aliasSeries && pivotConfig.aliasSeries[i]) { | ||
return [pivotConfig.aliasSeries[i], ...yValues]; | ||
} else if (duplicateMeasures.has(yValues[0])) { | ||
return [i, ...yValues]; | ||
} | ||
return yValues; | ||
}; | ||
return seriesNames.map((axisValues, i) => { | ||
const aliasedAxis = aliasSeries(axisValues, i); | ||
const aliasedAxis = aliasSeries(axisValues, i, pivotConfig, duplicateMeasures); | ||
return { | ||
@@ -720,3 +703,7 @@ title: this.axisValuesString( | ||
timeDimensionBackwardCompatibleData(resultIndex = 0) { | ||
timeDimensionBackwardCompatibleData(resultIndex) { | ||
if (resultIndex === undefined) { | ||
throw new Error('resultIndex is required'); | ||
} | ||
if (!this.backwardCompatibleData[resultIndex]) { | ||
@@ -723,0 +710,0 @@ const { data, query } = this.loadResponses[resultIndex]; |
import 'jest'; | ||
import ResultSet from '../ResultSet'; | ||
import { loadResponse, loadResponseWithoutDateRange } from './fixtures/datablending/load-responses.json'; | ||
const loadResponse = { | ||
queryType: 'blendingQuery', | ||
results: [ | ||
{ | ||
query: { | ||
measures: ['Orders.count'], | ||
timeDimensions: [ | ||
{ | ||
dimension: 'Orders.ts', | ||
granularity: 'day', | ||
dateRange: ['2020-08-01T00:00:00.000', '2020-08-07T23:59:59.999'], | ||
}, | ||
], | ||
filters: [], | ||
timezone: 'UTC', | ||
order: [], | ||
dimensions: [], | ||
}, | ||
data: [ | ||
{ | ||
'Orders.ts.day': '2020-08-01T00:00:00.000', | ||
'Orders.ts': '2020-08-01T00:00:00.000', | ||
'Orders.count': 1, | ||
'time.day': '2020-08-01T00:00:00.000', | ||
}, | ||
{ | ||
'Orders.ts.day': '2020-08-02T00:00:00.000', | ||
'Orders.ts': '2020-08-02T00:00:00.000', | ||
'Orders.count': 2, | ||
'time.day': '2020-08-02T00:00:00.000', | ||
}, | ||
], | ||
annotation: { | ||
measures: { | ||
'Orders.count': { | ||
title: 'Orders Count', | ||
shortTitle: 'Count', | ||
type: 'number', | ||
drillMembers: ['Orders.id', 'Orders.title'], | ||
drillMembersGrouped: { | ||
measures: [], | ||
dimensions: ['Orders.id', 'Orders.title'], | ||
}, | ||
}, | ||
}, | ||
dimensions: {}, | ||
segments: {}, | ||
timeDimensions: { | ||
'Orders.ts.day': { title: 'Orders Ts', shortTitle: 'Ts', type: 'time' }, | ||
'Orders.ts': { title: 'Orders Ts', shortTitle: 'Ts', type: 'time' }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
query: { | ||
measures: ['Users.count'], | ||
timeDimensions: [ | ||
{ | ||
dimension: 'Users.ts', | ||
granularity: 'day', | ||
dateRange: ['2020-08-01T00:00:00.000', '2020-08-07T23:59:59.999'], | ||
}, | ||
], | ||
filters: [], | ||
timezone: 'UTC', | ||
order: [], | ||
dimensions: ['Users.country'], | ||
}, | ||
data: [ | ||
{ | ||
'Users.ts.day': '2020-08-01T00:00:00.000', | ||
'Users.ts': '2020-08-01T00:00:00.000', | ||
'Users.count': 20, | ||
'Users.country': 'Australia', | ||
'time.day': '2020-08-01T00:00:00.000', | ||
}, | ||
{ | ||
'Users.ts.day': '2020-08-05T00:00:00.000', | ||
'Users.ts': '2020-08-05T00:00:00.000', | ||
'Users.count': 34, | ||
'Users.country': 'Spain', | ||
'time.day': '2020-08-05T00:00:00.000', | ||
}, | ||
{ | ||
'Users.ts.day': '2020-08-05T00:00:00.000', | ||
'Users.ts': '2020-08-05T00:00:00.000', | ||
'Users.count': 18, | ||
'Users.country': 'Italy', | ||
'time.day': '2020-08-05T00:00:00.000', | ||
}, | ||
], | ||
annotation: { | ||
measures: { | ||
'Users.count': { | ||
title: 'Users Count', | ||
shortTitle: 'Count', | ||
type: 'number', | ||
drillMembers: [], | ||
drillMembersGrouped: { | ||
measures: [], | ||
dimensions: [], | ||
}, | ||
}, | ||
}, | ||
dimensions: { | ||
'Users.country': { | ||
title: 'Users Country', | ||
shortTitle: 'Country', | ||
type: 'string', | ||
}, | ||
}, | ||
segments: {}, | ||
timeDimensions: { | ||
'Users.ts.day': { title: 'Orders Ts', shortTitle: 'Ts', type: 'time' }, | ||
'Users.ts': { title: 'Orders Ts', shortTitle: 'Ts', type: 'time' }, | ||
}, | ||
}, | ||
}, | ||
], | ||
pivotQuery: { | ||
measures: ['Orders.count', 'Users.count'], | ||
timeDimensions: [ | ||
{ | ||
dimension: 'time', | ||
granularity: 'day', | ||
dateRange: ['2020-08-01T00:00:00.000', '2020-08-07T23:59:59.999'], | ||
}, | ||
], | ||
dimensions: ['Users.country'], | ||
}, | ||
}; | ||
describe('data blending', () => { | ||
@@ -218,3 +88,3 @@ const resultSet1 = new ResultSet(loadResponse); | ||
test('data-blending with same measure', () => { | ||
test('query with a single measure', () => { | ||
const resultSet = new ResultSet({ | ||
@@ -380,3 +250,23 @@ queryType: 'blendingQuery', | ||
test('data-blending with same measure and custom series alias', () => { | ||
test('query without date range', () => { | ||
const resultSet = new ResultSet(loadResponseWithoutDateRange); | ||
expect(resultSet.chartPivot()).toEqual([ | ||
{ | ||
x: '2020-08-01T00:00:00.000', | ||
xValues: ['2020-08-01T00:00:00.000'], | ||
'Orders.count': 1, | ||
'Australia,Users.count': 20, | ||
}, | ||
{ | ||
x: '2020-08-02T00:00:00.000', | ||
xValues: ['2020-08-02T00:00:00.000'], | ||
'Orders.count': 2, | ||
'Spain,Users.count': 34, | ||
'Italy,Users.count': 18, | ||
}, | ||
]); | ||
}); | ||
test('query with a single measure and a custom series alias', () => { | ||
const resultSet = new ResultSet({ | ||
@@ -383,0 +273,0 @@ queryType: 'blendingQuery', |
@@ -288,1 +288,13 @@ import { indexBy, prop, clone, equals } from 'ramda'; | ||
} | ||
export function aliasSeries(values, index, pivotConfig, duplicateMeasures) { | ||
const nonNullValues = values.filter((value) => value != null); | ||
if (pivotConfig && pivotConfig.aliasSeries && pivotConfig.aliasSeries[index]) { | ||
return [pivotConfig.aliasSeries[index], ...nonNullValues]; | ||
} else if (duplicateMeasures.has(nonNullValues[0])) { | ||
return [index, ...nonNullValues]; | ||
} | ||
return nonNullValues; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1822990
30
20755