Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ES|QL language support #3858

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@
"title": "Erlang",
"owner": "Golmote"
},
"esql": {
"title": "ES|QL",
"owner": "vadimkibana"
},
"excel-formula": {
"title": "Excel Formula",
"alias": ["xlsx", "xls"],
Expand Down
271 changes: 271 additions & 0 deletions components/prism-esql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
var commands = [
'DISSECT',
'DROP',
'ENRICH',
'EVAL',
'EXPLAIN',
'FROM',
'FULL JOIN',
'GROK',
'INLINESTATS',
'JOIN',
'KEEP',
'LEFT JOIN',
'LIMIT',
'LOOKUP JOIN',
'METRICS',
'MV_EXPAND',
'RENAME',
'RIGHT JOIN',
'ROW',
'SHOW',
'SORT',
'STATS',
'WHERE',
];

var functions = [
'ABS',
'ACOS',
'ASIN',
'ATAN',
'ATAN2',
'AVG',
'BIT_LENGTH',
'BUCKET',
'BYTE_LENGTH',
'CASE',
'CATEGORIZE',
'CBRT',
'CEIL',
'CIDR_MATCH',
'COALESCE',
'CONCAT',
'COS',
'COSH',
'COUNT_DISTINCT',
'COUNT',
'DATE_DIFF',
'DATE_EXTRACT',
'DATE_FORMAT',
'DATE_PARSE',
'DATE_TRUNC',
'E',
'ENDS_WITH',
'EXP',
'FLOOR',
'FROM_BASE64',
'GREATEST',
'HASH',
'HYPOT',
'IP_PREFIX',
'LEAST',
'LEFT',
'LENGTH',
'LOCATE',
'LOG',
'LOG10',
'LTRIM',
'MATCH',
'MAX',
'MEDIAN_ABSOLUTE_DEVIATION',
'MEDIAN',
'MIN',
'MV_APPEND',
'MV_AVG',
'MV_CONCAT',
'MV_COUNT',
'MV_DEDUPE',
'MV_FIRST',
'MV_LAST',
'MV_MAX',
'MV_MEDIAN_ABSOLUTE_DEVIATION',
'MV_MEDIAN',
'MV_MIN',
'MV_PERCENTILE',
'MV_PSERIES_WEIGHTED_SUM',
'MV_SLICE',
'MV_SORT',
'MV_SUM',
'MV_ZIP',
'NOW',
'PERCENTILE',
'PI',
'POW',
'QSTR',
'REPEAT',
'REPLACE',
'REVERSE',
'RIGHT',
'ROUND',
'RTRIM',
'SIGNUM',
'SIN',
'SINH',
'SPACE',
'SPLIT',
'SQRT',
'ST_CENTROID_AGG',
'ST_CONTAINS',
'ST_DISJOINT',
'ST_DISTANCE',
'ST_ENVELOPE',
'ST_EXTENT_AGG',
'ST_INTERSECTS',
'ST_WITHIN',
'ST_X',
'ST_XMAX',
'ST_XMIN',
'ST_Y',
'ST_YMAX',
'ST_YMIN',
'STARTS_WITH',
'STD_DEV',
'SUBSTRING',
'SUM',
'TAN',
'TANH',
'TAU',
'TO_BASE64',
'TO_BOOLEAN',
'TO_CARTESIANPOINT',
'TO_CARTESIANSHAPE',
'TO_DATE_NANOS',
'TO_DATEPERIOD',
'TO_DATETIME',
'TO_DEGREES',
'TO_DOUBLE',
'TO_GEOPOINT',
'TO_GEOSHAPE',
'TO_INTEGER',
'TO_IP',
'TO_LONG',
'TO_LOWER',
'TO_RADIANS',
'TO_STRING',
'TO_TIMEDURATION',
'TO_UNSIGNED_LONG',
'TO_UPPER',
'TO_VERSION',
'TOP',
'TRIM',
'VALUES',
'WEIGHTED_AVG',
];

var keywords = [
'BY',
'ASC',
'DESC',
'FIRST',
'LAST',
'ON',
'WITH',
'METADATA',
'NULLS',
];

var namedBinaryOperators = [
'AND',
'OR',
'IS',
'IN',
'AS',
'LIKE',
'RLIKE',
'RLIKE',
'WHERE',
];

Prism.languages.esql = {
// Single line comment: // comment
comment: {
pattern: /\/\/.*/,
greedy: true
},

// Slash-star multiline comments: /* comment */
'multiline-comment': {
pattern: /\/\*[\s\S]*?\*\//,
greedy: true,
alias: [
'comment',
]
},

// Triple quoted strings: """string"""
'triple-quoted-string': {
pattern: /"""(?:\\.|[^\\"])*"""/,
greedy: true,
alias: [
'string',
]
},

// Single quoted strings: "string"
'string': {
pattern: /"(?:\\.|[^\\"])*"/,
greedy: true
},

