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: Mark counter fields as unsupported #99054

Merged
merged 9 commits into from
Sep 13, 2023

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Aug 30, 2023

This marks TSDB's counter fields as unsupported by ESQL. We'll support them eventually, but in the short term we were just treating them like their underlying numeric type and that's not great. They have a conceptually different meaning that we'd like to respect one day. So, for now, we'll mark them unsupported.

This marks TSDB's `counter` fields as unsupported by ESQL. We'll support
them eventually, but in the short term we were just treating them like
their underlying numeric type and that's not great. They have a
conceptually different meaning that we'd like to respect one day. So,
for now, we'll mark them unsupported.
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@elasticsearchmachine elasticsearchmachine added the Team:QL (Deprecated) Meta label for query languages team label Aug 30, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/elasticsearch-esql (:Query Languages/ES|QL)

@elasticsearchmachine
Copy link
Collaborator

Hi @nik9000, I've created a changelog YAML for you.

@nik9000
Copy link
Member Author

nik9000 commented Aug 30, 2023

@astefan, I'm not sure of a good way to unit test this thing. Do you have any ideas?

@@ -19,7 +21,7 @@ public interface DataTypeRegistry {
//
Collection<DataType> dataTypes();

DataType fromEs(String typeName);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would try to make this a bit more generic, ie instead of specifically looking at TimeSeriesParams.MetricType I'd try to use the FieldCapabilities instance itself from where I could extract whatever information necessary to decide the supportability of a data type. Another suggestion is to look into defining a second fromEs method that receives this FieldCapabilities parameter and keep the original one unchanged.

Copy link
Contributor

Choose a reason for hiding this comment

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

When the IndexResolver has been created the field_caps API didn't return such additional information and I am not seeing any less intrusive way to support this other than what you suggested.

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'd be worried about keeping the original one unchanged because it's kind of dangerous, at least in ESQL it is. But I'm happy to move the whole field caps response there.

Copy link
Member

Choose a reason for hiding this comment

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

I'm stumbling over the same issue - how about encoding the TIME_SERIES_METRIC_PARAM inside the name along with its value, as a suffix for example?
This convention avoids having to extend the static method and can handle in the future more parameter or special types outside the metric ones without having to extend the method yet again.

For example when dealing with a timeseries metric type, append that to the typeName itself and then check in EsqlDataType if the typeName ends up TIME_SERIES_METRIC_PARAM-COUNTER.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding it to the string feels easy to break. It'd be even more likely for folks to accidentally not use the metric param.

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 looked at taking the whole FieldCapabilities object but there is a place we don't have it - in the mapping walking code. I'm not sure it's worth trying to get it there when adding the smaller parameter works.

Copy link
Member

Choose a reason for hiding this comment

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

How about adding a generic object as field context instead of typing it to TimeSeriesParams.MetricType and doing an instanceof check?
It is not OOP-ish but in this case we're looking at a bag properties for fields vs just the name.
For example how about DataType fromEs(String typeName, Object typeContext)
and then in ESQL do:

if (typeContext ==TimeSeriesParams.MetricType.COUNTER)) {
  ...
}

I'd like to avoid us to add a new param for each special type on the method signature and instead use a "bucket" type approach.
If you're on the fence, we can merge the PR and revisit this in the future.

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 get where your coming from. My preference would be to merge as is and then, when we got to add the next "funny" parameter, we do something like:

record FromEs(String typeName, TimeSeriesParams.MetricType metricType, TheNewThing newThing) {}

DataType fromEs(FromEs fromEs) {

If it feels sensible then. I don't feel like we need something so fancy for two fields. But three or our we really may.

@astefan
Copy link
Contributor

astefan commented Aug 31, 2023

Regarding unit testing, there is TypesTests class in the ql module. But this is not an ideal test for the IndexResolver logic, since it's not using its methods :-(, it's a series of tests more for the data types themselves. There's also, probably better choice, IndexResolverTests in the SQL module, where FieldCapabilities instances are manually created and the result of indexresolver logic asserted.

@nik9000
Copy link
Member Author

nik9000 commented Aug 31, 2023

IndexResolverTests

I saw that! I thought "oh, I can copy this into the ql module and make changes. But that doesn't quite work. I'll push more in that direction.

@martijnvg
Copy link
Member

+1 for not allowing counter fields in esql for now.

@costin costin self-requested a review September 11, 2023 20:58
Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

Added a comment with my preference, I'll leave it up to you on how to move forward.

@nik9000
Copy link
Member Author

nik9000 commented Sep 12, 2023

@astefan could you have a look at this one again? I'm not sure about pushing the whole FieldCapabilities instance in - it's kind of not possible in some branches - though I wonder if that's testing branches that are only used in SQL.

@nik9000 nik9000 added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Sep 13, 2023
@elasticsearchmachine elasticsearchmachine merged commit 81c90ff into elastic:main Sep 13, 2023
@nik9000 nik9000 deleted the tsbd_counter branch September 13, 2023 20:01
piergm pushed a commit to piergm/elasticsearch that referenced this pull request Sep 14, 2023
This marks TSDB's `counter` fields as unsupported by ESQL. We'll support
them eventually, but in the short term we were just treating them like
their underlying numeric type and that's not great. They have a
conceptually different meaning that we'd like to respect one day. So,
for now, we'll mark them unsupported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >enhancement Team:QL (Deprecated) Meta label for query languages team v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants