-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] Transforms: Support for terms agg in pivot configurations. #123634
Changes from 4 commits
d886bf9
5e86925
aa31845
f9cc5f5
d9bb4e5
4878e18
1289fa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,11 @@ import { | |
import { | ||
isAggName, | ||
isPivotAggsConfigPercentiles, | ||
isPivotAggsConfigTerms, | ||
isPivotAggsConfigWithUiSupport, | ||
getEsAggFromAggConfig, | ||
PERCENTILES_AGG_DEFAULT_PERCENTS, | ||
TERMS_AGG_DEFAULT_SIZE, | ||
PivotAggsConfig, | ||
PivotAggsConfigWithUiSupportDict, | ||
} from '../../../../common'; | ||
|
@@ -75,6 +77,20 @@ function parsePercentsInput(inputValue: string | undefined) { | |
return []; | ||
} | ||
|
||
function getDefaultSize(defaultData: PivotAggsConfig): number | undefined { | ||
if (isPivotAggsConfigTerms(defaultData)) { | ||
return defaultData.size; | ||
} | ||
} | ||
|
||
function parseSizeInput(inputValue: string | undefined) { | ||
if (inputValue !== undefined) { | ||
return parseInt(inputValue, 10); | ||
} | ||
|
||
return TERMS_AGG_DEFAULT_SIZE; | ||
} | ||
|
||
export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onChange, options }) => { | ||
const [aggConfigDef, setAggConfigDef] = useState(cloneDeep(defaultData)); | ||
|
||
|
@@ -85,6 +101,7 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha | |
); | ||
|
||
const [percents, setPercents] = useState(getDefaultPercents(defaultData)); | ||
const [size, setSize] = useState(getDefaultSize(defaultData)); | ||
|
||
const isUnsupportedAgg = !isPivotAggsConfigWithUiSupport(defaultData); | ||
|
||
|
@@ -118,12 +135,19 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha | |
if (aggVal === PIVOT_SUPPORTED_AGGS.PERCENTILES && percents === undefined) { | ||
setPercents(PERCENTILES_AGG_DEFAULT_PERCENTS); | ||
} | ||
if (aggVal === PIVOT_SUPPORTED_AGGS.TERMS && size === undefined) { | ||
setSize(TERMS_AGG_DEFAULT_SIZE); | ||
} | ||
} | ||
|
||
function updatePercents(inputValue: string) { | ||
setPercents(parsePercentsInput(inputValue)); | ||
} | ||
|
||
function updateSize(inputValue: string) { | ||
setSize(parseSizeInput(inputValue)); | ||
} | ||
|
||
function getUpdatedItem(): PivotAggsConfig { | ||
let updatedItem: PivotAggsConfig; | ||
|
||
|
@@ -137,21 +161,29 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha | |
resultField = field[0]; | ||
} | ||
|
||
if (agg !== PIVOT_SUPPORTED_AGGS.PERCENTILES) { | ||
if (agg === PIVOT_SUPPORTED_AGGS.PERCENTILES) { | ||
updatedItem = { | ||
agg, | ||
aggName, | ||
field: resultField, | ||
dropDownName: defaultData.dropDownName, | ||
percents, | ||
}; | ||
} else if (agg === PIVOT_SUPPORTED_AGGS.TERMS) { | ||
updatedItem = { | ||
...aggConfigDef, | ||
agg, | ||
aggName, | ||
field: resultField, | ||
dropDownName: defaultData.dropDownName, | ||
size, | ||
}; | ||
} else { | ||
updatedItem = { | ||
...aggConfigDef, | ||
agg, | ||
aggName, | ||
field: resultField, | ||
dropDownName: defaultData.dropDownName, | ||
percents, | ||
}; | ||
} | ||
|
||
|
@@ -205,10 +237,20 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha | |
const validPercents = | ||
agg === PIVOT_SUPPORTED_AGGS.PERCENTILES && parsePercentsInput(percentsText).length > 0; | ||
|
||
let sizeText; | ||
if (size !== undefined) { | ||
sizeText = size.toString(); | ||
} | ||
|
||
const validSize = agg === PIVOT_SUPPORTED_AGGS.TERMS && parseSizeInput(sizeText) > 0; | ||
|
||
let formValid = validAggName; | ||
if (formValid && agg === PIVOT_SUPPORTED_AGGS.PERCENTILES) { | ||
formValid = validPercents; | ||
} | ||
if (formValid && agg === PIVOT_SUPPORTED_AGGS.TERMS) { | ||
formValid = validSize; | ||
} | ||
if (isPivotAggsWithExtendedForm(aggConfigDef)) { | ||
formValid = validAggName && aggConfigDef.isValid(); | ||
} | ||
|
@@ -325,6 +367,23 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha | |
/> | ||
</EuiFormRow> | ||
)} | ||
{agg === PIVOT_SUPPORTED_AGGS.TERMS && ( | ||
<EuiFormRow | ||
label={i18n.translate('xpack.transform.agg.popoverForm.sizeLabel', { | ||
defaultMessage: 'Size', | ||
})} | ||
error={ | ||
!validSize && [ | ||
i18n.translate('xpack.transform.groupBy.popoverForm.invalidSizeErrorMessage', { | ||
defaultMessage: 'Enter a valid positive number', | ||
}), | ||
] | ||
} | ||
isInvalid={!validSize} | ||
> | ||
<EuiFieldText defaultValue={sizeText} onChange={(e) => updateSize(e.target.value)} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. size is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember we intentionally went with the text field in other cases too because we had problems in the past with custom validations. So for consistency I went with the text based one here again. See the input for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the additional feedback, I switched to |
||
</EuiFormRow> | ||
)} | ||
{isUnsupportedAgg && ( | ||
<EuiCodeBlock | ||
aria-label={i18n.translate('xpack.transform.agg.popoverForm.codeBlock', { | ||
|
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.
The grid isn't inferring the type of the value correctly - it thinks it's a string, so left aligns the cell contents, and gives the alphabetical sort options (note sort isn't working on nested fields but I will raise a separate issue for that).
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.
It makes sense to address this as part of #123796 as even if the type for the
terms
agg columns is correctly set to numeric it still won't be sorted correctly as the column name will contain a dot.