Skip to content

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Sep 21, 2025

Standardizes how aggs and scalars work with arguments that take all
values at a position.

Aggs were using an arrays of values that we had to copy all of the
values into the array. And allocate it. Scalars passed down the Block
and the scalar read from the block on it's own. That's generally more
efficient and not a lot harder. So I standardized on that.

Previously scalars that took a Block parameter also took an implicit
builder and position parameter. But aggs don't need the builder. And
do need the position. This makes both of those parameters explicit
rather than implicit.

Relates to #108385

Standardizes how aggs and scalars work with arguments that take all
values at a position.

Aggs were using an arrays of values that we had to copy all of the
values into the array. And allocate it. Scalars passed down the `Block`
and the scalar read from the block on it's own. That's generally more
efficient and not a lot harder. So I standardized on that.

Previously scalars that took a `Block` parameter also took an implicit
builder and position parameter. But aggs don't need the builder. And
*do* need the position. This makes both of those parameters explicit
rather than implicit.
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Sep 21, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

case StandardArgument sa -> Stream.of(new AggregationParameter(sa.name(), sa.type(), false));
case BlockArgument ba -> Stream.of(new AggregationParameter(ba.name(), Types.elementType(ba.type()), true));
case PositionArgument pa -> Stream.of();
default -> throw new IllegalArgumentException("unsupported argument [" + declarationType + "][" + a + "]");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next PR I should be ale to remove this instanceof and just us the Argument directly. It'll need a few more methods, but should be fine.

current.add(values);
public static void combine(SpatialExtentState current, @Position int p, IntBlock values) {
current.add(p, values);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the shift from arrays to Block.


@Evaluator(extraName = "Int")
static void process(IntBlock.Builder builder, int position, IntBlock field1, IntBlock field2) {
static void process(IntBlock.Builder builder, @Position int position, IntBlock field1, IntBlock field2) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here's the explicit @Position parameter.

Copy link
Member

@dnhatn dnhatn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks Nik!

"int valuesEnd = valuesStart + $L.getValueCount(valuesPosition)",
aggParams.getFirst().blockName()
);
builder.addStatement("$L[] valuesArray = new $L[valuesEnd - valuesStart]", arrayType, arrayType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@nik9000
Copy link
Member Author

nik9000 commented Sep 22, 2025

Thanks @dnhatn !

@nik9000 nik9000 merged commit e660ebb into elastic:main Sep 22, 2025
34 checks passed
gmjehovich pushed a commit to gmjehovich/elasticsearch that referenced this pull request Sep 22, 2025
Standardizes how aggs and scalars work with arguments that take all
values at a position.

Aggs were using an arrays of values that we had to copy all of the
values into the array. And allocate it. Scalars passed down the `Block`
and the scalar read from the block on it's own. That's generally more
efficient and not a lot harder. So I standardized on that.

Previously scalars that took a `Block` parameter also took an implicit
builder and position parameter. But aggs don't need the builder. And
*do* need the position. This makes both of those parameters explicit
rather than implicit.
DonalEvans pushed a commit to DonalEvans/elasticsearch that referenced this pull request Sep 22, 2025
Standardizes how aggs and scalars work with arguments that take all
values at a position.

Aggs were using an arrays of values that we had to copy all of the
values into the array. And allocate it. Scalars passed down the `Block`
and the scalar read from the block on it's own. That's generally more
efficient and not a lot harder. So I standardized on that.

Previously scalars that took a `Block` parameter also took an implicit
builder and position parameter. But aggs don't need the builder. And
*do* need the position. This makes both of those parameters explicit
rather than implicit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants