Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Supports SQL query language (#134429) #136702

Merged
merged 36 commits into from
Jul 26, 2022

Conversation

stratoula
Copy link
Contributor

@stratoula stratoula commented Jul 20, 2022

Summary

This PR enables the SQL queries in Discover. The feature is available after an advanced setting is enabled.
image

The user can run sql queries and also save them as saved searches. These searches cant be used for creating an aggregation based visualization but can be imported on a dashboard.

sql_discover

sql_discover1

For the technical preview we are going to support the following features:

  • SQL integration, FROM clause bound to a data view (error if no match)
  • No autocomplete
  • No date histogram
  • Saving as part of the saved search
  • No switch to Lens
  • No filter by cell click
  • Time range integration
  • Dashboard filter integration
  • No async search / search sessions
  • No “add field” button
  • No document viewer / context viewer
  • Inline documentation

Checklist

Delete any items that are not applicable to this PR.

* Move the add dataview action above the dataview selection panel

* Implements a new selectable on the dataview picker for the text based languages

* Implementation of the transition modal when on SQL mode and select a dataview

* Fix es lint

* Change switch modal button modal icon

* Lazy load components

* Small changes on the styling of the switch without saving button

* Initialization of mocaco editor

* Change to the type

* Fixes types checks

* New submit button for query mode

* Implememtation of the expanded mode of the editor

* Implement documentation

* Implementation of the oneliner mode with ellipsis

* Some  fixes on the resizer

* Implementation of the errors layout, WIP

* Fetch SQL data in Discover

* Fix expression test

* Fix editor zIndex

* Fix types error

* Fix type check in Discover

* Fix more types

* some CI fixes

* Fixes

* Cleanup after merge

* Remove from state

* Connect search errors with the unified search editor

* Add error mrkers in unified search editor

* Save and open saved searches

* Filter out saved searches from text based languages

* Some fixes

* Fix unit tests

* Fix checks

* On save and exit modal implementation

* Add shortcut on the editor for submit query

* Fix wrong condition

* Initial types change

* Use regex to find the index pattern string

* Fix some types and cleanup

* Fix types

* Fix some types

* Further fixes

* More fixes

* More fixes

* Fix visualize types

* more

* More fixes

* Fixes more types

* Fix dashboard types

* Fix dashboard types

* Controls plugin types

* Fix Lens types

* Fix data plugin types

* Fix types in Lens 2

* buildEsConfig type fixes

* Fix observability types

* Fix maps types

* data visualizer types

* Fix ml types

* xpack rest types

* Fix jest test

* Fix

* Move helper functions to es config

* fix bug on breadcrumb click

* Fix time field bug

* Add enableSql advanced setting to discover for enabling the sql mode

* Make the documentation component more dynamic

* Add some comments, improvements

* Enhance storybook with the textbased languages

* Update storybook with the error state of the editor

* Adds a readme for the editor and fixes the modal mobile version

* [Discover] improve test and storybook for new data type

* [Discover] add functional tests

* Add aggregate functions to the documentation

* [Discover] fix tests

* Add some unit tests

* [Discover] fix linting

* [Discover] update linting

* More unti tests

* Dataview picker unit tests

* Fix a bug on the dataview picker

* Add unit tests for the editor

* Fix jest test

* [Discover] apply suggestions

* [Discover] adjust styles

* Fix some bugs and select columns in the sql mode

* [Discover] fix eslint and tests

* [Discover] update unit tests

* Fix bug on transitioning from sql mode to dataview mode

* [Discover] fix tests

* Design fixes on the errors messages

* [Discover] fix ci

* Update the columns only if the query changes

* [Discover] change isPlainRecord retrieval method

* Fix bug on cleanup

* Fix bug on opening a saved search

* [Discover] fix comments

* [Discover] fix bug with browser refresh

* [Discover] fix functional

* [Discover] fix another functional

* Fix ordering lost when the user refreshes the browser

* [Discover] revert use_discover_state

* [Discover] revert functional impl

* Fix security solution types

* Casting dashboard plugin

* Revert change

* type param

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Revert types changes

* More reverts

* Types fixes

* Fix Discover jest test

* Fix context app jest test

* Final types changes

* Fixes unit test

Co-authored-by: Dzmitry Tamashevich <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Joe Reuter <[email protected]>
@stratoula stratoula added Feature:Unified search Unified search related tasks Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting v8.4.0 labels Jul 20, 2022
@stratoula
Copy link
Contributor Author

I am currently working on these design improvements #134429 (review)

@stratoula stratoula marked this pull request as ready for review July 20, 2022 09:01
@stratoula stratoula requested review from a team as code owners July 20, 2022 09:01
@stratoula stratoula added the Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. label Jul 20, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@stratoula stratoula added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Jul 20, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors)

