Skip to content

Commit

Permalink
use FROM command to use METRICS fields
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimkibana committed Jun 11, 2024
1 parent 1b05483 commit bc03874
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
* Side Public License, v 1.
*/

import type { ESQLAst, ESQLAstItem, ESQLMessage, ESQLSingleAstItem } from '@kbn/esql-ast';
import type {
ESQLAst,
ESQLAstItem,
ESQLAstMetricsCommand,
ESQLMessage,
ESQLSingleAstItem,
} from '@kbn/esql-ast';
import { FunctionDefinition } from '../definitions/types';
import { getAllArrayTypes, getAllArrayValues } from '../shared/helpers';
import { getMessageFromId } from './errors';
import type { ESQLPolicy, ReferenceMaps } from './types';

export function buildQueryForFieldsFromSource(queryString: string, ast: ESQLAst) {
const firstCommand = ast[0];
if (firstCommand == null) {
return '';
if (!firstCommand) return '';
if (firstCommand.name === 'metrics') {
const metrics = firstCommand as ESQLAstMetricsCommand;
return `FROM ${metrics.sources.map((source) => source.name).join(', ')}`;
}
return queryString.substring(0, firstCommand.location.max + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ function validateFunctionColumnArg(
const messages: ESQLMessage[] = [];
if (isColumnItem(actualArg)) {
if (actualArg.name) {
const { hit: columnCheck, nameHit } = columnExists(actualArg, references);
if (!columnCheck) {
const { hit, nameHit } = columnExists(actualArg, references);
if (!hit) {
if (argDef.constantOnly) {
messages.push(
getMessageFromId({
Expand Down Expand Up @@ -1150,13 +1150,14 @@ async function validateAst(
messages.push(...validateUnsupportedTypeFields(availableFields));

for (const command of ast) {
const commandMessages = validateCommand(command, {
const references: ReferenceMaps = {
sources,
fields: availableFields,
policies: availablePolicies,
variables,
query: queryString,
});
};
const commandMessages = validateCommand(command, references);
messages.push(...commandMessages);
}

Expand Down

0 comments on commit bc03874

Please sign in to comment.