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
[Aggs] Fix column.meta.type for top hit, top metric and all filtered metrics #169834
Conversation
93fc94d
to
74c0d21
Compare
Pinging @elastic/kibana-visualizations (Team:Visualizations) |
b7e644b
to
b502baf
Compare
@@ -16,8 +16,7 @@ export function isNumericFieldForDatatable(currentData: Datatable | undefined, a | |||
const column = currentData?.columns.find( | |||
(col) => col.id === accessor || getOriginalId(col.id) === accessor | |||
); | |||
// min and max aggs are reporting as number but are actually dates - work around this by checking for the date formatter until this is fixed at the source |
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.
now that the min and max aggs were fixed, I think we can safely remove it.
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.
I think we could also remove the code in line 24, but I am leaving it just in case if there's something I miss!
b502baf
to
cb35516
Compare
const isNumericMap: Record<string, boolean> = useMemo(() => { | ||
const numericMap: Record<string, boolean> = {}; | ||
for (const column of firstLocalTable.columns) { | ||
// filtered metrics result as "number" type, but have no field |
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.
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.
I see that a test is failing but I think is fine, we are now actually fixing the last value alignmentws
@@ -545,53 +545,6 @@ describe('DatatableComponent', () => { | |||
}); | |||
}); | |||
|
|||
test('it detect last_value filtered metric type', () => { |
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 test is not needed anymore as it was added to guard against the buggy response from aggs that we were getting. Now, as we get a proper response (number type is always number, string is always a string) we don't have to test this.
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.
Tested locally and could not find issues with changes. LGTM 👍
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.
I don't find any bugs, on the contrary I think that we are improving our code a lot and we are possibly fixing bugs we don't know they exist :) Thanx Marta for working on this!
@@ -28,8 +28,7 @@ export class BaseParamType<TAggConfig extends IAggConfig = IAggConfig> { | |||
deserialize: (value: any, aggConfig?: TAggConfig) => any; | |||
toExpressionAst?: (value: any) => ExpressionAstExpression[] | ExpressionAstExpression | undefined; | |||
options: any[]; | |||
valueType?: any; | |||
|
|||
getValueType: (aggConfig: IAggConfig) => any; |
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.
I wonder is instead of any we give the DatatableColumnType will we have TS failures?
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 breaks because of the weird line I don't understand but without it the expression throws an error:
this.getValueType = () => AggConfig;
in file: src/plugins/data/common/search/aggs/param_types/agg.ts
Not sure how we could fix it, I'll talk to Peter about it once he's back to understand things better.
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.
Yes with so many anys it makes sense! Thanx for looking into it!
const isNumericMap: Record<string, boolean> = useMemo(() => { | ||
const numericMap: Record<string, boolean> = {}; | ||
for (const column of firstLocalTable.columns) { | ||
// filtered metrics result as "number" type, but have no field |
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.
I see that a test is failing but I think is fine, we are now actually fixing the last value alignmentws
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.
lgtm
d360fc3
to
8f71729
Compare
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Any counts in public APIs
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
…metrics (elastic#169834) ## Summary When checking my PR here elastic#169258 @stratoula noticed that the `column.meta.type` is not set properly for last value aggregation (it always defaults to 'number', same with all the filtered metrics too!). When I dug deeper, I noticed that happens because we calculate it as: ``` type: column.aggConfig.type.valueType column.aggConfig.params.field?.type || 'number', ``` and some of the `AggConfigs` don't have the static `valueType` property nor field, specifically the one with nested aggregations, like top_hits, top_metrics and filtered_metric. instead of a static `valueType`, I've decided to change it to a method `getValueType` where we can pass AggConfigs and get the type from different places internally. This way `top_hits`, `top_metrics` and `filtered_metric` get the type of the field from `customMetric`. I also changed the values for `min` and `max` aggregation - they were set on `number`, but they can also be a `date`.
…metrics (elastic#169834) ## Summary When checking my PR here elastic#169258 @stratoula noticed that the `column.meta.type` is not set properly for last value aggregation (it always defaults to 'number', same with all the filtered metrics too!). When I dug deeper, I noticed that happens because we calculate it as: ``` type: column.aggConfig.type.valueType column.aggConfig.params.field?.type || 'number', ``` and some of the `AggConfigs` don't have the static `valueType` property nor field, specifically the one with nested aggregations, like top_hits, top_metrics and filtered_metric. instead of a static `valueType`, I've decided to change it to a method `getValueType` where we can pass AggConfigs and get the type from different places internally. This way `top_hits`, `top_metrics` and `filtered_metric` get the type of the field from `customMetric`. I also changed the values for `min` and `max` aggregation - they were set on `number`, but they can also be a `date`.
Summary
When checking my PR here #169258 @stratoula noticed that the
column.meta.type
is not set properly for last value aggregation (it always defaults to 'number', same with all the filtered metrics too!). When I dug deeper, I noticed that happens because we calculate it as:and some of the
AggConfigs
don't have the staticvalueType
property nor field, specifically the one with nested aggregations, like top_hits, top_metrics and filtered_metric. instead of a staticvalueType
, I've decided to change it to a methodgetValueType
where we can pass AggConfigs and get the type from different places internally. This waytop_hits
,top_metrics
andfiltered_metric
get the type of the field fromcustomMetric
.I also changed the values for
min
andmax
aggregation - they were set onnumber
, but they can also be adate
.