Skip to content

Commit

Permalink
Remove duplicate values
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Oct 1, 2020
1 parent 912fe00 commit d8daf49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
18 changes: 3 additions & 15 deletions x-pack/plugins/lens/server/routes/existing_fields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('existingFields', () => {
name,
isScript: false,
isMeta: false,
path: name,
...obj,
};
}
Expand Down Expand Up @@ -51,28 +50,19 @@ describe('existingFields', () => {
expect(result).toEqual(['geo.country_name']);
});

it('should use path, not name', () => {
const result = existingFields(
[searchResults({ 'stuff.foo': ['bar'] })],
[field({ name: 'goober', path: 'stuff.foo' })]
);

expect(result).toEqual(['goober']);
});

it('supports scripted fields', () => {
const result = existingFields(
[searchResults({ bar: ['scriptvalue'] })],
[field({ name: 'baz', isScript: true, path: 'bar' })]
[field({ name: 'bar', isScript: true })]
);

expect(result).toEqual(['baz']);
expect(result).toEqual(['bar']);
});

it('supports meta fields', () => {
const result = existingFields(
[{ _mymeta: 'abc', ...searchResults({ bar: ['scriptvalue'] }) }],
[field({ name: '_mymeta', isMeta: true, path: '_mymeta' })]
[field({ name: '_mymeta', isMeta: true })]
);

expect(result).toEqual(['_mymeta']);
Expand Down Expand Up @@ -103,7 +93,6 @@ describe('buildFieldList', () => {
expect(fields.find((f) => f.isScript)).toMatchObject({
isScript: true,
name: 'foo',
path: 'foo',
lang: 'painless',
script: '2+2',
});
Expand All @@ -115,7 +104,6 @@ describe('buildFieldList', () => {
isScript: false,
isMeta: true,
name: '_mymeta',
path: '_mymeta',
});
});
});
10 changes: 2 additions & 8 deletions x-pack/plugins/lens/server/routes/existing_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { schema } from '@kbn/config-schema';
import { ILegacyScopedClusterClient, SavedObject, RequestHandlerContext } from 'src/core/server';
import { CoreSetup } from 'src/core/server';
import { BASE_API_URL } from '../../common';
import {
IndexPatternsFetcher,
IndexPatternAttributes,
UI_SETTINGS,
} from '../../../../../src/plugins/data/server';
import { IndexPatternAttributes, UI_SETTINGS } from '../../../../../src/plugins/data/server';

/**
* The number of docs to sample to determine field empty status.
Expand All @@ -24,7 +20,6 @@ export interface Field {
name: string;
isScript: boolean;
isMeta: boolean;
path: string;
lang?: string;
script?: string;
}
Expand Down Expand Up @@ -139,7 +134,6 @@ export function buildFieldList(
return {
name: field.name,
isScript: !!field.scripted,
path: field.name,
lang: field.lang,
script: field.script,
// id is a special case - it doesn't show up in the meta field list,
Expand Down Expand Up @@ -230,7 +224,7 @@ export function existingFields(
if (field.isMeta) {
fieldStore = doc;
}
const value = fieldStore[field.path];
const value = fieldStore[field.name];
if (Array.isArray(value) && value.length) {
missingFields.delete(field);
} else if (!Array.isArray(value) && value) {
Expand Down

0 comments on commit d8daf49

Please sign in to comment.