[ES|QL] Fixes the mapping of ES fields (#176665)

## Summary

When we created the ESQL strategy we used the same logic with SQL. But
this is not 100% correct. For example it converts the ip type fields to
strings, same as geo_points. This PR is fixing it.

So now if you run for example

```
from kibana_sample_data_logs | WHERE CIDR_MATCH(ip, "153.189.234.161/32", "127.0.0.3/32") | stats count(*)
```

the client side validation won't fail.
This commit is contained in:
Stratoula Kalafateli 2024-02-12 17:18:33 +02:00 committed by GitHub
parent d676f169f0
commit 8a651ea5be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 28 deletions

View file

@ -52,8 +52,6 @@ export const getFilterableKbnTypeNames = (): string[] =>
export function esFieldTypeToKibanaFieldType(type: string) {
switch (type) {
case ES_FIELD_TYPES._INDEX:
case ES_FIELD_TYPES.GEO_POINT:
case ES_FIELD_TYPES.IP:
return KBN_FIELD_TYPES.STRING;
case '_version':
return KBN_FIELD_TYPES.NUMBER;

View file

@ -7,13 +7,9 @@
*/
import type { KibanaRequest } from '@kbn/core/server';
import { castEsToKbnFieldTypeName, ES_FIELD_TYPES, KBN_FIELD_TYPES } from '@kbn/field-types';
import { esFieldTypeToKibanaFieldType } from '@kbn/field-types';
import { i18n } from '@kbn/i18n';
import type {
Datatable,
DatatableColumnType,
ExpressionFunctionDefinition,
} from '@kbn/expressions-plugin/common';
import type { Datatable, ExpressionFunctionDefinition } from '@kbn/expressions-plugin/common';
import { RequestAdapter } from '@kbn/inspector-plugin/common';
import { zipObject } from 'lodash';
@ -61,21 +57,6 @@ interface EsqlStartDependencies {
uiSettings: UiSettingsCommon;
}
function normalizeType(type: string): DatatableColumnType {
switch (type) {
case ES_FIELD_TYPES._INDEX:
case ES_FIELD_TYPES.GEO_POINT:
case ES_FIELD_TYPES.IP:
return KBN_FIELD_TYPES.STRING;
case '_version':
return KBN_FIELD_TYPES.NUMBER;
case 'datetime':
return KBN_FIELD_TYPES.DATE;
default:
return castEsToKbnFieldTypeName(type) as DatatableColumnType;
}
}
function extractTypeAndReason(attributes: any): { type?: string; reason?: string } {
if (['type', 'reason'].every((prop) => prop in attributes)) {
return attributes;
@ -252,7 +233,7 @@ export const getEsqlFn = ({ getStartDependencies }: EsqlFnArguments) => {
(body.all_columns ?? body.columns)?.map(({ name, type }) => ({
id: name,
name,
meta: { type: normalizeType(type) },
meta: { type: esFieldTypeToKibanaFieldType(type) },
isNull: hasEmptyColumns ? !lookup.has(name) : false,
})) ?? [];

View file

@ -130,7 +130,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.unifiedFieldList.clickFieldListItemAdd('ip');
await PageObjects.unifiedFieldList.clickFieldListItemAdd('geo.coordinates');
expect(await findFirstColumnTokens()).to.eql(['Number', 'String', 'String', 'String']);
expect(await findFirstColumnTokens()).to.eql(['Number', 'String', 'IP address', 'Geo point']);
expect(await findFirstDocViewerTokens()).to.eql([
'String',
@ -138,9 +138,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'Date',
'String',
'Number',
'IP address',
'String',
'String',
'String',
'Geo point',
'String',
'String',
]);

View file

@ -114,7 +114,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.unifiedFieldList.waitUntilSidebarHasLoaded();
await PageObjects.unifiedFieldList.openSidebarFieldFilter();
options = await find.allByCssSelector('[data-test-subj*="typeFilter"]');
expect(options).to.have.length(3);
expect(options).to.have.length(5);
expect(await PageObjects.unifiedFieldList.getSidebarAriaDescription()).to.be(
'82 available fields.'