2017-12-20 12:33:33 +01:00
|
|
|
import queryPart from '../query_part';
|
2015-09-30 17:16:34 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('InfluxQueryPart', () => {
|
|
|
|
|
describe('series with measurement only', () => {
|
|
|
|
|
it('should handle nested function parts', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const part = queryPart.create({
|
2017-12-20 12:33:33 +01:00
|
|
|
type: 'derivative',
|
|
|
|
|
params: ['10s'],
|
2015-09-30 17:16:34 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(part.text).toBe('derivative(10s)');
|
|
|
|
|
expect(part.render('mean(value)')).toBe('derivative(mean(value), 10s)');
|
2015-09-30 17:16:34 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should nest spread function', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const part = queryPart.create({
|
2017-12-20 12:33:33 +01:00
|
|
|
type: 'spread',
|
2016-05-30 14:23:24 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(part.text).toBe('spread()');
|
|
|
|
|
expect(part.render('value')).toBe('spread(value)');
|
2016-05-30 14:23:24 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should handle suffix parts', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const part = queryPart.create({
|
2017-12-20 12:33:33 +01:00
|
|
|
type: 'math',
|
|
|
|
|
params: ['/ 100'],
|
2015-09-30 17:16:34 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(part.text).toBe('math(/ 100)');
|
|
|
|
|
expect(part.render('mean(value)')).toBe('mean(value) / 100');
|
2015-09-30 17:16:34 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should handle alias parts', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const part = queryPart.create({
|
2017-12-20 12:33:33 +01:00
|
|
|
type: 'alias',
|
|
|
|
|
params: ['test'],
|
2015-09-30 17:16:34 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(part.text).toBe('alias(test)');
|
|
|
|
|
expect(part.render('mean(value)')).toBe('mean(value) AS "test"');
|
2015-09-30 17:16:34 +02:00
|
|
|
});
|
2018-05-30 09:22:16 +02:00
|
|
|
|
|
|
|
|
it('should nest distinct when count is selected', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const selectParts = [
|
2018-05-30 09:22:16 +02:00
|
|
|
queryPart.create({
|
|
|
|
|
type: 'field',
|
|
|
|
|
category: queryPart.getCategories().Fields,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'count',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
];
|
2018-08-26 18:43:07 +02:00
|
|
|
const partModel = queryPart.create({
|
2018-05-30 09:22:16 +02:00
|
|
|
type: 'distinct',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
queryPart.replaceAggregationAdd(selectParts, partModel);
|
|
|
|
|
|
|
|
|
|
expect(selectParts[1].text).toBe('distinct()');
|
|
|
|
|
expect(selectParts[2].text).toBe('count()');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should convert to count distinct when distinct is selected and count added', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const selectParts = [
|
2018-05-30 09:22:16 +02:00
|
|
|
queryPart.create({
|
|
|
|
|
type: 'field',
|
|
|
|
|
category: queryPart.getCategories().Fields,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'distinct',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
];
|
2018-08-26 18:43:07 +02:00
|
|
|
const partModel = queryPart.create({
|
2018-05-30 09:22:16 +02:00
|
|
|
type: 'count',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
queryPart.replaceAggregationAdd(selectParts, partModel);
|
|
|
|
|
|
|
|
|
|
expect(selectParts[1].text).toBe('distinct()');
|
|
|
|
|
expect(selectParts[2].text).toBe('count()');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should replace count distinct if an aggregation is selected', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const selectParts = [
|
2018-05-30 09:22:16 +02:00
|
|
|
queryPart.create({
|
|
|
|
|
type: 'field',
|
|
|
|
|
category: queryPart.getCategories().Fields,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'distinct',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'count',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
];
|
2018-08-26 18:43:07 +02:00
|
|
|
const partModel = queryPart.create({
|
2018-05-30 09:22:16 +02:00
|
|
|
type: 'mean',
|
|
|
|
|
category: queryPart.getCategories().Selectors,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
queryPart.replaceAggregationAdd(selectParts, partModel);
|
|
|
|
|
|
|
|
|
|
expect(selectParts[1].text).toBe('mean()');
|
|
|
|
|
expect(selectParts).toHaveLength(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not allowed nested counts when count distinct is selected', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const selectParts = [
|
2018-05-30 09:22:16 +02:00
|
|
|
queryPart.create({
|
|
|
|
|
type: 'field',
|
|
|
|
|
category: queryPart.getCategories().Fields,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'distinct',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'count',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
];
|
2018-08-26 18:43:07 +02:00
|
|
|
const partModel = queryPart.create({
|
2018-05-30 09:22:16 +02:00
|
|
|
type: 'count',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
queryPart.replaceAggregationAdd(selectParts, partModel);
|
|
|
|
|
|
|
|
|
|
expect(selectParts[1].text).toBe('distinct()');
|
|
|
|
|
expect(selectParts[2].text).toBe('count()');
|
|
|
|
|
expect(selectParts).toHaveLength(3);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not remove count distinct when distinct is added', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const selectParts = [
|
2018-05-30 09:22:16 +02:00
|
|
|
queryPart.create({
|
|
|
|
|
type: 'field',
|
|
|
|
|
category: queryPart.getCategories().Fields,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'distinct',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'count',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
];
|
2018-08-26 18:43:07 +02:00
|
|
|
const partModel = queryPart.create({
|
2018-05-30 09:22:16 +02:00
|
|
|
type: 'distinct',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
queryPart.replaceAggregationAdd(selectParts, partModel);
|
|
|
|
|
|
|
|
|
|
expect(selectParts[1].text).toBe('distinct()');
|
|
|
|
|
expect(selectParts[2].text).toBe('count()');
|
|
|
|
|
expect(selectParts).toHaveLength(3);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should remove distinct when sum aggregation is selected', () => {
|
2018-08-26 18:43:07 +02:00
|
|
|
const selectParts = [
|
2018-05-30 09:22:16 +02:00
|
|
|
queryPart.create({
|
|
|
|
|
type: 'field',
|
|
|
|
|
category: queryPart.getCategories().Fields,
|
|
|
|
|
}),
|
|
|
|
|
queryPart.create({
|
|
|
|
|
type: 'distinct',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
}),
|
|
|
|
|
];
|
2018-08-26 18:43:07 +02:00
|
|
|
const partModel = queryPart.create({
|
2018-05-30 09:22:16 +02:00
|
|
|
type: 'sum',
|
|
|
|
|
category: queryPart.getCategories().Aggregations,
|
|
|
|
|
});
|
|
|
|
|
queryPart.replaceAggregationAdd(selectParts, partModel);
|
|
|
|
|
|
|
|
|
|
expect(selectParts[1].text).toBe('sum()');
|
|
|
|
|
});
|
2015-09-30 17:16:34 +02:00
|
|
|
});
|
|
|
|
|
});
|