Skip to content

Commit

Permalink
[Ingest Pipelines] Fix dot expander processor to accept wildcard (#12…
Browse files Browse the repository at this point in the history
  • Loading branch information
shanwong29 committed Mar 1, 2022
1 parent 82f143c commit 7f364ea
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Processor: Dot Expander', () => {
expect(form.getErrorsMessages()).toEqual(['A field value is required.']);
});

test('prevents form submission if field does not contain a . for the dot notation', async () => {
test('prevents form submission if field for the dot notation does not contain a . and not equal to *', async () => {
const {
actions: { saveNewProcessor },
form,
Expand All @@ -77,9 +77,28 @@ describe('Processor: Dot Expander', () => {

// Expect form error as "field" does not contain '.'
expect(form.getErrorsMessages()).toEqual([
'A field value requires at least one dot character.',
'The field name must be an asterisk or contain a dot character.',
]);
});

test('allows form submission if the field for the dot notation is equal to *', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Set "field" value to a * for expanding all top-level dotted field names
form.setInputValue('fieldNameField.input', '*');

// Save the field
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, DOT_EXPANDER_TYPE);
expect(processors[0][DOT_EXPANDER_TYPE]).toEqual({
field: '*',
});
});

test('saves with default parameter values', async () => {
const {
actions: { saveNewProcessor },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ export const DotExpander: FunctionComponent = () => {
{
validator: ({ value }) => {
if (typeof value === 'string' && value.length) {
return !value.includes('.')
const allowedPattern = value.includes('.') || value === '*';
return !allowedPattern
? {
message: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.dotExpanderForm.fieldNameRequiresDotError',
{ defaultMessage: 'A field value requires at least one dot character.' }
{
defaultMessage:
'The field name must be an asterisk or contain a dot character.',
}
),
}
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,24 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = {
defaultMessage:
'Expands a field containing dot notation into an object field. The object field is then accessible by other processors in the pipeline.',
}),
getDefaultDescription: ({ field }) =>
i18n.translate('xpack.ingestPipelines.processors.defaultDescription.dot_expander', {
defaultMessage: 'Expands "{field}" into an object field',
values: {
field,
},
}),
getDefaultDescription: ({ field }) => {
return field === '*'
? i18n.translate(
'xpack.ingestPipelines.processors.defaultDescription.dot_expander.wildcard',
{
defaultMessage: 'All top-level fields will be expanded',
}
)
: i18n.translate(
'xpack.ingestPipelines.processors.defaultDescription.dot_expander.dot_notation',
{
defaultMessage: 'Expands "{field}" into an object field',
values: {
field,
},
}
);
},
},
drop: {
FieldsComponent: Drop,
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -15712,7 +15712,6 @@
"xpack.ingestPipelines.processors.defaultDescription.dateIndexName.indexNamePrefixDefault.noPrefixValueLabel": "プレフィックスなし",
"xpack.ingestPipelines.processors.defaultDescription.dateIndexName.indexNamePrefixDefault.prefixValueLabel": "プレフィックス\"{prefix}\"を使用",
"xpack.ingestPipelines.processors.defaultDescription.dissect": "分離したパターンと一致する値を\"{field}\"から抽出します",
"xpack.ingestPipelines.processors.defaultDescription.dot_expander": "\"{field}\"をオブジェクトフィールドに拡張します",
"xpack.ingestPipelines.processors.defaultDescription.drop": "エラーを返さずにドキュメントを破棄します",
"xpack.ingestPipelines.processors.defaultDescription.enrich": "\"{policy_name}\"ポリシーが\"{field}\"と一致した場合に、データを\"{target_field}\"に改善します",
"xpack.ingestPipelines.processors.defaultDescription.fail": "実行を停止する例外を発生させます",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -15736,7 +15736,6 @@
"xpack.ingestPipelines.processors.defaultDescription.dateIndexName.indexNamePrefixDefault.noPrefixValueLabel": "无前缀",
"xpack.ingestPipelines.processors.defaultDescription.dateIndexName.indexNamePrefixDefault.prefixValueLabel": "带前缀“{prefix}”",
"xpack.ingestPipelines.processors.defaultDescription.dissect": "从“{field}”提取匹配分解模式的值",
"xpack.ingestPipelines.processors.defaultDescription.dot_expander": "将“{field}”扩展成对象字段",
"xpack.ingestPipelines.processors.defaultDescription.drop": "丢弃文档而不返回错误",
"xpack.ingestPipelines.processors.defaultDescription.enrich": "如果策略“{policy_name}”匹配“{field}”,将数据扩充到“{target_field}”",
"xpack.ingestPipelines.processors.defaultDescription.fail": "引发使执行停止的异常",
Expand Down

0 comments on commit 7f364ea

Please sign in to comment.