Skip to content

Commit

Permalink
Change the implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Jul 4, 2024
1 parent 10d3818 commit c8c27c6
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { getIndexPatternFromESQLQuery } from '@kbn/esql-utils';

const STRING_DELIMITER_TOKENS = ['`', "'", '"'];
const ESCAPE_TOKEN = '\\\\';
Expand Down Expand Up @@ -237,16 +236,9 @@ export function correctCommonEsqlMistakes(query: string): {
let formattedCommand = command;
switch (name) {
case 'FROM': {
// gets the index pattern from the FROM command using AST parsing
const indexPattern = getIndexPatternFromESQLQuery(formattedCommand);
let indexPatternWithFixedQuotes = replaceSingleQuotesWithDoubleQuotes(indexPattern);
// the parser removes the backticks from the indices (but not the double quotes), so we need a different approach if
// the indices are wrapped in backticks from the LLM
if (formattedCommand.includes('`')) {
const indices = indexPattern.split(',');
indexPatternWithFixedQuotes = indices?.map((i) => `"${i}"`).join(',');
}
formattedCommand = `FROM ${indexPatternWithFixedQuotes}`;
formattedCommand = split(formattedCommand, ',')
.map((singlePattern) => singlePattern.replaceAll(/`/g, '"').replaceAll(/'/g, '"'))
.join(',');
break;
}
case 'WHERE':
Expand Down

0 comments on commit c8c27c6

Please sign in to comment.