-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESQL: Implement 'right' function (#98974)
Add the 'right' function, which extracts a substring beginning from its right end (opposite function of 'left'). --------- Co-authored-by: Alexander Spies <alexander.spies@elastic.co>
- Loading branch information
1 parent
7dcfdd6
commit 0438166
Showing
18 changed files
with
658 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 98974 | ||
summary: "ESQL: RIGHT function" | ||
area: ES|QL | ||
type: feature | ||
issues: [] |
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
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,19 @@ | ||
[[esql-right]] | ||
=== `RIGHT` | ||
[.text-center] | ||
image::esql/functions/signature/right.svg[Embedded,opts=inline] | ||
|
||
Return the substring that extracts 'length' chars from the 'string' starting from the right. | ||
|
||
[source.merge.styled,esql] | ||
---- | ||
include::{esql-specs}/string.csv-spec[tag=right] | ||
---- | ||
[%header.monospaced.styled,format=dsv,separator=|] | ||
|=== | ||
include::{esql-specs}/string.csv-spec[tag=right-result] | ||
|=== | ||
|
||
Supported types: | ||
|
||
include::types/right.asciidoc[] |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[%header.monospaced.styled,format=dsv,separator=|] | ||
|=== | ||
arg1 | arg2 | result | ||
string | length | result | ||
keyword | integer | keyword | ||
|=== |
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,5 @@ | ||
[%header.monospaced.styled,format=dsv,separator=|] | ||
|=== | ||
string | length | result | ||
keyword | integer | keyword | ||
|=== |
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
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
...erated/org/elasticsearch/xpack/esql/expression/function/scalar/string/RightEvaluator.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.string; | ||
|
||
import java.lang.Override; | ||
import java.lang.String; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.apache.lucene.util.UnicodeUtil; | ||
import org.elasticsearch.compute.data.Block; | ||
import org.elasticsearch.compute.data.BytesRefBlock; | ||
import org.elasticsearch.compute.data.BytesRefVector; | ||
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 Right}. | ||
* This class is generated. Do not edit it. | ||
*/ | ||
public final class RightEvaluator implements EvalOperator.ExpressionEvaluator { | ||
private final BytesRef out; | ||
|
||
private final UnicodeUtil.UTF8CodePoint cp; | ||
|
||
private final EvalOperator.ExpressionEvaluator str; | ||
|
||
private final EvalOperator.ExpressionEvaluator length; | ||
|
||
public RightEvaluator(BytesRef out, UnicodeUtil.UTF8CodePoint cp, | ||
EvalOperator.ExpressionEvaluator str, EvalOperator.ExpressionEvaluator length) { | ||
this.out = out; | ||
this.cp = cp; | ||
this.str = str; | ||
this.length = length; | ||
} | ||
|
||
@Override | ||
public Block eval(Page page) { | ||
Block strUncastBlock = str.eval(page); | ||
if (strUncastBlock.areAllValuesNull()) { | ||
return Block.constantNullBlock(page.getPositionCount()); | ||
} | ||
BytesRefBlock strBlock = (BytesRefBlock) strUncastBlock; | ||
Block lengthUncastBlock = length.eval(page); | ||
if (lengthUncastBlock.areAllValuesNull()) { | ||
return Block.constantNullBlock(page.getPositionCount()); | ||
} | ||
IntBlock lengthBlock = (IntBlock) lengthUncastBlock; | ||
BytesRefVector strVector = strBlock.asVector(); | ||
if (strVector == null) { | ||
return eval(page.getPositionCount(), strBlock, lengthBlock); | ||
} | ||
IntVector lengthVector = lengthBlock.asVector(); | ||
if (lengthVector == null) { | ||
return eval(page.getPositionCount(), strBlock, lengthBlock); | ||
} | ||
return eval(page.getPositionCount(), strVector, lengthVector).asBlock(); | ||
} | ||
|
||
public BytesRefBlock eval(int positionCount, BytesRefBlock strBlock, IntBlock lengthBlock) { | ||
BytesRefBlock.Builder result = BytesRefBlock.newBlockBuilder(positionCount); | ||
BytesRef strScratch = new BytesRef(); | ||
position: for (int p = 0; p < positionCount; p++) { | ||
if (strBlock.isNull(p) || strBlock.getValueCount(p) != 1) { | ||
result.appendNull(); | ||
continue position; | ||
} | ||
if (lengthBlock.isNull(p) || lengthBlock.getValueCount(p) != 1) { | ||
result.appendNull(); | ||
continue position; | ||
} | ||
result.appendBytesRef(Right.process(out, cp, strBlock.getBytesRef(strBlock.getFirstValueIndex(p), strScratch), lengthBlock.getInt(lengthBlock.getFirstValueIndex(p)))); | ||
} | ||
return result.build(); | ||
} | ||
|
||
public BytesRefVector eval(int positionCount, BytesRefVector strVector, IntVector lengthVector) { | ||
BytesRefVector.Builder result = BytesRefVector.newVectorBuilder(positionCount); | ||
BytesRef strScratch = new BytesRef(); | ||
position: for (int p = 0; p < positionCount; p++) { | ||
result.appendBytesRef(Right.process(out, cp, strVector.getBytesRef(p, strScratch), lengthVector.getInt(p))); | ||
} | ||
return result.build(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RightEvaluator[" + "str=" + str + ", length=" + length + "]"; | ||
} | ||
} |
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
Oops, something went wrong.