Skip to content

Commit

Permalink
Merge branch 'main' into eui/v95.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Jul 31, 2024
2 parents 7019f07 + bdc9a6c commit a64cb7d
Show file tree
Hide file tree
Showing 25 changed files with 2,557 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@
"svgo": "^2.8.0",
"table": "^6.8.1",
"tape": "^5.0.1",
"terser": "^5.31.2",
"terser": "^5.31.3",
"terser-webpack-plugin": "^4.2.3",
"tough-cookie": "^4.1.4",
"tree-kill": "^1.2.2",
Expand Down
369 changes: 369 additions & 0 deletions packages/kbn-esql-ast/src/__tests__/ast_parser.commands.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,369 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { getAstAndSyntaxErrors as parse } from '../ast_parser';

describe('commands', () => {
describe('correctly formatted, basic usage', () => {
it('SHOW', () => {
const query = 'SHOW info';
const { ast } = parse(query);

expect(ast).toMatchObject([
{
type: 'command',
name: 'show',
args: [
{
type: 'function',
name: 'info',
},
],
},
]);
});

it('META', () => {
const query = 'META functions';
const { ast } = parse(query);

expect(ast).toMatchObject([
{
type: 'command',
name: 'meta',
args: [
{
type: 'function',
name: 'functions',
},
],
},
]);
});

it('FROM', () => {
const query = 'FROM index';
const { ast } = parse(query);

expect(ast).toMatchObject([
{
type: 'command',
name: 'from',
args: [
{
type: 'source',
name: 'index',
},
],
},
]);
});

it('ROW', () => {
const query = 'ROW 1';
const { ast } = parse(query);

expect(ast).toMatchObject([
{
type: 'command',
name: 'row',
args: [
{
type: 'literal',
value: 1,
},
],
},
]);
});

it('EVAL', () => {
const query = 'FROM index | EVAL 1';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'eval',
args: [
{
type: 'literal',
value: 1,
},
],
},
]);
});

it('STATS', () => {
const query = 'FROM index | STATS 1';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'stats',
args: [
{
type: 'literal',
value: 1,
},
],
},
]);
});

it('LIMIT', () => {
const query = 'FROM index | LIMIT 1';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'limit',
args: [
{
type: 'literal',
value: 1,
},
],
},
]);
});

it('KEEP', () => {
const query = 'FROM index | KEEP abc';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'keep',
args: [
{
type: 'column',
name: 'abc',
},
],
},
]);
});

it('SORT', () => {
const query = 'FROM index | SORT 1';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'sort',
args: [
{
type: 'literal',
value: 1,
},
],
},
]);
});

it('WHERE', () => {
const query = 'FROM index | WHERE 1';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'where',
args: [
{
type: 'literal',
value: 1,
},
],
},
]);
});

it('DROP', () => {
const query = 'FROM index | DROP abc';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'drop',
args: [
{
type: 'column',
name: 'abc',
},
],
},
]);
});

it('RENAME', () => {
const query = 'FROM index | RENAME a AS b, c AS d';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'rename',
args: [
{
type: 'option',
name: 'as',
args: [
{
type: 'column',
name: 'a',
},
{
type: 'column',
name: 'b',
},
],
},
{
type: 'option',
name: 'as',
args: [
{
type: 'column',
name: 'c',
},
{
type: 'column',
name: 'd',
},
],
},
],
},
]);
});

it('DISSECT', () => {
const query = 'FROM index | DISSECT a "b" APPEND_SEPARATOR="c"';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'dissect',
args: [
{
type: 'column',
name: 'a',
},
{
type: 'literal',
value: '"b"',
},
{
type: 'option',
name: 'append_separator',
args: [
{
type: 'literal',
value: '"c"',
},
],
},
],
},
]);
});

it('GROK', () => {
const query = 'FROM index | GROK a "b"';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'grok',
args: [
{
type: 'column',
name: 'a',
},
{
type: 'literal',
value: '"b"',
},
],
},
]);
});

it('ENRICH', () => {
const query = 'FROM index | ENRICH a ON b WITH c, d';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'enrich',
args: [
{
type: 'source',
name: 'a',
},
{
type: 'option',
name: 'on',
args: [
{
type: 'column',
name: 'b',
},
],
},
{
type: 'option',
name: 'with',
},
],
},
]);
});

it('MV_EXPAND', () => {
const query = 'FROM index | MV_EXPAND a ';
const { ast } = parse(query);

expect(ast).toMatchObject([
{},
{
type: 'command',
name: 'mv_expand',
args: [
{
type: 'column',
name: 'a',
},
],
},
]);
});
});
});
Loading

0 comments on commit a64cb7d

Please sign in to comment.