Skip to content

Commit

Permalink
ESQL: Move some of ENRICH into compute (#116338) (#116424)
Browse files Browse the repository at this point in the history
* ESQL: Move some of ENRICH into compute

Move much of the code powering ENRICH and LOOKUP from index into the
`compute` project which has better support for testing `Operator`s.

This is *almost* just a move - except that I had to change the way
`QueryList` looks at `DataType` - because `compute` doesn't have
`DataType`. Instead I've moved the places where we used `DataType` into
method calls. I haven't changed how anything works in the tight loop -
but I have changed how it works in the setup.

* Do better

* Rename

* Drop extra
  • Loading branch information
nik9000 authored Nov 7, 2024
1 parent 1133942 commit 1e72669
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 140 deletions.
28 changes: 0 additions & 28 deletions x-pack/plugin/esql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -289,34 +289,6 @@ tasks.named('stringTemplates').configure {
var doubleProperties = prop("Double", "double", "DOUBLE", "Double.BYTES", "DoubleArray")
var bytesRefProperties = prop("BytesRef", "BytesRef", "BYTES_REF", "org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_REF", "")
var booleanProperties = prop("Boolean", "boolean", "BOOLEAN", "Byte.BYTES", "BitArray")
// enrich
File enrichResultBuilderInput = file("src/main/java/org/elasticsearch/xpack/esql/enrich/X-EnrichResultBuilder.java.st")
template {
it.properties = intProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/esql/enrich/EnrichResultBuilderForInt.java"
}
template {
it.properties = longProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/esql/enrich/EnrichResultBuilderForLong.java"
}
template {
it.properties = doubleProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/esql/enrich/EnrichResultBuilderForDouble.java"
}
template {
it.properties = bytesRefProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/esql/enrich/EnrichResultBuilderForBytesRef.java"
}
template {
it.properties = booleanProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/esql/enrich/EnrichResultBuilderForBoolean.java"
}


File inInputFile = file("src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/X-InEvaluator.java.st")
template {
Expand Down
28 changes: 28 additions & 0 deletions x-pack/plugin/esql/compute/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -803,4 +803,32 @@ tasks.named('stringTemplates').configure {
it.inputFile = bucketedSortInputFile
it.outputFile = "org/elasticsearch/compute/data/sort/DoubleBucketedSort.java"
}

File enrichResultBuilderInput = file("src/main/java/org/elasticsearch/compute/operator/lookup/X-EnrichResultBuilder.java.st")
template {
it.properties = intProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/compute/operator/lookup/EnrichResultBuilderForInt.java"
}
template {
it.properties = longProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/compute/operator/lookup/EnrichResultBuilderForLong.java"
}
template {
it.properties = doubleProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/compute/operator/lookup/EnrichResultBuilderForDouble.java"
}
template {
it.properties = bytesRefProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/compute/operator/lookup/EnrichResultBuilderForBytesRef.java"
}
template {
it.properties = booleanProperties
it.inputFile = enrichResultBuilderInput
it.outputFile = "org/elasticsearch/xpack/compute/operator/lookup/EnrichResultBuilderForBoolean.java"
}

}

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

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

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

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

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

1 change: 1 addition & 0 deletions x-pack/plugin/esql/compute/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
exports org.elasticsearch.compute.operator.exchange;
exports org.elasticsearch.compute.aggregation.blockhash;
exports org.elasticsearch.compute.aggregation.spatial;
exports org.elasticsearch.compute.operator.lookup;
exports org.elasticsearch.compute.operator.topn;
exports org.elasticsearch.compute.operator.mvdedupe;
exports org.elasticsearch.compute.aggregation.table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

package org.elasticsearch.xpack.esql.enrich;
package org.elasticsearch.compute.operator.lookup;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
Expand All @@ -31,8 +31,7 @@
* This operator will emit Pages consisting of a {@link DocVector} and {@link IntBlock} of positions for each query of the input queries.
* The position block will be used as keys to combine the extracted values by {@link MergePositionsOperator}.
*/
final class EnrichQuerySourceOperator extends SourceOperator {

public final class EnrichQuerySourceOperator extends SourceOperator {
private final BlockFactory blockFactory;
private final QueryList queryList;
private int queryPosition = -1;
Expand All @@ -41,9 +40,9 @@ final class EnrichQuerySourceOperator extends SourceOperator {
private final int maxPageSize;

// using smaller pages enables quick cancellation and reduces sorting costs
static final int DEFAULT_MAX_PAGE_SIZE = 256;
public static final int DEFAULT_MAX_PAGE_SIZE = 256;

EnrichQuerySourceOperator(BlockFactory blockFactory, int maxPageSize, QueryList queryList, IndexReader indexReader) {
public EnrichQuerySourceOperator(BlockFactory blockFactory, int maxPageSize, QueryList queryList, IndexReader indexReader) {
this.blockFactory = blockFactory;
this.maxPageSize = maxPageSize;
this.queryList = queryList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

package org.elasticsearch.xpack.esql.enrich;
package org.elasticsearch.compute.operator.lookup;

import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.BlockFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

package org.elasticsearch.xpack.esql.enrich;
package org.elasticsearch.compute.operator.lookup;

import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.BlockFactory;
Expand Down Expand Up @@ -43,15 +43,15 @@
* | null | null |
* | d | 2023 |
*/
final class MergePositionsOperator implements Operator {
public final class MergePositionsOperator implements Operator {
private boolean finished = false;
private final int positionChannel;
private final EnrichResultBuilder[] builders;
private final IntBlock selectedPositions;

private Page outputPage;

MergePositionsOperator(
public MergePositionsOperator(
int positionChannel,
int[] mergingChannels,
ElementType[] mergingTypes,
Expand Down
Loading

0 comments on commit 1e72669

Please sign in to comment.