@stratoula
Copy link
Contributor Author

stratoula commented Jul 20, 2022

@MichaelMarcialis I have addressed the majority of your comments except from:

  • The red underlining of errors within the editor appears odd currently. For example, when supplying an unavailable data view with the SQL FROM clause, only the R in FROM will be underlined in red. It seems odd that only a single character in the clause is being underlined. Further, would it be better to have the unavailable data view underlined here instead?

I can't replicate this. Can you give me the query that you are using?

  • I had suggested in the wireframes that clicking an individual error in the error list popover should focus the user's cursor on that error in the editor. That doesn't appear to be implemented here. Would it be possible to add?

I didn't implement it as we can only have one error and not a list of errors. So the user can't be confused with it. Focusing on a specific line of the monaco editor is also something that needs investigation. I can add it on the list for 8.5.

  • When SQL errors are present and the query is run, the current error messaging doesn't currently appear as suggested in the wireframes. The field list still shows (even in situations where a non-existing data view is being referenced) and the only option provided to users is to show the error message in a toast. Would it be possible to change this to come closer to the what the wireframes suggest?

I used the current Discover logic for displaying errors. I can look into it on a follow up PR!

Depending on my comments above and the fact that this feature is hidden under an advanced setting, do we consider them as blockers for merging this PR?

Copy link
Member

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core changes LGTM (Telemetry updates)

@stratoula
Copy link
Contributor Author

Things that need to be addressed on follow-up PRS have been added here #136950 cc @ghudgins

@gchaps gchaps added the ui-copy Review of UI copy with docs team is recommended label Jul 22, 2022
Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like most of what I reported is already fixed and Discover code changes LGTM!

@stratoula
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VisEditors changes look mostly good to me, noticed two small things but they don't block the PR:

Data view recognition is using the first FROM from the query, but in case of nested selects this doesn't work:
Screenshot 2022-07-25 at 10 27 29

It's possible to save a saved search, build a vis on it, then switch it to sql and save it again. The panel then fails like this:
Screenshot 2022-07-25 at 10 32 00
This could be fixed by "forgetting" the current saved search when switching to/from SQL mode.

Approving as I'm happy to merge as-is

@stratoula
Copy link
Contributor Author

Thanx @flash1293! I am moving them to the follow up issue!

@stratoula
Copy link
Contributor Author

Fixed the nested selects problem (wrong dataview recognition)

image

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making those additional requested changes, @stratoula. Amazing work! I've put together an updated list of comments for your review below.

I know feature freeze is looming and we're eager to get this feature in. At the end of the day, none of my comments are what I'd consider hard blockers, so I'm going to go ahead and approve now so I don't hold you up further (under the assumption that these either get addressed in this PR or spun off as a separate issue/PR).

Replies

About the resizer I am fine on copying the styles but it is a bit confusing for me as I am not very comfortable with the EUI code. I would need some help here.

Certainly. Do you want my assistance, or are you looking for one of the experts from the @elastic/eui-design team? If me, feel free to throw something on the calendar for us to hop on a Zoom.

New Comments

  • For the error popover, would it be possible to put an alignItems="flexStart" prop on the containing EuiFlexGroup? Doing so should prevent the first column (with icon and line number) from being vertical aligned to the center (noticeable when the message breaks a line).

