-
Notifications
You must be signed in to change notification settings - Fork 4.6k
S3 destination: Updating processing data types for Avro/Parquet formats #13483
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
Merged
sashaNeshcheret
merged 20 commits into
master
from
omneshcheret/11627-procesing-number-data-types
Jun 14, 2022
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8aac27f
S3 destination: Updating processing data types for Avro/Parquet formats
sashaNeshcheret fe984ac
S3 destination: handle comparing data types
sashaNeshcheret 7603028
S3 destination: clean code
sashaNeshcheret 0022e62
S3 destination: clean code
sashaNeshcheret 5c10dcd
S3 destination: handle case with unexpected json schema type
sashaNeshcheret b7e007d
S3 destination: clean code
sashaNeshcheret 34fa32c
S3 destination: Extract the same logic for Avro/Parquet formats to se…
sashaNeshcheret 66403b5
S3 destination: clean code
sashaNeshcheret fe93cb0
S3 destination: clean code
sashaNeshcheret e6bee9d
GCS destination: Update data types processing for Avro/Parquet formats
sashaNeshcheret 924cdee
GCS destination: clean redundant code
sashaNeshcheret ec7528d
S3 destination: handle case with numbers inside array
sashaNeshcheret 7a303e2
S3 destination: clean code
sashaNeshcheret 127f64a
S3 destination: add unit test
sashaNeshcheret ac0bc53
S3 destination: update unit test cases with number types.
sashaNeshcheret 6710a41
S3 destination: update unit tests.
sashaNeshcheret 6a33d7a
S3 destination: bump version for s3 and gcs
sashaNeshcheret 17110bc
auto-bump connector version
octavia-squidington-iii 34171fa
auto-bump connector version
octavia-squidington-iii c493117
Merge branch 'omneshcheret/11627-procesing-number-data-types' of http…
octavia-squidington-iii 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 hidden or 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 hidden or 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 hidden or 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
99 changes: 99 additions & 0 deletions
99
...n/java/io/airbyte/integrations/destination/s3/S3AvroParquetDestinationAcceptanceTest.java
This file contains hidden or 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,99 @@ | ||
package io.airbyte.integrations.destination.s3; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.commons.resources.MoreResources; | ||
import io.airbyte.integrations.destination.s3.avro.JsonSchemaType; | ||
import io.airbyte.protocol.models.AirbyteCatalog; | ||
import io.airbyte.protocol.models.AirbyteMessage; | ||
import io.airbyte.protocol.models.AirbyteStream; | ||
import io.airbyte.protocol.models.CatalogHelpers; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.apache.avro.Schema; | ||
import org.apache.avro.Schema.Type; | ||
import org.apache.avro.generic.GenericData.Record; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public abstract class S3AvroParquetDestinationAcceptanceTest extends S3DestinationAcceptanceTest{ | ||
|
||
protected S3AvroParquetDestinationAcceptanceTest(S3Format s3Format) { | ||
super(s3Format); | ||
} | ||
|
||
@Test | ||
public void testNumberDataType() throws Exception { | ||
final AirbyteCatalog catalog = readCatalogFromFile("number_data_type_test_catalog.json"); | ||
final ConfiguredAirbyteCatalog configuredCatalog = CatalogHelpers.toDefaultConfiguredCatalog(catalog); | ||
final List<AirbyteMessage> messages = readMessagesFromFile("number_data_type_test_messages.txt"); | ||
|
||
final JsonNode config = getConfig(); | ||
final String defaultSchema = getDefaultSchema(config); | ||
runSyncAndVerifyStateOutput(config, messages, configuredCatalog, false); | ||
|
||
for (final AirbyteStream stream : catalog.getStreams()) { | ||
final String streamName = stream.getName(); | ||
final String schema = stream.getNamespace() != null ? stream.getNamespace() : defaultSchema; | ||
|
||
Set<Type> actualSchemaTypes = retrieveDataTypesFromPersistedFiles(streamName, schema); | ||
Optional<Type> actualSchemaTypesWithoutNull = actualSchemaTypes.stream().filter(type -> !type.equals(Type.NULL)).findAny(); | ||
|
||
JsonNode fieldDefinition = stream.getJsonSchema().get("properties").get("data"); | ||
List<Type> expectedTypeList = getExpectedSchemaType(fieldDefinition); | ||
assertEquals(1, expectedTypeList.size(), "Several not null data types are not supported for single stream"); | ||
assertTrue(actualSchemaTypesWithoutNull.isPresent()); | ||
assertEquals(expectedTypeList.get(0), actualSchemaTypesWithoutNull.get()); | ||
} | ||
} | ||
|
||
private List<Type> getExpectedSchemaType(JsonNode fieldDefinition) { | ||
final JsonNode typeProperty = fieldDefinition.get("type"); | ||
final JsonNode airbyteTypeProperty = fieldDefinition.get("airbyte_type"); | ||
final String airbyteTypePropertyText = airbyteTypeProperty == null ? null : airbyteTypeProperty.asText(); | ||
return Arrays.stream(JsonSchemaType.values()) | ||
.filter( | ||
value -> value.getJsonSchemaType().equals(typeProperty.asText()) && compareAirbyteTypes(airbyteTypePropertyText, value)) | ||
.map(JsonSchemaType::getAvroType) | ||
.toList(); | ||
} | ||
|
||
private boolean compareAirbyteTypes(String airbyteTypePropertyText, JsonSchemaType value) { | ||
if (airbyteTypePropertyText == null){ | ||
return value.getJsonSchemaAirbyteType() == null; | ||
} | ||
return airbyteTypePropertyText.equals(value.getJsonSchemaAirbyteType()); | ||
} | ||
|
||
private AirbyteCatalog readCatalogFromFile(final String catalogFilename) throws IOException { | ||
return Jsons.deserialize(MoreResources.readResource(catalogFilename), AirbyteCatalog.class); | ||
} | ||
|
||
private List<AirbyteMessage> readMessagesFromFile(final String messagesFilename) throws IOException { | ||
return MoreResources.readResource(messagesFilename).lines() | ||
.map(record -> Jsons.deserialize(record, AirbyteMessage.class)).collect(Collectors.toList()); | ||
} | ||
|
||
protected abstract Set<Type> retrieveDataTypesFromPersistedFiles(final String streamName, final String namespace) throws Exception; | ||
|
||
protected Set<Type> getTypes(Record record) { | ||
List<Schema> listAvroTypes = record | ||
.getSchema() | ||
.getField("data") | ||
.schema() | ||
.getTypes(); | ||
|
||
return listAvroTypes | ||
.stream() | ||
.map(Schema::getType) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
} |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.