Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edgao committed Jul 17, 2023
1 parent 2d3b86a commit 8154cb6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

package io.airbyte.integrations.base.destination.typing_deduping;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.JsonNode;
import io.airbyte.commons.json.Jsons;
Expand All @@ -16,7 +15,6 @@
import io.airbyte.protocol.models.v0.ConfiguredAirbyteStream;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

class CatalogParserTest {
Expand All @@ -36,30 +34,12 @@ public void setup() {
String namespace = invocation.getArgument(0);
String name = invocation.getArgument(1);
String rawNamespace = invocation.getArgument(1);
return new StreamId(namespace, name, rawNamespace, namespace + "_" + name, namespace, name);
return new StreamId(namespace, name, rawNamespace, namespace + "_abab_" + name, namespace, name);
});

parser = new CatalogParser(sqlGenerator);
}

/**
* Both these streams want the same raw table name ("a_b_c"). Verify that they don't actually use
* the same raw table.
*/
@Disabled("This feature is not yet supported; see https://github.com/airbytehq/airbyte/issues/27798")
@Test
public void rawNameCollision() {
final ConfiguredAirbyteCatalog catalog = new ConfiguredAirbyteCatalog().withStreams(List.of(
stream("a", "b_c"),
stream("a_b", "c")));

final ParsedCatalog parsedCatalog = parser.parseCatalog(catalog);

assertNotEquals(
parsedCatalog.streams().get(0).id().rawName(),
parsedCatalog.streams().get(1).id().rawName());
}

/**
* Both these streams will write to the same final table name ("foofoo"). Verify that they don't
* actually use the same tablename.
Expand All @@ -73,7 +53,7 @@ public void finalNameCollision() {

// emulate quoting logic that causes a name collision
String quotedName = originalName.replaceAll("bar", "");
return new StreamId(originalNamespace, quotedName, originalRawNamespace, originalNamespace + "_" + quotedName, originalNamespace, originalName);
return new StreamId(originalNamespace, quotedName, originalRawNamespace, originalNamespace + "_abab_" + quotedName, originalNamespace, originalName);
});
final ConfiguredAirbyteCatalog catalog = new ConfiguredAirbyteCatalog().withStreams(List.of(
stream("a", "foobarfoo"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.airbyte.integrations.base.destination.typing_deduping;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class StreamIdTest {

/**
* Both these streams naively want the same raw table name ("aaa_abab_bbb_abab_ccc"). Verify that they don't actually use
* the same raw table.
*/
@Test
public void rawNameCollision() {
String stream1 = StreamId.concatenateRawTableName("aaa_abab_bbb", "ccc");
String stream2 = StreamId.concatenateRawTableName("aaa", "bbb_abab_ccc");

assertEquals("aaa_abab_bbb_ab__ab_ccc", stream1);
assertEquals("aaa_ab__ab_bbb_abab_ccc", stream2);
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package io.airbyte.integrations.destination.bigquery.typing_deduping;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.DatasetId;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.TableId;
import com.google.cloud.bigquery.TableResult;
import io.airbyte.commons.json.Jsons;
import io.airbyte.integrations.base.destination.typing_deduping.BaseTypingDedupingTest;
import io.airbyte.integrations.destination.bigquery.BigQueryDestination;
import io.airbyte.integrations.destination.bigquery.BigQueryDestinationTestUtils;
import io.airbyte.integrations.destination.bigquery.BigQueryUtils;
import java.io.IOException;
import java.nio.file.Path;
import java.time.Instant;
import java.util.LinkedHashMap;
import java.util.List;

public abstract class AbstractBigQueryTypingDedupingTest extends BaseTypingDedupingTest {
Expand All @@ -42,7 +38,7 @@ protected List<JsonNode> dumpRawTableRecords(String streamNamespace, String stre
if (streamNamespace == null) {
streamNamespace = BigQueryUtils.getDatasetId(getConfig());
}
TableResult result = bq.query(QueryJobConfiguration.of("SELECT * FROM airbyte." + streamNamespace + "_" + streamName));
TableResult result = bq.query(QueryJobConfiguration.of("SELECT * FROM airbyte." + streamNamespace + "_ab__ab_" + streamName));
return BigQuerySqlGeneratorIntegrationTest.toJsonRecords(result);
}

Expand Down

0 comments on commit 8154cb6

Please sign in to comment.