mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-25 15:47:23 -04:00
* Enforce an invariant in our dependency checker so that logical plans never have duplicate output attribute names or ids. * Fix ROW to not produce columns with duplicate names. * Fix ResolveUnionTypes to not create multiple synthetic field attributes for the same union type. * Add tests for commands using the same column name more than once. * Update docs w.r.t. how commands behave if they are used with duplicate column names.
78 lines
2.1 KiB
Text
78 lines
2.1 KiB
Text
[discrete]
|
|
[[esql-eval]]
|
|
=== `EVAL`
|
|
|
|
The `EVAL` processing command enables you to append new columns with calculated
|
|
values.
|
|
|
|
**Syntax**
|
|
|
|
[source,esql]
|
|
----
|
|
EVAL [column1 =] value1[, ..., [columnN =] valueN]
|
|
----
|
|
|
|
*Parameters*
|
|
|
|
`columnX`::
|
|
The column name.
|
|
If a column with the same name already exists, the existing column is dropped.
|
|
If a column name is used more than once, only the rightmost duplicate creates a column.
|
|
|
|
`valueX`::
|
|
The value for the column. Can be a literal, an expression, or a
|
|
<<esql-functions,function>>. Can use columns defined left of this one.
|
|
|
|
*Description*
|
|
|
|
The `EVAL` processing command enables you to append new columns with calculated
|
|
values. `EVAL` supports various functions for calculating values. Refer to
|
|
<<esql-functions,Functions>> for more information.
|
|
|
|
*Examples*
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/eval.csv-spec[tag=eval]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/eval.csv-spec[tag=eval-result]
|
|
|===
|
|
|
|
If the specified column already exists, the existing column will be dropped, and
|
|
the new column will be appended to the table:
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/eval.csv-spec[tag=evalReplace]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/eval.csv-spec[tag=evalReplace-result]
|
|
|===
|
|
|
|
Specifying the output column name is optional. If not specified, the new column
|
|
name is equal to the expression. The following query adds a column named
|
|
`height*3.281`:
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumn]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumn-result]
|
|
|===
|
|
|
|
Because this name contains special characters, <<esql-identifiers,it needs to be
|
|
quoted>> with backticks (+{backtick}+) when using it in subsequent commands:
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumnStats]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumnStats-result]
|
|
|===
|