Skip to content

Commit

Permalink
Merge pull request #229 from keen/bugfix/extraction-keys
Browse files Browse the repository at this point in the history
fix issue with extraction missing keys
  • Loading branch information
Artur Pryka authored Oct 8, 2020
2 parents 91d7520 + 291d07d commit 429ab55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lib/dataset/utils/create-extraction-keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { flatten } from '../utils/flatten';

export function createExtractionKeys(results) {
const keys = new Set();
results.forEach((result) => {
Object.keys(flatten(result)).map((key) => {
keys.add(key);
});
});

return keys;
}
11 changes: 6 additions & 5 deletions lib/dataset/utils/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let Dataset; /* injected */
import { each } from '../../utils/each';
import { flatten } from '../utils/flatten';
import { valueAtDeepKey } from '../utils/object';
import { createExtractionKeys } from '../utils/create-extraction-keys';

export default function initialize(lib){
Dataset = lib;
Expand Down Expand Up @@ -162,8 +163,8 @@ function parseExtraction(){
const datasetExtraction = new Dataset()
.type('extraction');

// get keys of the Object, static schema
let names = Object.keys(flatten(res.result[0]));
const datasetKeys = createExtractionKeys(res.result);
let names = Array.from(datasetKeys);

const tableConfig = config && config.table;
if (tableConfig && tableConfig.schema === 'dynamic') {
Expand All @@ -181,13 +182,13 @@ function parseExtraction(){
});
names = Object.keys(keys);
}

let nameI = 0;
names.forEach(value => {
datasetExtraction.set([ value, '0' ], value);
nameI++;
});

if (Dataset) {
if (config
&& config.table
Expand All @@ -214,7 +215,7 @@ function parseHeatmapAxis() {
return function(res) {
const heatmapDataset = new Dataset()
.type('heatmap');

each(res.result, function(value, i){
const objKeys = Object.keys(value);
const x = value[objKeys[0]];
Expand Down

0 comments on commit 429ab55

Please sign in to comment.