forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds `LEAST` and `GREATEST` functions to find the min or max of the values in many colunms.
- Loading branch information
Showing
23 changed files
with
1,402 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[[esql-greatest]] | ||
=== `GREATEST` | ||
|
||
Returns the maximum value from many columns. | ||
|
||
[source.merge.styled,esql] | ||
---- | ||
include::{esql-specs}/math.csv-spec[tag=greatest] | ||
---- | ||
[%header.monospaced.styled,format=dsv,separator=|] | ||
|=== | ||
include::{esql-specs}/math.csv-spec[tag=greatest-result] | ||
|=== | ||
|
||
NOTE: When run on `keyword` or `text` fields, this'll return the last string | ||
in alphabetical order. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[[esql-least]] | ||
=== `LEAST` | ||
|
||
Returns the minimum value from many columns. | ||
|
||
[source.merge.styled,esql] | ||
---- | ||
include::{esql-specs}/math.csv-spec[tag=least] | ||
---- | ||
[%header.monospaced.styled,format=dsv,separator=|] | ||
|=== | ||
include::{esql-specs}/math.csv-spec[tag=least-result] | ||
|=== | ||
|
||
NOTE: When run on `keyword` or `text` fields, this'll return the first string | ||
in alphabetical order. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...g/elasticsearch/xpack/esql/expression/function/scalar/math/GreatestBytesRefEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// 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; you may not use this file except in compliance with the Elastic License | ||
// 2.0. | ||
package org.elasticsearch.xpack.esql.expression.function.scalar.math; | ||
|
||
import java.lang.Override; | ||
import java.lang.String; | ||
import java.util.Arrays; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.compute.data.Block; | ||
import org.elasticsearch.compute.data.BytesRefBlock; | ||
import org.elasticsearch.compute.data.BytesRefVector; | ||
import org.elasticsearch.compute.data.Page; | ||
import org.elasticsearch.compute.operator.EvalOperator; | ||
|
||
/** | ||
* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Greatest}. | ||
* This class is generated. Do not edit it. | ||
*/ | ||
public final class GreatestBytesRefEvaluator implements EvalOperator.ExpressionEvaluator { | ||
private final EvalOperator.ExpressionEvaluator[] values; | ||
|
||
public GreatestBytesRefEvaluator(EvalOperator.ExpressionEvaluator[] values) { | ||
this.values = values; | ||
} | ||
|
||
@Override | ||
public Block eval(Page page) { | ||
BytesRefBlock[] valuesBlocks = new BytesRefBlock[values.length]; | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
Block block = values[i].eval(page); | ||
if (block.areAllValuesNull()) { | ||
return Block.constantNullBlock(page.getPositionCount()); | ||
} | ||
valuesBlocks[i] = (BytesRefBlock) block; | ||
} | ||
BytesRefVector[] valuesVectors = new BytesRefVector[values.length]; | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
valuesVectors[i] = valuesBlocks[i].asVector(); | ||
if (valuesVectors[i] == null) { | ||
return eval(page.getPositionCount(), valuesBlocks); | ||
} | ||
} | ||
return eval(page.getPositionCount(), valuesVectors).asBlock(); | ||
} | ||
|
||
public BytesRefBlock eval(int positionCount, BytesRefBlock[] valuesBlocks) { | ||
BytesRefBlock.Builder result = BytesRefBlock.newBlockBuilder(positionCount); | ||
BytesRef[] valuesValues = new BytesRef[values.length]; | ||
BytesRef[] valuesScratch = new BytesRef[values.length]; | ||
for (int i = 0; i < values.length; i++) { | ||
valuesScratch[i] = new BytesRef(); | ||
} | ||
position: for (int p = 0; p < positionCount; p++) { | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
if (valuesBlocks[i].isNull(p) || valuesBlocks[i].getValueCount(p) != 1) { | ||
result.appendNull(); | ||
continue position; | ||
} | ||
} | ||
// unpack valuesBlocks into valuesValues | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
int o = valuesBlocks[i].getFirstValueIndex(p); | ||
valuesValues[i] = valuesBlocks[i].getBytesRef(o, valuesScratch[i]); | ||
} | ||
result.appendBytesRef(Greatest.process(valuesValues)); | ||
} | ||
return result.build(); | ||
} | ||
|
||
public BytesRefVector eval(int positionCount, BytesRefVector[] valuesVectors) { | ||
BytesRefVector.Builder result = BytesRefVector.newVectorBuilder(positionCount); | ||
BytesRef[] valuesValues = new BytesRef[values.length]; | ||
BytesRef[] valuesScratch = new BytesRef[values.length]; | ||
for (int i = 0; i < values.length; i++) { | ||
valuesScratch[i] = new BytesRef(); | ||
} | ||
position: for (int p = 0; p < positionCount; p++) { | ||
// unpack valuesVectors into valuesValues | ||
for (int i = 0; i < valuesVectors.length; i++) { | ||
valuesValues[i] = valuesVectors[i].getBytesRef(p, valuesScratch[i]); | ||
} | ||
result.appendBytesRef(Greatest.process(valuesValues)); | ||
} | ||
return result.build(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GreatestBytesRefEvaluator[" + "values=" + Arrays.toString(values) + "]"; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...org/elasticsearch/xpack/esql/expression/function/scalar/math/GreatestDoubleEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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; you may not use this file except in compliance with the Elastic License | ||
// 2.0. | ||
package org.elasticsearch.xpack.esql.expression.function.scalar.math; | ||
|
||
import java.lang.Override; | ||
import java.lang.String; | ||
import java.util.Arrays; | ||
import org.elasticsearch.compute.data.Block; | ||
import org.elasticsearch.compute.data.DoubleBlock; | ||
import org.elasticsearch.compute.data.DoubleVector; | ||
import org.elasticsearch.compute.data.Page; | ||
import org.elasticsearch.compute.operator.EvalOperator; | ||
|
||
/** | ||
* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Greatest}. | ||
* This class is generated. Do not edit it. | ||
*/ | ||
public final class GreatestDoubleEvaluator implements EvalOperator.ExpressionEvaluator { | ||
private final EvalOperator.ExpressionEvaluator[] values; | ||
|
||
public GreatestDoubleEvaluator(EvalOperator.ExpressionEvaluator[] values) { | ||
this.values = values; | ||
} | ||
|
||
@Override | ||
public Block eval(Page page) { | ||
DoubleBlock[] valuesBlocks = new DoubleBlock[values.length]; | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
Block block = values[i].eval(page); | ||
if (block.areAllValuesNull()) { | ||
return Block.constantNullBlock(page.getPositionCount()); | ||
} | ||
valuesBlocks[i] = (DoubleBlock) block; | ||
} | ||
DoubleVector[] valuesVectors = new DoubleVector[values.length]; | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
valuesVectors[i] = valuesBlocks[i].asVector(); | ||
if (valuesVectors[i] == null) { | ||
return eval(page.getPositionCount(), valuesBlocks); | ||
} | ||
} | ||
return eval(page.getPositionCount(), valuesVectors).asBlock(); | ||
} | ||
|
||
public DoubleBlock eval(int positionCount, DoubleBlock[] valuesBlocks) { | ||
DoubleBlock.Builder result = DoubleBlock.newBlockBuilder(positionCount); | ||
double[] valuesValues = new double[values.length]; | ||
position: for (int p = 0; p < positionCount; p++) { | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
if (valuesBlocks[i].isNull(p) || valuesBlocks[i].getValueCount(p) != 1) { | ||
result.appendNull(); | ||
continue position; | ||
} | ||
} | ||
// unpack valuesBlocks into valuesValues | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
int o = valuesBlocks[i].getFirstValueIndex(p); | ||
valuesValues[i] = valuesBlocks[i].getDouble(o); | ||
} | ||
result.appendDouble(Greatest.process(valuesValues)); | ||
} | ||
return result.build(); | ||
} | ||
|
||
public DoubleVector eval(int positionCount, DoubleVector[] valuesVectors) { | ||
DoubleVector.Builder result = DoubleVector.newVectorBuilder(positionCount); | ||
double[] valuesValues = new double[values.length]; | ||
position: for (int p = 0; p < positionCount; p++) { | ||
// unpack valuesVectors into valuesValues | ||
for (int i = 0; i < valuesVectors.length; i++) { | ||
valuesValues[i] = valuesVectors[i].getDouble(p); | ||
} | ||
result.appendDouble(Greatest.process(valuesValues)); | ||
} | ||
return result.build(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GreatestDoubleEvaluator[" + "values=" + Arrays.toString(values) + "]"; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...ed/org/elasticsearch/xpack/esql/expression/function/scalar/math/GreatestIntEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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; you may not use this file except in compliance with the Elastic License | ||
// 2.0. | ||
package org.elasticsearch.xpack.esql.expression.function.scalar.math; | ||
|
||
import java.lang.Override; | ||
import java.lang.String; | ||
import java.util.Arrays; | ||
import org.elasticsearch.compute.data.Block; | ||
import org.elasticsearch.compute.data.IntBlock; | ||
import org.elasticsearch.compute.data.IntVector; | ||
import org.elasticsearch.compute.data.Page; | ||
import org.elasticsearch.compute.operator.EvalOperator; | ||
|
||
/** | ||
* {@link EvalOperator.ExpressionEvaluator} implementation for {@link Greatest}. | ||
* This class is generated. Do not edit it. | ||
*/ | ||
public final class GreatestIntEvaluator implements EvalOperator.ExpressionEvaluator { | ||
private final EvalOperator.ExpressionEvaluator[] values; | ||
|
||
public GreatestIntEvaluator(EvalOperator.ExpressionEvaluator[] values) { | ||
this.values = values; | ||
} | ||
|
||
@Override | ||
public Block eval(Page page) { | ||
IntBlock[] valuesBlocks = new IntBlock[values.length]; | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
Block block = values[i].eval(page); | ||
if (block.areAllValuesNull()) { | ||
return Block.constantNullBlock(page.getPositionCount()); | ||
} | ||
valuesBlocks[i] = (IntBlock) block; | ||
} | ||
IntVector[] valuesVectors = new IntVector[values.length]; | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
valuesVectors[i] = valuesBlocks[i].asVector(); | ||
if (valuesVectors[i] == null) { | ||
return eval(page.getPositionCount(), valuesBlocks); | ||
} | ||
} | ||
return eval(page.getPositionCount(), valuesVectors).asBlock(); | ||
} | ||
|
||
public IntBlock eval(int positionCount, IntBlock[] valuesBlocks) { | ||
IntBlock.Builder result = IntBlock.newBlockBuilder(positionCount); | ||
int[] valuesValues = new int[values.length]; | ||
position: for (int p = 0; p < positionCount; p++) { | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
if (valuesBlocks[i].isNull(p) || valuesBlocks[i].getValueCount(p) != 1) { | ||
result.appendNull(); | ||
continue position; | ||
} | ||
} | ||
// unpack valuesBlocks into valuesValues | ||
for (int i = 0; i < valuesBlocks.length; i++) { | ||
int o = valuesBlocks[i].getFirstValueIndex(p); | ||
valuesValues[i] = valuesBlocks[i].getInt(o); | ||
} | ||
result.appendInt(Greatest.process(valuesValues)); | ||
} | ||
return result.build(); | ||
} | ||
|
||
public IntVector eval(int positionCount, IntVector[] valuesVectors) { | ||
IntVector.Builder result = IntVector.newVectorBuilder(positionCount); | ||
int[] valuesValues = new int[values.length]; | ||
position: for (int p = 0; p < positionCount; p++) { | ||
// unpack valuesVectors into valuesValues | ||
for (int i = 0; i < valuesVectors.length; i++) { | ||
valuesValues[i] = valuesVectors[i].getInt(p); | ||
} | ||
result.appendInt(Greatest.process(valuesValues)); | ||
} | ||
return result.build(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GreatestIntEvaluator[" + "values=" + Arrays.toString(values) + "]"; | ||
} | ||
} |
Oops, something went wrong.