Skip to content

Commit

Permalink
fix: Handles parsing errors when format not expected on distinct valu…
Browse files Browse the repository at this point in the history
…es (#966)

* fix: Handles parsing errors when format not expected on distinct values

Signed-off-by: Marcos Iglesias <miglesiasvalle@lyft.com>

* Updates docs

Signed-off-by: Marcos Iglesias <miglesiasvalle@lyft.com>
  • Loading branch information
Golodhros authored Apr 2, 2021
1 parent e3be638 commit 473bbdb
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
74 changes: 74 additions & 0 deletions amundsen_application/static/js/utils/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,69 @@ describe('stats utils', () => {
stat_val: '70',
},
];
const STRINGIFIED_ARRAY_UNIQUE_VALUES = [
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'count_null',
stat_val: '0.0',
},
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'count_zero',
stat_val: '4378016.0',
},
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'stddev_value',
stat_val: '0.5856386084183235',
},
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'avg_value',
stat_val: '0.6695026231618191',
},
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'distinctValues',
stat_val:
'{1: 5756008, 0: 4450396, 2: 591892, 3: 12948, 4: 424, 5: 40, 11: 16, 7: 12, 6: 8, 9: 8, 8: 4, 10: 4}',
},
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'approx_distinct_count',
stat_val: '13.0',
},
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'max_value',
stat_val: '12.0',
},
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'min_value',
stat_val: '0.0',
},
{
end_epoch: 1617147150,
start_epoch: 1616542350,
stat_type: 'median_value',
stat_val: '0.9907752863495858',
},
{
end_epoch: 1615593600,
start_epoch: 1613001600,
stat_type: 'column_usage',
stat_val: '78',
},
];

describe('getUniqueValues', () => {
it('returns an empty array when there is no stats', () => {
Expand Down Expand Up @@ -545,6 +608,17 @@ describe('stats utils', () => {
expect(actual).toEqual(expected);
});
});

describe('when there are unique values as a stringified array', () => {
it('returns an array with zero elements', () => {
const expected = 0;
const actual = StatUtils.getUniqueValues(
STRINGIFIED_ARRAY_UNIQUE_VALUES
).length;

expect(actual).toEqual(expected);
});
});
});

describe('filterOutUniqueValues', () => {
Expand Down
14 changes: 12 additions & 2 deletions amundsen_application/static/js/utils/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ const mapIntoUniqueValueFormat = ([k, v]): ColumnUniqueValues => ({
value: k,
count: v,
});
const parseRawUniqueValues = (uniqueValues: string) =>
JSON.parse(uniqueValues.split("'").join('"'));
const parseRawUniqueValues = (uniqueValues: string) => {
let parsedUniqueValues = {};

try {
parsedUniqueValues = JSON.parse(uniqueValues.split("'").join('"'));
} catch (e) {
// eslint-disable-next-line no-console
console.log('Error parsing unique values on stats!');
}

return parsedUniqueValues;
};

/**
* Parses the stats' unique values key into an array of
Expand Down
12 changes: 12 additions & 0 deletions docs/application_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ To achieve this, you will need to modify your custom configuration (config-custo
}
```

The unique values set needs to be an object like this:

```
{
end_epoch: 1609522182,
start_epoch: 1608917382,
stat_type: 'keyNameExample',
stat_val:
"{'Category': 66, 'AnotherCategory': 54, 'More': 48}",
},
```

## Notices

We now can add notices to tables and dashboards. These notices allows Amundsen administrators to show informational, warning and alert messages related to the different resources (tables, dashboards, eventually people) we expose in Amundsen.
Expand Down

0 comments on commit 473bbdb

Please sign in to comment.