Skip to content
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

ESQL: Move more of EsqlDataTypes into DataType #109921

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Jun 19, 2024

This further consolidates our type resolution stuff into DataType. Slowly, slowly, there will be one place to do this stuff for ESQL.

This further consolidates our type resolution stuff into `DataType`.
Slowly, slowly, there will be one place to do this stuff for ESQL.
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jun 19, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@@ -27,32 +27,9 @@
import static java.util.stream.Collectors.toUnmodifiableMap;

public enum DataType {
UNSUPPORTED("UNSUPPORTED", null, 0, false, false, false),
Copy link
Member Author

Choose a reason for hiding this comment

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

I went to add three more parameters and couldn't read anything. So I shifted it to a sort of named parameters with defaults thing.

Copy link
Member

Choose a reason for hiding this comment

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

If we're going to use a builder, I'd prefer if the constructor didn't take any parameters and everything used a named parameter function. I do think the builder is a good idea.

assumeTrue("Expected type must be representable to build an evaluator", EsqlDataTypes.isRepresentable(testCase.expectedType()));
logger.info(
"Test Values: " + testCase.getData().stream().map(TestCaseSupplier.TypedData::toString).collect(Collectors.joining(","))
);
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this because isRepresentable had been getting a null value for a long time and that was returning null. With this change you can't send null to isRepresentable. Which, to be honest, we never should have been sending. It's kind of like asking "can you represent unknown in a block?". And the answer is "no, of course not, that's silly".

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

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

LGTM, but I'd keep the widening outside the type definition.

* If this is a "small" numeric type this contains the type ESQL will
* widen it into, otherwise this is {@code null}.
*/
private final DataType widenSmallNumeric;
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem a property of the type, IMO, but a type's user preference.
If we add, say, float through support, we'd no longer widen the values to double.

Copy link
Member Author

Choose a reason for hiding this comment

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

I figured we'd remove that widening in that case. It feels a little simpler to stick it here, but I'm not tightly tied to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I merged this on Friday so Mark could build on this. I covered some of the followups in #110105. But not this one. I kind of like keeping this where it is....

Copy link
Contributor

Choose a reason for hiding this comment

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

Was a minor note, it can stay as is 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

❤️

Copy link
Member

@not-napoleon not-napoleon left a comment

Choose a reason for hiding this comment

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

LGTM. Couple of nits, but overall this is a great change. Thanks for taking it.

@@ -27,32 +27,9 @@
import static java.util.stream.Collectors.toUnmodifiableMap;

public enum DataType {
UNSUPPORTED("UNSUPPORTED", null, 0, false, false, false),
Copy link
Member

Choose a reason for hiding this comment

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

If we're going to use a builder, I'd prefer if the constructor didn't take any parameters and everything used a named parameter function. I do think the builder is a good idea.

return EsqlDataTypes.fromName(typeName);
}
DataType type = EsqlDataTypes.fromName(typeName);
return metricType == TimeSeriesParams.MetricType.COUNTER ? type.widenSmallNumeric().counter() : type;
Copy link
Member

Choose a reason for hiding this comment

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

It's not obvious to me what this is doing, or why it's equivalent to the old code. Please add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added this to #110105.

@nik9000
Copy link
Member Author

nik9000 commented Jun 21, 2024

@not-napoleon is going to build on top of this one so I'm going to merge even though we've got some feedback on this. I'll iterate on the feedback in a separate PR on Monday.

@nik9000 nik9000 merged commit e998c30 into elastic:main Jun 21, 2024
14 of 15 checks passed
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Jun 24, 2024
This moves a few more methods from `EsqlDataTypes` into `DataType` and
makes some of the followup changes recommended in elastic#109921.
nik9000 added a commit that referenced this pull request Jun 26, 2024
This moves a few more methods from `EsqlDataTypes` into `DataType` and
makes some of the followup changes recommended in #109921.
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) v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants