Skip to content

Commit 6f74d7f

Browse files
Fix source command detection if we have a field expression before source (#10598)
* Fix source command detection if we have a field expression before source Signed-off-by: Suchit Sahoo <suchsah@amazon.com> * Changeset file for PR #10598 created/updated --------- Signed-off-by: Suchit Sahoo <suchsah@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent 58f770e commit 6f74d7f

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

changelogs/fragments/10598.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fix:
2+
- Source command detection if we have a field expression before source ([#10598](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10598))

src/plugins/explore/public/application/utils/languages/ppl/get_query_string_with_source/get_query_with_source.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,14 @@ describe('getQueryWithSource', () => {
221221
const result = getQueryWithSource(query);
222222
expect(result).toEqual(query);
223223
});
224+
225+
it('should handle if we have a field Expression infront of SOURCE command', () => {
226+
const query: Query = {
227+
query: 'unique_category = "Configuration" source = `data_logs_small_time_1*`',
228+
dataset: { title: 'test-dataset', id: '123', type: 'INDEX_PATTERN' },
229+
language: 'ppl',
230+
};
231+
const result = getQueryWithSource(query);
232+
expect(result).toEqual(query);
233+
});
224234
});

src/plugins/explore/public/application/utils/languages/ppl/get_query_string_with_source/get_query_with_source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { QueryWithQueryAsString } from '../../types';
1212
export const getQueryWithSource = (query: Query): QueryWithQueryAsString => {
1313
const queryString = typeof query.query === 'string' ? query.query : '';
1414
const lowerCaseQuery = queryString.toLowerCase();
15-
const hasSource = /^\s*(search\s+)?source\s*=/.test(lowerCaseQuery);
15+
const hasSource = /^[^|]*\bsource\s*=/.test(lowerCaseQuery);
1616
const hasDescribe = /^\s*describe\s+/.test(lowerCaseQuery);
1717
const hasShow = /^\s*show\s+/.test(lowerCaseQuery);
1818

0 commit comments

Comments
 (0)