image

  • Would it be possible to support word breaking (via the euiTextBreakWord mixin, I believe) for the messages within the error popover? Currently, long strings of unbroken text can overflow out of the popover.

image

  • For the unfocused editor in compact mode, the presence of the invalid red bottom border appears to be throwing off the editor's alignment (by increasing it's height by 1px) relative to other adjacent elements. Can this be remedied? If the custom styles currently in place aren't working, one alternative may be to use styles like EUI does for standard input (where both the focus and invalid colored borders are created via a background gradient).

image

  • The editor footer in expanded mode still appears to be misaligned by 1px horizontally.

image

  • During a resize action, the gray border above the editor footer disappears and a blue border appears below/behind the footer. Can we correct this so that the gray border doesn't disappear and the blue border doesn't appear during a resize action?

image

  • During a resize action, if an invalid border is present on the editor, it temporarily turns from a 2px border to a 1px border. After stopping the resize action, it correctly returns to 2px after a few seconds. Possible to fix?

image

  • It appears that field type filtering is being omitted when in SQL mode. Is this intentional?

  • It appears that field type tokens and tooltips are missing from the field list in SQL mode. Is this intentional?

  • Interacting with one or more "Remove field from table" buttons in the field list doesn't appear to alter the SQL query. For example, if the user's query selects all fields (via SELECT *), removing a field from the table keeps the wildcard (*) intact, which I found somewhat confusing. As a user, I'd expect the query to break out the wildcard into only the selected fields (i.e. all but the ones the user has chose to remove from the table). Is the current behavior intentional? Also worth noting with this currently implemented behavior is that refreshing doesn't restore all fields to the table, even though the wildcard is still present in the SELECT clause.

@kertal
Copy link
Member

kertal commented Jul 26, 2022

  • It appears that field type filtering is being omitted when in SQL mode. Is this intentional?
  • It appears that field type tokens and tooltips are missing from the field list in SQL mode. Is this intentional?

good point, Michael, yes, this is something to discuss. In SQL you can do the following:

SELECT geoip.continent_name as "taxless_total_price", taxless_total_price as "some other name"

In this case taxless_total_price would have the wrong type, and taxless_total_price would have an unknown type.
Secondly if you add aggregations, these would have unknown types. So the information about the types could be unreliable / or be primarily unknown ... if we are fine with this, it's simple to enable filtering and tokens, but it needs to be considered.

  • Interacting with one or more "Remove field from table" buttons in the field list doesn't appear to alter the SQL query. For example, if the user's query selects all fields (via SELECT *), removing a field from the table keeps the wildcard (*) intact, which I found somewhat confusing.

This is simply a limitation how Discover currently works , there is the data layer and the presentation layer, when you're adding/removing fields you're changing the presentation of your results and not the query. But it's not written in stone of course.

@stratoula
Copy link
Contributor Author

Thanx @MichaelMarcialis, I really appreciate it! I addressed everything except from the 2 issues that have to do with the resizer. I added them to the followup issue #136950. This has something to do with monaco height update so I need some time to investigate it and find alternatives.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
aiops 354 355 +1
apm 1304 1305 +1
canvas 1140 1141 +1
cloudSecurityPosture 273 274 +1
controls 172 173 +1
dashboard 422 423 +1
dashboardEnhanced 93 94 +1
data 516 518 +2
dataViewManagement 175 176 +1
dataVisualizer 376 377 +1
discover 597 601 +4
discoverEnhanced 71 72 +1
fleet 748 749 +1
graph 216 217 +1
infra 951 952 +1
inputControlVis 106 107 +1
lens 934 935 +1
lists 306 307 +1
maps 872 873 +1
ml 1627 1628 +1
monitoring 505 506 +1
observability 474 475 +1
osquery 323 324 +1
securitySolution 3238 3239 +1
stackAlerts 137 138 +1
synthetics 917 918 +1
timelines 252 253 +1
transform 320 321 +1
triggersActionsUi 575 576 +1
unifiedSearch 199 220 +21
upgradeAssistant 197 198 +1
visTypeTimelion 106 107 +1
visTypeVega 229 230 +1
visualizations 363 364 +1
total +58

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/es-query 159 168 +9
data 2421 2424 +3
discover 66 68 +2
unifiedSearch 80 84 +4
total +18

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
aiops 467.0KB 467.0KB +57.0B
cloudSecurityPosture 220.7KB 220.7KB +57.0B
controls 428.3KB 428.4KB +57.0B
dashboard 409.1KB 409.9KB +768.0B
dataViewManagement 143.7KB 143.7KB +57.0B
dataVisualizer 561.5KB 561.6KB +57.0B
discover 494.0KB 500.6KB +6.6KB
discoverEnhanced 42.6KB 43.4KB +768.0B
infra 1018.0KB 1018.0KB +57.0B
lens 1.2MB 1.2MB +768.0B
ml 3.3MB 3.3MB +57.0B
transform 385.6KB 385.7KB +57.0B
unifiedSearch 178.4KB 228.0KB +49.7KB
visTypeTimelion 107.7KB 107.8KB +57.0B
visTypeVega 1.7MB 1.7MB +57.0B
visualizations 237.1KB 237.2KB +85.0B
total +59.1KB

