Skip to content

Commit 99f1810

Browse files
committed
elasticsearch: Interpolate datapoint field values into transformation
data prefixed with "__field_"
1 parent c800ca3 commit 99f1810

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## development
44
- Improve tests for checking "clickthroughUrl" interpolation
55
- Add tests for elasticsearch query results, both for table- and timeseries-data
6+
- Interpolate datapoint field values with `__field_` prefix into transformation
7+
data, now also for elasticsearch queries.
68

79

810
## v0.9.0

src/data_formatter.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,21 @@ describe('DataFormatter', () => {
365365
'columns': [
366366
{text: 'geopoint'},
367367
{text: 'metric'},
368+
{text: 'foo'},
369+
{text: 'bar'},
368370
],
369371
'rows': [
370372
[
371373
'u0wt6pv2qqhz',
372374
123.45,
375+
"42.42",
376+
42.42,
373377
],
374378
[
375379
'u33dbm6duz90',
376380
67.890,
381+
"43.43",
382+
43.43,
377383
],
378384
],
379385
},
@@ -386,7 +392,11 @@ describe('DataFormatter', () => {
386392

387393
it('the fields should be available within transformed data', () => {
388394
expect(data[0].value).toEqual(123.45);
395+
expect(data[0].__field_foo).toEqual("42.42");
396+
expect(data[0].__field_bar).toEqual(42.42);
389397
expect(data[1].value).toEqual(67.890);
398+
expect(data[1].__field_foo).toEqual("43.43");
399+
expect(data[1].__field_bar).toEqual(43.43);
390400
});
391401

392402
});
@@ -412,10 +422,14 @@ describe('DataFormatter', () => {
412422
{
413423
geopoint: 'u0wt6pv2qqhz',
414424
metric: 123.45,
425+
foo: "42.42",
426+
bar: 42.42,
415427
},
416428
{
417429
geopoint: 'u33dbm6duz90',
418430
metric: 67.890,
431+
foo: "43.43",
432+
bar: 43.43,
419433
},
420434
],
421435
},
@@ -428,7 +442,11 @@ describe('DataFormatter', () => {
428442

429443
it('the fields should be available within transformed data', () => {
430444
expect(data[0].value).toEqual(123.45);
445+
expect(data[0].__field_foo).toEqual("42.42");
446+
expect(data[0].__field_bar).toEqual(42.42);
431447
expect(data[1].value).toEqual(67.890);
448+
expect(data[1].__field_foo).toEqual("43.43");
449+
expect(data[1].__field_bar).toEqual(43.43);
432450
});
433451

434452
});

src/data_formatter.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default class DataFormatter {
8787
return loc.key.toUpperCase() === serie.alias.toUpperCase();
8888
});
8989

90+
// Todo: Propagate user-level notification?
9091
if (!location) {
9192
return;
9293
}
@@ -201,6 +202,15 @@ export default class DataFormatter {
201202
const link = this.settings.esLink ? row[columnNames[this.settings.esLink]] : null;
202203

203204
const dataValue = this.createDataValue(encodedGeohash, decodedGeohash, locationName, value, link);
205+
206+
// Add all values from the original datapoint as attributes prefixed with `__field_`.
207+
for (let columnName in columnNames) {
208+
const value = row[columnNames[columnName]];
209+
const key = '__field_' + columnName;
210+
dataValue[key] = value;
211+
}
212+
213+
// Bookkeeping for computing valueRange.
204214
if (dataValue.value > highestValue) {
205215
highestValue = dataValue.value;
206216
}
@@ -232,6 +242,15 @@ export default class DataFormatter {
232242
const link = this.settings.esLink ? datapoint[this.settings.esLink] : null;
233243

234244
const dataValue = this.createDataValue(encodedGeohash, decodedGeohash, locationName, value, link);
245+
246+
// Add all values from the original datapoint as attributes prefixed with `__field_`.
247+
for (let key in datapoint) {
248+
const value = datapoint[key];
249+
key = '__field_' + key;
250+
dataValue[key] = value;
251+
}
252+
253+
// Bookkeeping for computing valueRange.
235254
if (dataValue.value > highestValue) {
236255
highestValue = dataValue.value;
237256
}

0 commit comments

Comments
 (0)