-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Add dimension values for time-series #136052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dnhatn
wants to merge
2
commits into
elastic:main
Choose a base branch
from
dnhatn:dimension-values
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+250
−23
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
server/src/main/resources/transport/definitions/referable/dimension_values.csv
This file contains hidden or 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 @@ | ||
9188000,9185001 |
This file contains hidden or 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 +1 @@ | ||
initial_9.2.0,9185000 | ||
dimension_values,9185001 |
This file contains hidden or 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 +1 @@ | ||
resolved_index_expressions,9187000 | ||
dimension_values,9188000 |
This file contains hidden or 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
92 changes: 92 additions & 0 deletions
92
...main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/DimensionValues.java
This file contains hidden or 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,92 @@ | ||
/* | ||
* 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.aggregate; | ||
|
||
import org.elasticsearch.TransportVersion; | ||
import org.elasticsearch.common.io.stream.NamedWriteable; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.compute.aggregation.AggregatorFunctionSupplier; | ||
import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
import org.elasticsearch.xpack.esql.core.tree.NodeInfo; | ||
import org.elasticsearch.xpack.esql.core.tree.Source; | ||
import org.elasticsearch.xpack.esql.core.type.DataType; | ||
import org.elasticsearch.xpack.esql.io.stream.VersionedExpression; | ||
import org.elasticsearch.xpack.esql.planner.ToAggregator; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
/** | ||
* A specialization of {@link Values} for collecting dimension fields in time-series queries. | ||
*/ | ||
public class DimensionValues extends AggregateFunction implements ToAggregator, VersionedExpression { | ||
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry( | ||
Expression.class, | ||
"DimensionValues", | ||
DimensionValues::new | ||
); | ||
|
||
static final TransportVersion DIMENSION_VALUES_VERSION = TransportVersion.fromName("dimension_values"); | ||
|
||
public DimensionValues(Source source, Expression field, Expression filter) { | ||
super(source, field, filter, emptyList()); | ||
} | ||
|
||
private DimensionValues(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return ENTRY.name; | ||
} | ||
|
||
@Override | ||
public NamedWriteable getVersionedNamedWriteable(TransportVersion transportVersion) { | ||
if (transportVersion.onOrAfter(DIMENSION_VALUES_VERSION)) { | ||
return this; | ||
} else { | ||
// fallback to VALUES | ||
return new Values(source(), field(), filter()); | ||
} | ||
} | ||
|
||
@Override | ||
protected NodeInfo<DimensionValues> info() { | ||
return NodeInfo.create(this, DimensionValues::new, field(), filter()); | ||
} | ||
|
||
@Override | ||
public DimensionValues replaceChildren(List<Expression> newChildren) { | ||
return new DimensionValues(source(), newChildren.get(0), newChildren.get(1)); | ||
} | ||
|
||
@Override | ||
public DimensionValues withFilter(Expression filter) { | ||
return new DimensionValues(source(), field(), filter); | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return field().dataType().noText(); | ||
} | ||
|
||
@Override | ||
protected TypeResolution resolveType() { | ||
return new Values(source(), field(), filter()).resolveType(); | ||
} | ||
|
||
@Override | ||
public AggregatorFunctionSupplier supplier() { | ||
// TODO: link new implementation | ||
return new Values(source(), field(), filter()).supplier(); | ||
} | ||
} |
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
...plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/VersionedExpression.java
This file contains hidden or 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,23 @@ | ||
/* | ||
* 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.io.stream; | ||
|
||
import org.elasticsearch.TransportVersion; | ||
import org.elasticsearch.common.io.stream.NamedWriteable; | ||
|
||
/** | ||
* An interface indicating to {@link PlanStreamOutput} that this expression can have multiple versions and may need to fallback. | ||
* TODO: Should we move this to VersionedNamedWriteable? | ||
*/ | ||
public interface VersionedExpression { | ||
/** | ||
* Returns the writeable expression for the specified transport version. | ||
* This allows introducing a new expression when nodes are ready to handle it; otherwise, it falls back to the previous expression. | ||
*/ | ||
NamedWriteable getVersionedNamedWriteable(TransportVersion transportVersion); | ||
} |
This file contains hidden or 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
74 changes: 74 additions & 0 deletions
74
...ticsearch/xpack/esql/expression/function/aggregate/DimensionValuesSerializationTests.java
This file contains hidden or 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,74 @@ | ||
/* | ||
* 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.aggregate; | ||
|
||
import org.elasticsearch.TransportVersion; | ||
import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.TransportVersionUtils; | ||
import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute; | ||
import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; | ||
import org.elasticsearch.xpack.esql.expression.function.ReferenceAttributeTests; | ||
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput; | ||
import org.elasticsearch.xpack.esql.io.stream.PlanStreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class DimensionValuesSerializationTests extends AbstractExpressionSerializationTests<DimensionValues> { | ||
@Override | ||
protected DimensionValues createTestInstance() { | ||
return new DimensionValues(randomSource(), randomChild(), randomChild()); | ||
} | ||
|
||
@Override | ||
protected DimensionValues mutateInstance(DimensionValues instance) throws IOException { | ||
return new DimensionValues( | ||
instance.source(), | ||
randomValueOtherThan(instance.field(), AbstractExpressionSerializationTests::randomChild), | ||
randomValueOtherThan(instance.filter(), AbstractExpressionSerializationTests::randomChild) | ||
); | ||
} | ||
|
||
public void testBWC() throws Exception { | ||
DimensionValues dimensionValues = new DimensionValues( | ||
randomSource(), | ||
randomAttributeWithoutQualifier(), | ||
randomAttributeWithoutQualifier() | ||
); | ||
TransportVersion version = TransportVersionUtils.randomVersionBetween( | ||
random(), | ||
TransportVersion.minimumCompatible(), | ||
TransportVersionUtils.getPreviousVersion(DimensionValues.DIMENSION_VALUES_VERSION) | ||
); | ||
NamedWriteableRegistry namedWriteableRegistry = getNamedWriteableRegistry(); | ||
try (BytesStreamOutput output = new BytesStreamOutput()) { | ||
output.setTransportVersion(version); | ||
PlanStreamOutput planOut = new PlanStreamOutput(output, configuration()); | ||
planOut.writeNamedWriteable(dimensionValues); | ||
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) { | ||
PlanStreamInput planIn = new PlanStreamInput(in, namedWriteableRegistry, configuration()); | ||
planIn.setTransportVersion(version); | ||
Expression oldValues = (Expression) planIn.readNamedWriteable(categoryClass()); | ||
Values expected = new Values(dimensionValues.source(), dimensionValues.field(), dimensionValues.filter()); | ||
assertThat(oldValues, equalTo(expected)); | ||
} | ||
} | ||
} | ||
|
||
// can't serialize qualified attribute with older versions | ||
private Expression randomAttributeWithoutQualifier() { | ||
ReferenceAttribute e = ReferenceAttributeTests.randomReferenceAttribute(ESTestCase.randomBoolean()); | ||
return new ReferenceAttribute(e.source(), null, e.name(), e.dataType(), e.nullable(), e.id(), e.synthetic()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where we fallback dimension_values to values.