Skip to content

Commit

Permalink
[Discover] add sample queries for PPL (#8752)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 authored Oct 30, 2024
1 parent e7533a9 commit 7471a65
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,33 +260,37 @@ export const DiscoverNoResults = ({ queryString, query, savedQuery, timeFieldNam

return (
<I18nProvider>
<EuiEmptyPrompt
iconType="editorCodeBlock"
iconColor="default"
data-test-subj="discoverNoResults"
title={
<EuiText size="s">
<h2>
{i18n.translate('discover.emptyPrompt.title', {
defaultMessage: 'No Results',
})}
</h2>
</EuiText>
}
body={
<EuiText size="s" data-test-subj="discoverNoResultsTimefilter">
<p>
{i18n.translate('discover.emptyPrompt.body', {
defaultMessage:
'Try selecting a different data source, expanding your time range or modifying the query & filters.',
})}
</p>
</EuiText>
}
/>
<div className="discoverNoResults-sampleContainer">
<EuiTabbedContent tabs={tabs} />
</div>
<>
<EuiEmptyPrompt
iconType="editorCodeBlock"
iconColor="default"
data-test-subj="discoverNoResults"
title={
<EuiText size="s">
<h2>
{i18n.translate('discover.emptyPrompt.title', {
defaultMessage: 'No Results',
})}
</h2>
</EuiText>
}
body={
<EuiText size="s" data-test-subj="discoverNoResultsTimefilter">
<p>
{i18n.translate('discover.emptyPrompt.body', {
defaultMessage:
'Try selecting a different data source, expanding your time range or modifying the query & filters.',
})}
</p>
</EuiText>
}
/>
{tabs.length && (
<div className="discoverNoResults-sampleContainer">
<EuiTabbedContent tabs={tabs} />
</div>
)}
</>
</I18nProvider>
);
};
88 changes: 56 additions & 32 deletions src/plugins/query_enhancements/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,45 @@ export class QueryEnhancementsPlugin
editor: createEditor(SingleLineInput, null, pplControls, DefaultInput),
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'data-explorer'],
sampleQueries: [
{
title: i18n.translate('queryEnhancements.sampleQuery.titleContainsWind', {
defaultMessage: 'The title field contains the word wind.',
}),
query: `SOURCE = your_table | WHERE LIKE(title, '%wind%')`,
},
{
title: i18n.translate('queryEnhancements.sampleQuery.titleContainsWindOrWindy', {
defaultMessage: 'The title field contains the word wind or the word windy.',
}),
query: `SOURCE = your_table | WHERE LIKE(title, '%wind%') OR LIKE(title, '%windy%')`,
},
{
title: i18n.translate('queryEnhancements.sampleQuery.titleContainsPhraseWindRises', {
defaultMessage: 'The title field contains the phrase wind rises.',
}),
query: `SOURCE = your_table | WHERE LIKE(title, '%wind rises%')`,
},
{
title: i18n.translate('queryEnhancements.sampleQuery.titleExactMatchWindRises', {
defaultMessage: 'The title.keyword field exactly matches The wind rises.',
}),
query: `SOURCE = your_table | WHERE title = 'The wind rises'`,
},
{
title: i18n.translate('queryEnhancements.sampleQuery.titleFieldsContainWind', {
defaultMessage:
'Any field that starts with title (for example, title and title.keyword) contains the word wind',
}),
query: `SOURCE = your_table | WHERE LIKE(title, '%wind%') OR title = 'wind'`,
},
{
title: i18n.translate('queryEnhancements.sampleQuery.descriptionFieldExists', {
defaultMessage: 'Documents in which the field description exists.',
}),
query: `SOURCE = your_table | WHERE ISNOTNULL(description) AND description != '';`,
},
],
};
queryString.getLanguageService().registerLanguage(pplLanguageConfig);

Expand Down Expand Up @@ -99,55 +138,40 @@ export class QueryEnhancementsPlugin
hideDatePicker: true,
sampleQueries: [
{
title: i18n.translate('queryEnhancements.sqlLanguage.sampleQuery.titleContainsWind', {
title: i18n.translate('queryEnhancements.sampleQuery.titleContainsWind', {
defaultMessage: 'The title field contains the word wind.',
}),
query: `SELECT * FROM your_table WHERE title LIKE '%wind%'`,
},
{
title: i18n.translate(
'queryEnhancements.sqlLanguage.sampleQuery.titleContainsWindOrWindy',
{
defaultMessage: 'The title field contains the word wind or the word windy.',
}
),
title: i18n.translate('queryEnhancements.sampleQuery.titleContainsWindOrWindy', {
defaultMessage: 'The title field contains the word wind or the word windy.',
}),
query: `SELECT * FROM your_table WHERE title LIKE '%wind%' OR title LIKE '%windy%';`,
},
{
title: i18n.translate(
'queryEnhancements.sqlLanguage.sampleQuery.titleContainsPhraseWindRises',
{
defaultMessage: 'The title field contains the phrase wind rises.',
}
),
title: i18n.translate('queryEnhancements.sampleQuery.titleContainsPhraseWindRises', {
defaultMessage: 'The title field contains the phrase wind rises.',
}),
query: `SELECT * FROM your_table WHERE title LIKE '%wind rises%'`,
},
{
title: i18n.translate(
'queryEnhancements.sqlLanguage.sampleQuery.titleExactMatchWindRises',
{
defaultMessage: 'The title.keyword field exactly matches The wind rises.',
}
),
title: i18n.translate('queryEnhancements.sampleQuery.titleExactMatchWindRises', {
defaultMessage: 'The title.keyword field exactly matches The wind rises.',
}),
query: `SELECT * FROM your_table WHERE title = 'The wind rises'`,
},
{
title: i18n.translate(
'queryEnhancements.sqlLanguage.sampleQuery.titleFieldsContainWind',
{
defaultMessage:
'Any field that starts with title (for example, title and title.keyword) contains the word wind',
}
),
title: i18n.translate('queryEnhancements.sampleQuery.titleFieldsContainWind', {
defaultMessage:
'Any field that starts with title (for example, title and title.keyword) contains the word wind',
}),
query: `SELECT * FROM your_table WHERE title LIKE '%wind%' OR title = 'wind'`,
},
{
title: i18n.translate(
'queryEnhancements.sqlLanguage.sampleQuery.descriptionFieldExists',
{
defaultMessage: 'Documents in which the field description exists.',
}
),
title: i18n.translate('queryEnhancements.sampleQuery.descriptionFieldExists', {
defaultMessage: 'Documents in which the field description exists.',
}),
query: `SELECT * FROM your_table WHERE description IS NOT NULL AND description != '';`,
},
],
Expand Down

0 comments on commit 7471a65

Please sign in to comment.