-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Destination BigQuery: Accept Dataset ID field prefixed by Project ID #8383
Merged
mkhokh-33
merged 17 commits into
airbytehq:master
from
koji-m:parsing-dataset-names-in-bq
Jan 18, 2022
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7f7b220
add Dataset ID parse method
koji-m 69b510d
add BigQuery Destination unit test
koji-m 5d99d33
update change log
koji-m ddd1425
Merge branch 'master' into parsing-dataset-names-in-bq
koji-m d3d9cda
fit to the latest code base
koji-m f4ced62
update change log
koji-m a3838eb
change var name to const name
koji-m af80798
change public method to private
koji-m 4c78cb5
add test cases for testGetDatasetIdFail
koji-m 7171871
add integration test for dataset-id prefixed with project-id
koji-m 85ab152
Merge branch 'master' into parsing-dataset-names-in-bq
koji-m c505823
fix getDatasetId
koji-m 686e2c7
add comment to parameterized test provider
koji-m d4522f4
Merge branch 'parsing-dataset-names-in-bq' of github.com:koji-m/airby…
koji-m 6c26a63
update docker image versions
koji-m 25bf817
update docker image versions again
koji-m 5eefebe
Merge branch 'master' into parsing-dataset-names-in-bq
koji-m 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
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
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 |
---|---|---|
|
@@ -55,13 +55,18 @@ | |
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import java.util.stream.StreamSupport; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -197,16 +202,20 @@ void testSpec() throws Exception { | |
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void testCheckSuccess() { | ||
@ParameterizedTest | ||
@MethodSource("datasetIdResetterProvider") | ||
void testCheckSuccess(DatasetIdResetter resetDatasetId) { | ||
resetDatasetId.accept(config); | ||
final AirbyteConnectionStatus actual = new BigQueryDestination().check(config); | ||
final AirbyteConnectionStatus expected = new AirbyteConnectionStatus().withStatus(Status.SUCCEEDED); | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void testCheckFailure() { | ||
@ParameterizedTest | ||
@MethodSource("datasetIdResetterProvider") | ||
void testCheckFailure(DatasetIdResetter resetDatasetId) { | ||
((ObjectNode) config).put(BigQueryConsts.CONFIG_PROJECT_ID, "fake"); | ||
resetDatasetId.accept(config); | ||
final AirbyteConnectionStatus actual = new BigQueryDestination().check(config); | ||
final String actualMessage = actual.getMessage(); | ||
LOGGER.info("Checking expected failure message:" + actualMessage); | ||
|
@@ -215,8 +224,10 @@ void testCheckFailure() { | |
assertEquals(expected, actual.withMessage("")); | ||
} | ||
|
||
@Test | ||
void testWriteSuccess() throws Exception { | ||
@ParameterizedTest | ||
@MethodSource("datasetIdResetterProvider") | ||
void testWriteSuccess(DatasetIdResetter resetDatasetId) throws Exception { | ||
resetDatasetId.accept(config); | ||
final BigQueryDestination destination = new BigQueryDestination(); | ||
final AirbyteMessageConsumer consumer = destination.getConsumer(config, catalog, Destination::defaultOutputRecordCollector); | ||
|
||
|
@@ -244,8 +255,10 @@ void testWriteSuccess() throws Exception { | |
.collect(Collectors.toList())); | ||
} | ||
|
||
@Test | ||
void testWriteFailure() throws Exception { | ||
@ParameterizedTest | ||
@MethodSource("datasetIdResetterProvider") | ||
void testWriteFailure(DatasetIdResetter resetDatasetId) throws Exception { | ||
resetDatasetId.accept(config); | ||
// hack to force an exception to be thrown from within the consumer. | ||
final AirbyteMessage spiedMessage = spy(MESSAGE_USERS1); | ||
doThrow(new RuntimeException()).when(spiedMessage).getRecord(); | ||
|
@@ -305,8 +318,10 @@ private List<JsonNode> retrieveRecords(final String tableName) throws Exception | |
.collect(Collectors.toList()); | ||
} | ||
|
||
@Test | ||
void testWritePartitionOverUnpartitioned() throws Exception { | ||
@ParameterizedTest | ||
@MethodSource("datasetIdResetterProvider") | ||
void testWritePartitionOverUnpartitioned(DatasetIdResetter resetDatasetId) throws Exception { | ||
resetDatasetId.accept(config); | ||
final String raw_table_name = String.format("_airbyte_raw_%s", USERS_STREAM_NAME); | ||
createUnpartitionedTable(bigquery, dataset, raw_table_name); | ||
assertFalse(isTablePartitioned(bigquery, dataset, raw_table_name)); | ||
|
@@ -369,4 +384,30 @@ private boolean isTablePartitioned(final BigQuery bigquery, final Dataset datase | |
return false; | ||
} | ||
|
||
private static class DatasetIdResetter { | ||
private Consumer<JsonNode> consumer; | ||
|
||
DatasetIdResetter(Consumer<JsonNode> consumer) { | ||
this.consumer = consumer; | ||
} | ||
|
||
public void accept(JsonNode config) { | ||
consumer.accept(config); | ||
} | ||
} | ||
|
||
private static Stream<Arguments> datasetIdResetterProvider() { | ||
// parameterized test with two dataset-id patterns: `dataset_id` and `project-id:dataset_id` | ||
return Stream.of( | ||
Arguments.arguments(new DatasetIdResetter(config -> {})), | ||
Arguments.arguments(new DatasetIdResetter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a comment to explain what this is testing |
||
config -> { | ||
String projectId = ((ObjectNode) config).get(BigQueryConsts.CONFIG_PROJECT_ID).asText(); | ||
String datasetId = ((ObjectNode) config).get(BigQueryConsts.CONFIG_DATASET_ID).asText(); | ||
((ObjectNode) config).put(BigQueryConsts.CONFIG_DATASET_ID, | ||
String.format("%s:%s", projectId, datasetId)); | ||
} | ||
)) | ||
); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...igquery/src/test/java/io/airbyte/integrations/destination/bigquery/BigQueryUtilsTest.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,69 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.bigquery; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.commons.json.Jsons; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class BigQueryUtilsTest { | ||
|
||
private ImmutableMap.Builder<Object, Object> configMapBuilder; | ||
|
||
@BeforeEach | ||
public void init() { | ||
configMapBuilder = ImmutableMap.builder() | ||
.put(BigQueryConsts.CONFIG_CREDS, "test_secret") | ||
.put(BigQueryConsts.CONFIG_DATASET_LOCATION, "US"); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("validBigQueryIdProvider") | ||
public void testGetDatasetIdSuccess(String projectId, String datasetId, String expected) throws Exception { | ||
JsonNode config = Jsons.jsonNode(configMapBuilder | ||
.put(BigQueryConsts.CONFIG_PROJECT_ID, projectId) | ||
.put(BigQueryConsts.CONFIG_DATASET_ID, datasetId) | ||
.build()); | ||
|
||
String actual = BigQueryUtils.getDatasetId(config); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("invalidBigQueryIdProvider") | ||
public void testGetDatasetIdFail(String projectId, String datasetId, String expected) throws Exception { | ||
JsonNode config = Jsons.jsonNode(configMapBuilder | ||
.put(BigQueryConsts.CONFIG_PROJECT_ID, projectId) | ||
.put(BigQueryConsts.CONFIG_DATASET_ID, datasetId) | ||
.build()); | ||
|
||
Exception exception = assertThrows(IllegalArgumentException.class, () -> BigQueryUtils.getDatasetId(config)); | ||
|
||
assertEquals(expected, exception.getMessage()); | ||
} | ||
|
||
private static Stream<Arguments> validBigQueryIdProvider() { | ||
return Stream.of( | ||
Arguments.arguments("my-project", "my_dataset", "my_dataset"), | ||
Arguments.arguments("my-project", "my-project:my_dataset", "my_dataset")); | ||
} | ||
|
||
private static Stream<Arguments> invalidBigQueryIdProvider() { | ||
return Stream.of( | ||
Arguments.arguments("my-project", ":my_dataset", | ||
"Project ID included in Dataset ID must match Project ID field's value: Project ID is `my-project`, but you specified `` in Dataset ID"), | ||
Arguments.arguments("my-project", "your-project:my_dataset", | ||
"Project ID included in Dataset ID must match Project ID field's value: Project ID is `my-project`, but you specified `your-project` in Dataset ID")); | ||
} | ||
} |
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.
BigQueryUtils.getDatasetId(config) used in 2 cases
Could you pls consider to add integration test to BigQueryDestinationTest to check that: