Skip to content

Commit

Permalink
[Maps] fix data-mapping switch enabled for vector tiles (#116366)
Browse files Browse the repository at this point in the history
* clean up IField API

* disable switch when using MVTs for es docs

* clean up interface comment style

* implement supportsFieldMetaFromEs and supportsFieldMetaFromLocalData in all Field classes

* fix dynamic_color_property test

* fix jest tests

* mock getRangeFieldMeta instead of passing in VectorLayerMock with MockStyle

* review feedback

* clean up supportsFieldMetaFromLocalData test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
nreese and kibanamachine committed Oct 29, 2021
1 parent d284d65 commit ee61368
Show file tree
Hide file tree
Showing 32 changed files with 526 additions and 270 deletions.
41 changes: 32 additions & 9 deletions x-pack/plugins/maps/public/classes/fields/agg/agg_field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,48 @@ const defaultParams = {
origin: FIELD_ORIGIN.SOURCE,
};

describe('supportsFieldMeta', () => {
test('Non-counting aggregations should support field meta', () => {
describe('supportsFieldMetaFromEs', () => {
test('Non-counting aggregations should support field meta from ES', () => {
const avgMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.AVG });
expect(avgMetric.supportsFieldMeta()).toBe(true);
expect(avgMetric.supportsFieldMetaFromEs()).toBe(true);
const maxMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.MAX });
expect(maxMetric.supportsFieldMeta()).toBe(true);
expect(maxMetric.supportsFieldMetaFromEs()).toBe(true);
const minMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.MIN });
expect(minMetric.supportsFieldMeta()).toBe(true);
expect(minMetric.supportsFieldMetaFromEs()).toBe(true);
const termsMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.TERMS });
expect(termsMetric.supportsFieldMeta()).toBe(true);
expect(termsMetric.supportsFieldMetaFromEs()).toBe(true);
});

test('Counting aggregations should not support field meta', () => {
test('Counting aggregations should not support field meta from ES', () => {
const sumMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.SUM });
expect(sumMetric.supportsFieldMeta()).toBe(false);
expect(sumMetric.supportsFieldMetaFromEs()).toBe(false);
const uniqueCountMetric = new AggField({
...defaultParams,
aggType: AGG_TYPE.UNIQUE_COUNT,
});
expect(uniqueCountMetric.supportsFieldMeta()).toBe(false);
expect(uniqueCountMetric.supportsFieldMetaFromEs()).toBe(false);
});
});

describe('supportsFieldMetaFromLocalData', () => {
test('number metrics should support field meta from local', () => {
const avgMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.AVG });
expect(avgMetric.supportsFieldMetaFromLocalData()).toBe(true);
const maxMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.MAX });
expect(maxMetric.supportsFieldMetaFromLocalData()).toBe(true);
const minMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.MIN });
expect(minMetric.supportsFieldMetaFromLocalData()).toBe(true);
const sumMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.SUM });
expect(sumMetric.supportsFieldMetaFromLocalData()).toBe(true);
const uniqueCountMetric = new AggField({
...defaultParams,
aggType: AGG_TYPE.UNIQUE_COUNT,
});
expect(uniqueCountMetric.supportsFieldMetaFromLocalData()).toBe(true);
});

test('Non number metrics should not support field meta from local', () => {
const termMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.TERMS });
expect(termMetric.supportsFieldMetaFromLocalData()).toBe(false);
});
});
21 changes: 15 additions & 6 deletions x-pack/plugins/maps/public/classes/fields/agg/agg_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export class AggField extends CountAggField {
this._aggType = params.aggType;
}

supportsFieldMetaFromEs(): boolean {
// count and sum aggregations are not within field bounds so they do not support field meta.
return !isMetricCountable(this._getAggType());
}

supportsFieldMetaFromLocalData(): boolean {
// Elasticsearch vector tile search API returns meta tiles with numeric aggregation metrics.
return this._getDataTypeSynchronous() === 'number';
}

