-
Notifications
You must be signed in to change notification settings - Fork 4.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
On-the-fly migrations of persisted catalogs #21757
Merged
gosusnp
merged 19 commits into
gosusnp/platform-use-protocol-v1-the-quick-way
from
gosusnp/on-the-fly-catalog-migrations
Jan 27, 2023
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
38a0276
On the fly catalog migration for normalization activity
gosusnp 8d294e4
On the fly catalog migration for job persistence
gosusnp bac097b
On the fly migration for standard sync persistence
gosusnp d2da503
On the fly migration for airbyte catalogs
gosusnp 5c2323d
Refactor code to share JsonSchema traversal
gosusnp 884f083
Add V0 Data type search function
gosusnp b078ceb
PMD and Format
gosusnp 8ca1949
Fix getOrInsertActorCatalog and ConfigRepositoryE2E tests
gosusnp a7fab2d
Null-proofing CatalogMigrationV1Helper
gosusnp 2b2a084
More null checks
gosusnp eb9f979
Fix test
gosusnp 2cb231e
Format
gosusnp 9fa77f1
Add data type v1 support to the FE
gosusnp accb6d1
Changes AC test check to check exited ps (#21672)
supertopher 277f8e4
Merge remote-tracking branch 'origin/gosusnp/platform-use-protocol-v1…
gosusnp fe45017
Move wellknown types mapping to the utility function
gosusnp d3cd495
use protocolv1 normalization
edgao 6fbf2fa
Merge branch 'gosusnp/platform-use-protocol-v1-the-quick-way' into go…
gosusnp e434498
Merge branch 'gosusnp/platform-use-protocol-v1-the-quick-way' into go…
gosusnp 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
121 changes: 121 additions & 0 deletions
121
...col/src/main/java/io/airbyte/commons/protocol/migrations/v1/CatalogMigrationV1Helper.java
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,121 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.commons.protocol.migrations.v1; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.commons.protocol.migrations.util.SchemaMigrations; | ||
import io.airbyte.protocol.models.AirbyteCatalog; | ||
import io.airbyte.protocol.models.AirbyteStream; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteStream; | ||
|
||
/** | ||
* For the v0 to v1 migration, it appears that we are persisting some protocol objects without | ||
* version. Until this gets addressed more properly, this class contains the helper functions used | ||
* to handle this on the fly migration. | ||
* | ||
* Once persisted objects are versioned, this code should be deleted. | ||
*/ | ||
public class CatalogMigrationV1Helper { | ||
|
||
/** | ||
* Performs an in-place migration of the schema from v0 to v1 if v0 data types are detected | ||
* | ||
* @param configuredAirbyteCatalog to migrate | ||
*/ | ||
public static void upgradeSchemaIfNeeded(final ConfiguredAirbyteCatalog configuredAirbyteCatalog) { | ||
if (containsV0DataTypes(configuredAirbyteCatalog)) { | ||
upgradeSchema(configuredAirbyteCatalog); | ||
} | ||
} | ||
|
||
/** | ||
* Performs an in-place migration of the schema from v0 to v1 if v0 data types are detected | ||
* | ||
* @param airbyteCatalog to migrate | ||
*/ | ||
public static void upgradeSchemaIfNeeded(final AirbyteCatalog airbyteCatalog) { | ||
if (containsV0DataTypes(airbyteCatalog)) { | ||
upgradeSchema(airbyteCatalog); | ||
} | ||
} | ||
|
||
/** | ||
* Performs an in-place migration of the schema from v0 to v1 | ||
* | ||
* @param configuredAirbyteCatalog to migrate | ||
*/ | ||
private static void upgradeSchema(final ConfiguredAirbyteCatalog configuredAirbyteCatalog) { | ||
for (final var stream : configuredAirbyteCatalog.getStreams()) { | ||
SchemaMigrationV1.upgradeSchema(stream.getStream().getJsonSchema()); | ||
} | ||
} | ||
|
||
/** | ||
* Performs an in-place migration of the schema from v0 to v1 | ||
* | ||
* @param airbyteCatalog to migrate | ||
*/ | ||
private static void upgradeSchema(final AirbyteCatalog airbyteCatalog) { | ||
for (final var stream : airbyteCatalog.getStreams()) { | ||
SchemaMigrationV1.upgradeSchema(stream.getJsonSchema()); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if catalog contains v0 data types | ||
*/ | ||
private static boolean containsV0DataTypes(final ConfiguredAirbyteCatalog configuredAirbyteCatalog) { | ||
if (configuredAirbyteCatalog == null) { | ||
return false; | ||
} | ||
|
||
return configuredAirbyteCatalog | ||
.getStreams() | ||
.stream().findFirst() | ||
.map(ConfiguredAirbyteStream::getStream) | ||
.map(CatalogMigrationV1Helper::streamContainsV0DataTypes) | ||
.orElse(false); | ||
} | ||
|
||
/** | ||
* Returns true if catalog contains v0 data types | ||
*/ | ||
private static boolean containsV0DataTypes(final AirbyteCatalog airbyteCatalog) { | ||
if (airbyteCatalog == null) { | ||
return false; | ||
} | ||
|
||
return airbyteCatalog | ||
.getStreams() | ||
.stream().findFirst() | ||
.map(CatalogMigrationV1Helper::streamContainsV0DataTypes) | ||
.orElse(false); | ||
} | ||
|
||
private static boolean streamContainsV0DataTypes(final AirbyteStream airbyteStream) { | ||
if (airbyteStream == null || airbyteStream.getJsonSchema() == null) { | ||
return false; | ||
} | ||
return hasV0DataType(airbyteStream.getJsonSchema()); | ||
} | ||
|
||
/** | ||
* Performs of search of a v0 data type node, returns true at the first node found. | ||
*/ | ||
private static boolean hasV0DataType(final JsonNode schema) { | ||
if (SchemaMigrationV1.isPrimitiveTypeDeclaration(schema)) { | ||
return true; | ||
} | ||
|
||
for (final JsonNode subSchema : SchemaMigrations.findSubschemas(schema)) { | ||
if (hasV0DataType(subSchema)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.
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.
This seems risky, granted this is a
private
method so there is less risk, but I wonder if this code should be moved to thegetOrInsertActorCatalog
method to prevent any future issues from occurring.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 am open to inlining this in
getOrInsertActorCatalog
. One extra note is that this behavior (the insert only inserts when it's actually different) is currently tested.