-
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
[ZDT] Pickup updated types only #161123
Merged
gsoldevila
merged 3 commits into
elastic:main
from
gsoldevila:kbn-161067-pickup-updated-types-only
Jul 4, 2023
Merged
[ZDT] Pickup updated types only #161123
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...core-saved-objects-migration-server-internal/src/core/build_pickup_mappings_query.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { buildPickupMappingsQuery } from './build_pickup_mappings_query'; | ||
|
||
describe('buildPickupMappingsQuery', () => { | ||
describe('when no root fields have been updated', () => { | ||
it('builds a boolean query to select the updated types', () => { | ||
const query = buildPickupMappingsQuery({ | ||
rootFields: ['someRootField'], | ||
updatedFields: ['type1', 'type2'], | ||
}); | ||
|
||
expect(query).toEqual({ | ||
bool: { | ||
should: [{ term: { type: 'type1' } }, { term: { type: 'type2' } }], | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when some root fields have been updated', () => { | ||
it('returns undefined', () => { | ||
const query = buildPickupMappingsQuery({ | ||
rootFields: ['someRootField'], | ||
updatedFields: ['type1', 'type2', 'someRootField'], | ||
}); | ||
|
||
expect(query).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
...ects/core-saved-objects-migration-server-internal/src/core/build_pickup_mappings_query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; | ||
|
||
export const buildPickupMappingsQuery = ({ | ||
rootFields, | ||
updatedFields, | ||
}: { | ||
rootFields: string[]; | ||
updatedFields: string[]; | ||
}): QueryDslQueryContainer | undefined => { | ||
if (updatedFields.some((field) => rootFields.includes(field))) { | ||
// we are updating some root fields, update ALL documents (no filter query) | ||
return undefined; | ||
} | ||
|
||
// at this point, all updated fields correspond to SO types | ||
const updatedTypes = updatedFields; | ||
|
||
return { | ||
bool: { | ||
should: updatedTypes.map((type) => ({ term: { type } })), | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
NIT: Why passing
rootFields
as parameters? any value compared to just usingObject.keys(getBaseMappings().properties)
internally in this function? Is this only for testability?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.
Yeah, I was mainly thinking of testability, but I don't have a strong opinion.
I will simplify and build the
rootFields
internally.