// ES|LQ params: "?paramName", "?1", "?"
variable: /\?\w{1,999}/,

// Command names
command: {
pattern: new RegExp('\\b(?:' + commands.join('|') + ')\\b', 'i'),
alias: [
'keyword',
],
},

// List of well known keywords
keyword: {
pattern: new RegExp('\\b(?:' + keywords.join('|') + ')\\b', 'i'),
},


'named-binary-operator': {
pattern: new RegExp('\\b(?:' + namedBinaryOperators.join('|') + ')\\b', 'i'),
alias: [
'keyword',
],
},

// Highlight list of known functions
function: {
pattern: new RegExp('\\b(?:' + functions.join('|') + ')\\b', 'i'),
},

boolean: /\b(?:false|true)\b/i,

// Floating point numbers (ES|QL "decimals")
float: {
pattern: /\b(?:\d{1,50}\.{1}\d{0,50}|\.\d{1,50})(?:[eE][+-]?\d+)?\b/,
alias: [
'number'
],
},

// Integer numbers
integer: {
pattern: /\b\d+\b/,
alias: [
'number'
],
},

// Cast expressions
cast: {
pattern: /::\s*\w+\b/,
alias: [
'operator',
],
},

// General operators
operator: /-|\+|\*|\||\/|%|==|=|<=|>=|<|>/,

// Mark "|" and "," and some other symbols as punctuation
punctuation: /\||,|\(|\)|\[|\]|\{|\}/,
};
1 change: 1 addition & 0 deletions components/prism-esql.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions examples/prism-esql.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2>Full example</h2>
<pre><code>// This is a comment
FROM logs-endpoint METADATA test
| ROW a=[1,2,3], b="b", j=["a","b"]
/* This is a multiline
commnet */
| MV_EXPAND a
| WHERE process.name == "curl.exe" AND ?asdf == 123
| STATS bytes = (SUM(destination.bytes, true) BY destination.?asdf.asdf)::INTEGER
| EVAL kb = bytes / 1024 * -1.23e12 + ?e
| SORT kb DESC
| LIMIT 10
| KEEP kb, destination.address
| GROK a """%{TIMESTAMP_ISO8601:date} %{IP:ip} %{EMAILADDRESS:email} %{NUMBER:num}"""
| KEEP date, ip, email, num</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"ejs": "EJS",
"etlua": "Embedded Lua templating",
"erb": "ERB",
"esql": "ES|QL",
"excel-formula": "Excel Formula",
"xlsx": "Excel Formula",
"xls": "Excel Formula",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/languages/esql/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
TRUE FALSE
true false

----------------------------------------------------

[
["boolean", "TRUE"], ["boolean", "FALSE"],
["boolean", "true"], ["boolean", "false"]
]

----------------------------------------------------

Checks for booleans.
27 changes: 27 additions & 0 deletions tests/languages/esql/commands_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM
ROW
STATS
LIMIT
WHERE
KEEP
DROP
GROK
EXPLAIN

----------------------------------------------------

[
["command", "FROM"],
["command", "ROW"],
["command", "STATS"],
["command", "LIMIT"],
["command", "WHERE"],
["command", "KEEP"],
["command", "DROP"],
["command", "GROK"],
["command", "EXPLAIN"]
]

----------------------------------------------------

Checks for comments.
Loading