Canvas Sharable Runtime

The Canvas "shareable runtime" is an bundle produced to enable running Canvas workpads outside of Kibana. This bundle is included in third-party webpages that embed canvas and therefor should be as slim as possible.

id before after diff
module count 4935 4937 +2

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
unifiedSearch 13 16 +3

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 426.9KB 428.2KB +1.3KB
discover 28.9KB 29.1KB +192.0B
maps 81.1KB 81.1KB +4.0B
navigation 9.6KB 9.6KB +56.0B
reporting 42.4KB 42.5KB +97.0B
securitySolution 253.1KB 253.2KB +57.0B
timelines 258.6KB 258.7KB +57.0B
unifiedSearch 44.7KB 47.8KB +3.1KB
total +4.9KB

Saved Objects .kibana field count

Every field in each saved object type adds overhead to Elasticsearch. Kibana needs to keep the total field count below Elasticsearch's default limit of 1000 fields. Only specify field mappings for the fields you wish to search on or query. See https://www.elastic.co/guide/en/kibana/master/development-plugin-saved-objects.html#_mappings

id before after diff
search 14 15 +1
Unknown metric groups

API count

id before after diff
@kbn/es-query 213 222 +9
data 3094 3097 +3
discover 82 84 +2
unifiedSearch 84 98 +14
total +28

async chunk count

id before after diff
unifiedSearch 11 14 +3

ESLint disabled line counts

id before after diff
discover 36 37 +1
unifiedSearch 16 19 +3
total +4

Total ESLint disabled count

id before after diff
discover 38 39 +1
unifiedSearch 16 19 +3
total +4

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@stratoula stratoula merged commit a296e4c into main Jul 26, 2022
@stratoula stratoula deleted the unified-search-text-based-lang branch July 26, 2022 07:51
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 26, 2022
@@ -45,14 +45,15 @@ export const createTileMapFn = (): TileMapExpressionFunctionDefinition => ({
},
},
async fn(input, args) {
const query = input.query as Query;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can we be sure that what's passed in here is not an AggregateQuery?

}

const savedSearch = embeddable.getSavedSearch();
const query = savedSearch.searchSource.getField('query');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not possible that searchsource contains the query of type sql but it gets dropped (ignored) in the actual embeddable?

return false;
}

const savedSearch = embeddable.getSavedSearch();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we be sure here that embeddable contains a saved search ?

@@ -51,15 +51,15 @@ export const useEditorUpdates = (
uiState: vis.uiState,
timeRange: timefilter.getTime(),
filters: filterManager.getFilters(),
query: queryString.getQuery(),
query: queryString.getQuery() as Query,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we be sure this is not an AggregateQuery ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Discover Discover Application Feature:Unified search Unified search related tasks release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. Team:Visualizations Visualization editors, elastic-charts and infrastructure ui-copy Review of UI copy with docs team is recommended v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.