-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add catalog diff connection read (#13918)
- Loading branch information
Showing
13 changed files
with
405 additions
and
582 deletions.
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
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
98 changes: 98 additions & 0 deletions
98
airbyte-server/src/main/java/io/airbyte/server/converters/CatalogDiffConverters.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,98 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.converters; | ||
|
||
import io.airbyte.api.model.generated.FieldNameAndSchema; | ||
import io.airbyte.api.model.generated.FieldSchemaUpdate; | ||
import io.airbyte.api.model.generated.FieldTransform; | ||
import io.airbyte.api.model.generated.StreamDescriptor; | ||
import io.airbyte.api.model.generated.StreamTransform; | ||
import io.airbyte.commons.enums.Enums; | ||
import io.airbyte.protocol.models.transform_models.FieldTransformType; | ||
import io.airbyte.protocol.models.transform_models.StreamTransformType; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Utility methods for converting between internal and API representation of catalog diffs. | ||
*/ | ||
public class CatalogDiffConverters { | ||
|
||
public static StreamTransform streamTransformToApi(final io.airbyte.protocol.models.transform_models.StreamTransform transform) { | ||
return new StreamTransform() | ||
.transformType(Enums.convertTo(transform.getTransformType(), StreamTransform.TransformTypeEnum.class)) | ||
.addStream(addStreamToApi(transform).orElse(null)) | ||
.removeStream(removeStreamToApi(transform).orElse(null)) | ||
.updateStream(updateStreamToApi(transform).orElse(null)); | ||
} | ||
|
||
public static Optional<StreamDescriptor> addStreamToApi(final io.airbyte.protocol.models.transform_models.StreamTransform transform) { | ||
if (transform.getTransformType() == StreamTransformType.ADD_STREAM) { | ||
return Optional.ofNullable(ProtocolConverters.streamDescriptorToApi(transform.getAddStreamTransform().getStreamDescriptor())); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
public static Optional<StreamDescriptor> removeStreamToApi(final io.airbyte.protocol.models.transform_models.StreamTransform transform) { | ||
if (transform.getTransformType() == StreamTransformType.REMOVE_STREAM) { | ||
return Optional.ofNullable(ProtocolConverters.streamDescriptorToApi(transform.getRemoveStreamTransform().getStreamDescriptor())); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
public static Optional<List<FieldTransform>> updateStreamToApi(final io.airbyte.protocol.models.transform_models.StreamTransform transform) { | ||
if (transform.getTransformType() == StreamTransformType.UPDATE_STREAM) { | ||
return Optional.ofNullable(transform.getUpdateStreamTransform() | ||
.getFieldTransforms() | ||
.stream() | ||
.map(CatalogDiffConverters::fieldTransformToApi) | ||
.toList()); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
public static FieldTransform fieldTransformToApi(final io.airbyte.protocol.models.transform_models.FieldTransform transform) { | ||
return new FieldTransform() | ||
.transformType(Enums.convertTo(transform.getTransformType(), FieldTransform.TransformTypeEnum.class)) | ||
.addField(addFieldToApi(transform).orElse(null)) | ||
.removeField(removeFieldToApi(transform).orElse(null)) | ||
.updateFieldSchema(updateFieldToApi(transform).orElse(null)); | ||
} | ||
|
||
private static Optional<FieldNameAndSchema> addFieldToApi(final io.airbyte.protocol.models.transform_models.FieldTransform transform) { | ||
if (transform.getTransformType() == FieldTransformType.ADD_FIELD) { | ||
return Optional.of(new FieldNameAndSchema() | ||
.fieldName(transform.getAddFieldTransform().getFieldName()) | ||
.fieldSchema(transform.getAddFieldTransform().getSchema())); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
private static Optional<FieldNameAndSchema> removeFieldToApi(final io.airbyte.protocol.models.transform_models.FieldTransform transform) { | ||
if (transform.getTransformType() == FieldTransformType.REMOVE_FIELD) { | ||
return Optional.of(new FieldNameAndSchema() | ||
.fieldName(transform.getRemoveFieldTransform().getFieldName()) | ||
.fieldSchema(transform.getRemoveFieldTransform().getSchema())); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
private static Optional<FieldSchemaUpdate> updateFieldToApi(final io.airbyte.protocol.models.transform_models.FieldTransform transform) { | ||
if (transform.getTransformType() == FieldTransformType.UPDATE_FIELD) { | ||
return Optional.of(new FieldSchemaUpdate() | ||
.fieldName(transform.getUpdateFieldTransform().getFieldName()) | ||
.oldSchema(transform.getUpdateFieldTransform().getOldSchema()) | ||
.newSchema(transform.getUpdateFieldTransform().getNewSchema())); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
airbyte-server/src/main/java/io/airbyte/server/converters/ProtocolConverters.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,18 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.converters; | ||
|
||
import io.airbyte.api.model.generated.StreamDescriptor; | ||
|
||
/** | ||
* Utilities that convert protocol types into API representations of the protocol type. | ||
*/ | ||
public class ProtocolConverters { | ||
|
||
public static StreamDescriptor streamDescriptorToApi(final io.airbyte.protocol.models.StreamDescriptor protocolStreamDescriptor) { | ||
return new StreamDescriptor().name(protocolStreamDescriptor.getName()).namespace(protocolStreamDescriptor.getNamespace()); | ||
} | ||
|
||
} |
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.