isValid(): boolean {
return !!this._esDocField;
}
Expand All @@ -38,11 +48,6 @@ export class AggField extends CountAggField {
return this._source.isMvt() ? this.getName() + '.value' : this.getName();
}

supportsFieldMeta(): boolean {
// count and sum aggregations are not within field bounds so they do not support field meta.
return !isMetricCountable(this._getAggType());
}

canValueBeFormatted(): boolean {
return this._getAggType() !== AGG_TYPE.UNIQUE_COUNT;
}
Expand Down Expand Up @@ -73,10 +78,14 @@ export class AggField extends CountAggField {
);
}

async getDataType(): Promise<string> {
_getDataTypeSynchronous(): string {
return this._getAggType() === AGG_TYPE.TERMS ? 'string' : 'number';
}

async getDataType(): Promise<string> {
return this._getDataTypeSynchronous();
}

getBucketCount(): number {
// terms aggregation increases the overall number of buckets per split bucket
return this._getAggType() === AGG_TYPE.TERMS ? TERMS_AGG_SHARD_SIZE : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ export interface CountAggFieldParams {
label?: string;
source: IESAggSource;
origin: FIELD_ORIGIN;
canReadFromGeoJson?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const defaultParams = {
origin: FIELD_ORIGIN.SOURCE,
};

describe('supportsFieldMeta', () => {
describe('supportsFieldMetaFromEs', () => {
test('Counting aggregations should not support field meta', () => {
const countMetric = new CountAggField({ ...defaultParams });
expect(countMetric.supportsFieldMeta()).toBe(false);
expect(countMetric.supportsFieldMetaFromEs()).toBe(false);
});
});
25 changes: 10 additions & 15 deletions x-pack/plugins/maps/public/classes/fields/agg/count_agg_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ export class CountAggField implements IESAggField {
protected readonly _source: IESAggSource;
private readonly _origin: FIELD_ORIGIN;
protected readonly _label?: string;
private readonly _canReadFromGeoJson: boolean;

constructor({ label, source, origin, canReadFromGeoJson = true }: CountAggFieldParams) {
constructor({ label, source, origin }: CountAggFieldParams) {
this._source = source;
this._origin = origin;
this._label = label;
this._canReadFromGeoJson = canReadFromGeoJson;
}

supportsFieldMetaFromEs(): boolean {
return false;
}

supportsFieldMetaFromLocalData(): boolean {
// Elasticsearch vector tile search API returns meta tiles for aggregation metrics
return true;
}

_getAggType(): AGG_TYPE {
Expand Down Expand Up @@ -79,10 +86,6 @@ export class CountAggField implements IESAggField {
return null;
}

supportsFieldMeta(): boolean {
return false;
}

getBucketCount() {
return 0;
}
Expand All @@ -103,14 +106,6 @@ export class CountAggField implements IESAggField {
return null;
}

supportsAutoDomain(): boolean {
return true;
}

canReadFromGeoJson(): boolean {
return this._canReadFromGeoJson;
}

isEqual(field: IESAggField) {
return field.getName() === this.getName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ import { PercentileAggField } from './percentile_agg_field';
export function esAggFieldsFactory(
aggDescriptor: AggDescriptor,
source: IESAggSource,
origin: FIELD_ORIGIN,
canReadFromGeoJson: boolean = true
origin: FIELD_ORIGIN
): IESAggField[] {
let aggField;
if (aggDescriptor.type === AGG_TYPE.COUNT) {
aggField = new CountAggField({
label: aggDescriptor.label,
source,
origin,
canReadFromGeoJson,
});
} else if (aggDescriptor.type === AGG_TYPE.PERCENTILE) {
aggField = new PercentileAggField({
Expand All @@ -42,7 +40,6 @@ export function esAggFieldsFactory(
: DEFAULT_PERCENTILE,
source,
origin,
canReadFromGeoJson,
});
} else {
aggField = new AggField({
Expand All @@ -54,14 +51,13 @@ export function esAggFieldsFactory(
aggType: aggDescriptor.type,
source,
origin,
canReadFromGeoJson,
});
}

const aggFields: IESAggField[] = [aggField];

if ('field' in aggDescriptor && aggDescriptor.type === AGG_TYPE.TERMS) {
aggFields.push(new TopTermPercentageField(aggField, canReadFromGeoJson));
aggFields.push(new TopTermPercentageField(aggField));
}

return aggFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export class PercentileAggField extends AggField implements IESAggField {
this._percentile = params.percentile;
}

supportsFieldMeta(): boolean {
supportsFieldMetaFromEs(): boolean {
return true;
}

supportsFieldMetaFromLocalData(): boolean {
// Elasticsearch vector tile search API returns meta tiles for aggregation metrics
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import { TOP_TERM_PERCENTAGE_SUFFIX, FIELD_ORIGIN } from '../../../../common/con

export class TopTermPercentageField implements IESAggField {
private readonly _topTermAggField: IESAggField;
private readonly _canReadFromGeoJson: boolean;

constructor(topTermAggField: IESAggField, canReadFromGeoJson: boolean = true) {
constructor(topTermAggField: IESAggField) {
this._topTermAggField = topTermAggField;
this._canReadFromGeoJson = canReadFromGeoJson;
}

supportsFieldMetaFromEs(): boolean {
return false;
}

supportsFieldMetaFromLocalData(): boolean {
// Elasticsearch vector tile search API does not support top term metric
return false;
}

getSource(): IVectorSource {
Expand Down Expand Up @@ -64,15 +71,6 @@ export class TopTermPercentageField implements IESAggField {
getBucketCount(): number {
return 0;
}

supportsAutoDomain(): boolean {
return this._canReadFromGeoJson;
}

supportsFieldMeta(): boolean {
return false;
}

async getExtendedStatsFieldMetaRequest(): Promise<unknown | null> {
return null;
}
Expand All @@ -89,10 +87,6 @@ export class TopTermPercentageField implements IESAggField {
return false;
}

canReadFromGeoJson(): boolean {
return this._canReadFromGeoJson;
}

isEqual(field: IESAggField) {
return field.getName() === this.getName();
}
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/maps/public/classes/fields/ems_file_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class EMSFileField extends AbstractField implements IField {
this._source = source;
}

supportsFieldMetaFromEs(): boolean {
return false;
}

supportsFieldMetaFromLocalData(): boolean {
return true;
}

getSource(): IVectorSource {
return this._source;
}
Expand Down
21 changes: 9 additions & 12 deletions x-pack/plugins/maps/public/classes/fields/es_doc_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ import { IVectorSource } from '../sources/vector_source';

export class ESDocField extends AbstractField implements IField {
private readonly _source: IESSource;
private readonly _canReadFromGeoJson: boolean;

constructor({
fieldName,
source,
origin,
canReadFromGeoJson = true,
}: {
fieldName: string;
source: IESSource;
origin: FIELD_ORIGIN;
canReadFromGeoJson?: boolean;
}) {
super({ fieldName, origin });
this._source = source;
this._canReadFromGeoJson = canReadFromGeoJson;
}

supportsFieldMetaFromEs(): boolean {
return true;
}

supportsFieldMetaFromLocalData(): boolean {
// Elasticsearch vector tile search API does not return meta tiles for documents
return !this.getSource().isMvt();
}

canValueBeFormatted(): boolean {
Expand Down Expand Up @@ -73,14 +78,6 @@ export class ESDocField extends AbstractField implements IField {
: super.getLabel();
}

supportsFieldMeta(): boolean {
return true;
}

canReadFromGeoJson(): boolean {
return this._canReadFromGeoJson;
}

async getExtendedStatsFieldMetaRequest(): Promise<unknown | null> {
const indexPatternField = await this._getIndexPatternField();

Expand Down
Loading

0 comments on commit ee61368

Please sign in to comment.