forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] ESQL geo_shape support (elastic#175156)
elastic/elasticsearch#104269 adds geo_shape support to ESQL This PR updates maps ESQL source to support geo_shape column type <img width="800" alt="Screenshot 2024-01-18 at 1 15 31 PM" src="https://github.com/elastic/kibana/assets/373691/844251a6-4409-45f4-89f5-513f4537d833"> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
74aac97
commit 8dc22fb
Showing
6 changed files
with
205 additions
and
11 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
x-pack/plugins/maps/public/classes/sources/esql_source/create_source_editor.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import { CreateSourceEditor } from './create_source_editor'; | ||
|
||
jest.mock('../../../kibana_services', () => { | ||
const mockDefaultDataView = { | ||
fields: [ | ||
{ | ||
name: 'location', | ||
type: 'geo_point', | ||
}, | ||
{ | ||
name: '@timestamp', | ||
type: 'date', | ||
}, | ||
], | ||
timeFieldName: '@timestamp', | ||
getIndexPattern: () => { | ||
return 'logs'; | ||
}, | ||
}; | ||
const mockDataView = { | ||
fields: [ | ||
{ | ||
name: 'geometry', | ||
type: 'geo_shape', | ||
}, | ||
], | ||
getIndexPattern: () => { | ||
return 'world_countries'; | ||
}, | ||
}; | ||
return { | ||
getIndexPatternService() { | ||
return { | ||
get: async () => { | ||
return mockDataView; | ||
}, | ||
getDefaultDataView: async () => { | ||
return mockDefaultDataView; | ||
}, | ||
}; | ||
}, | ||
}; | ||
}); | ||
|
||
describe('CreateSourceEditor', () => { | ||
test('should preview default data view on load', async () => { | ||
const onSourceConfigChange = jest.fn(); | ||
render(<CreateSourceEditor onSourceConfigChange={onSourceConfigChange} />); | ||
await waitFor(() => | ||
expect(onSourceConfigChange).toBeCalledWith({ | ||
columns: [ | ||
{ | ||
name: 'location', | ||
type: 'geo_point', | ||
}, | ||
], | ||
dateField: '@timestamp', | ||
esql: 'from logs | keep location | limit 10000', | ||
}) | ||
); | ||
}); | ||
|
||
test('should preview requested data view on load when mostCommonDataViewId prop provided', async () => { | ||
const onSourceConfigChange = jest.fn(); | ||
render( | ||
<CreateSourceEditor | ||
onSourceConfigChange={onSourceConfigChange} | ||
mostCommonDataViewId="123abc" | ||
/> | ||
); | ||
await waitFor(() => | ||
expect(onSourceConfigChange).toBeCalledWith({ | ||
columns: [ | ||
{ | ||
name: 'geometry', | ||
type: 'geo_shape', | ||
}, | ||
], | ||
dateField: undefined, | ||
esql: 'from world_countries | keep geometry | limit 10000', | ||
}) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/maps/public/classes/sources/esql_source/esql_source.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ESQLSource } from './esql_source'; | ||
import { VECTOR_SHAPE_TYPE } from '../../../../common/constants'; | ||
|
||
describe('getSupportedShapeTypes', () => { | ||
test('should return point for geo_point column', async () => { | ||
const descriptor = ESQLSource.createDescriptor({ | ||
esql: 'from kibana_sample_data_logs | keep geo.coordinates | limit 10000', | ||
columns: [ | ||
{ | ||
name: 'geo.coordinates', | ||
type: 'geo_point', | ||
}, | ||
], | ||
}); | ||
const esqlSource = new ESQLSource(descriptor); | ||
expect(await esqlSource.getSupportedShapeTypes()).toEqual([VECTOR_SHAPE_TYPE.POINT]); | ||
}); | ||
|
||
test('should return all geometry types for geo_shape column', async () => { | ||
const descriptor = ESQLSource.createDescriptor({ | ||
esql: 'from world_countries | keep geometry | limit 10000', | ||
columns: [ | ||
{ | ||
name: 'geometry', | ||
type: 'geo_shape', | ||
}, | ||
], | ||
}); | ||
const esqlSource = new ESQLSource(descriptor); | ||
expect(await esqlSource.getSupportedShapeTypes()).toEqual([ | ||
VECTOR_SHAPE_TYPE.POINT, | ||
VECTOR_SHAPE_TYPE.LINE, | ||
VECTOR_SHAPE_TYPE.POLYGON, | ||
]); | ||
}); | ||
|
||
test('should fallback to point when geometry column can not be found', async () => { | ||
const descriptor = ESQLSource.createDescriptor({ | ||
esql: 'from world_countries | keep geometry | limit 10000', | ||
}); | ||
const esqlSource = new ESQLSource(descriptor); | ||
expect(await esqlSource.getSupportedShapeTypes()).toEqual([VECTOR_SHAPE_TYPE.POINT]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/maps/public/classes/sources/esql_source/esql_utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { isGeometryColumn } from './esql_utils'; | ||
|
||
describe('isGeometryColumn', () => { | ||
test('should return true for geo_point columns', () => { | ||
expect(isGeometryColumn({ name: 'myColumn', type: 'geo_point' })).toBe(true); | ||
}); | ||
|
||
test('should return true for geo_shape columns', () => { | ||
expect(isGeometryColumn({ name: 'myColumn', type: 'geo_shape' })).toBe(true); | ||
}); | ||
|
||
test('should return false for non-geometry columns', () => { | ||
expect(isGeometryColumn({ name: 'myColumn', type: 'string' })).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters