-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 Oracle: change table limit and format record data #5542
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
94efc9a
change oracle dest connector
marcosmarxm 9c5e179
remove container to run tests add depency to secrets/config.json
marcosmarxm ca7fd95
correct functions in tests
marcosmarxm fe88f45
gradlew format
marcosmarxm 62f70b8
Merge branch 'master' into marcosmarxm/oracle-dest
marcosmarxm 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,72 +25,46 @@ | |
package io.airbyte.integrations.destination.oracle; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import io.airbyte.commons.io.IOs; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.db.Database; | ||
import io.airbyte.db.Databases; | ||
import io.airbyte.integrations.destination.ExtendedNameTransformer; | ||
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest; | ||
import java.nio.file.Path; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.jooq.JSONFormat; | ||
import org.jooq.JSONFormat.RecordFormat; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.OracleContainer; | ||
|
||
public class OracleIntegrationTest extends DestinationAcceptanceTest { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(OracleIntegrationTest.class); | ||
private static final JSONFormat JSON_FORMAT = new JSONFormat().recordFormat(RecordFormat.OBJECT); | ||
|
||
private static OracleContainer db; | ||
private static JsonNode baseConfig; | ||
private ExtendedNameTransformer namingResolver = new OracleNameTransformer(); | ||
private JsonNode config; | ||
private static JsonNode config; | ||
|
||
@BeforeAll | ||
protected static void init() { | ||
db = new OracleContainer("epiclabs/docker-oracle-xe-11g"); | ||
db.start(); | ||
public JsonNode getStaticConfig() { | ||
return Jsons.deserialize(IOs.readFile(Path.of("secrets/config.json"))); | ||
} | ||
|
||
@Override | ||
protected String getImageName() { | ||
return "airbyte/destination-oracle:dev"; | ||
} | ||
|
||
private JsonNode getConfig(OracleContainer db) { | ||
return Jsons.jsonNode(ImmutableMap.builder() | ||
.put("host", db.getHost()) | ||
.put("port", db.getFirstMappedPort()) | ||
.put("username", db.getUsername()) | ||
.put("password", db.getPassword()) | ||
.put("schema", "testSchema") | ||
.put("sid", db.getSid()) | ||
.build()); | ||
} | ||
|
||
@Override | ||
protected JsonNode getConfig() { | ||
return config; | ||
} | ||
|
||
@Override | ||
protected JsonNode getFailCheckConfig() { | ||
return Jsons.jsonNode(ImmutableMap.builder() | ||
.put("host", db.getHost()) | ||
.put("username", db.getUsername()) | ||
.put("password", "wrong password") | ||
.put("schema", "public") | ||
.put("port", db.getFirstMappedPort()) | ||
.put("sid", db.getSid()) | ||
.build()); | ||
} | ||
|
||
@Override | ||
protected List<JsonNode> retrieveRecords(TestDestinationEnv env, String streamName, String namespace, JsonNode streamSchema) throws Exception { | ||
return retrieveRecordsFromTable(namingResolver.getRawTableName(streamName), namespace) | ||
|
@@ -116,6 +90,13 @@ protected List<JsonNode> retrieveNormalizedRecords(TestDestinationEnv env, Strin | |
return retrieveRecordsFromTable(tableName, namespace); | ||
} | ||
|
||
@Override | ||
protected JsonNode getFailCheckConfig() { | ||
final JsonNode invalidConfig = Jsons.clone(config); | ||
((ObjectNode) invalidConfig).put("password", "wrong password"); | ||
return invalidConfig; | ||
} | ||
|
||
@Override | ||
protected List<String> resolveIdentifier(String identifier) { | ||
final List<String> result = new ArrayList<>(); | ||
|
@@ -130,28 +111,27 @@ protected List<String> resolveIdentifier(String identifier) { | |
} | ||
|
||
private List<JsonNode> retrieveRecordsFromTable(String tableName, String schemaName) throws SQLException { | ||
List<org.jooq.Record> result = Databases.createOracleDatabase(db.getUsername(), db.getPassword(), db.getJdbcUrl()) | ||
.query(ctx -> ctx | ||
.fetch(String.format("SELECT * FROM %s.%s ORDER BY %s ASC", schemaName, tableName, OracleDestination.COLUMN_NAME_EMITTED_AT)) | ||
.stream() | ||
.collect(Collectors.toList())); | ||
List<org.jooq.Record> result = getDatabase().query(ctx -> ctx | ||
.fetch(String.format("SELECT * FROM %s.%s ORDER BY %s ASC", schemaName, tableName, OracleDestination.COLUMN_NAME_EMITTED_AT)) | ||
.stream() | ||
.collect(Collectors.toList())); | ||
return result | ||
.stream() | ||
.map(r -> r.formatJSON(JSON_FORMAT)) | ||
.map(Jsons::deserialize) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static Database getDatabase(JsonNode config) { | ||
private static Database getDatabase() { | ||
// todo (cgardens) - rework this abstraction so that we do not have to pass a null into the | ||
// constructor. at least explicitly handle it, even if the impl doesn't change. | ||
return Databases.createDatabase( | ||
config.get("username").asText(), | ||
config.get("password").asText(), | ||
baseConfig.get("username").asText(), | ||
baseConfig.get("password").asText(), | ||
String.format("jdbc:oracle:thin:@//%s:%s/%s", | ||
config.get("host").asText(), | ||
config.get("port").asText(), | ||
config.get("sid").asText()), | ||
baseConfig.get("host").asText(), | ||
baseConfig.get("port").asText(), | ||
baseConfig.get("sid").asText()), | ||
"oracle.jdbc.driver.OracleDriver", | ||
null); | ||
} | ||
|
@@ -172,21 +152,18 @@ private List<String> getAllTables(Database db) { | |
|
||
@Override | ||
protected void setup(TestDestinationEnv testEnv) throws SQLException { | ||
config = getConfig(db); | ||
|
||
final Database database = getDatabase(config); | ||
database.query(ctx -> { | ||
ctx.execute("alter database default tablespace users"); | ||
return null; | ||
}); | ||
Comment on lines
-178
to
-181
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. I removed this because requires a very strong privilege to execute it. I'm running the AWS instance where I can change the permission of my admin user. |
||
// config = getConfig(db); | ||
baseConfig = getStaticConfig(); | ||
config = Jsons.clone(baseConfig); | ||
final Database database = getDatabase(); | ||
allTables = getAllTables(database); | ||
} | ||
|
||
@Override | ||
protected void tearDown(TestDestinationEnv testEnv) { | ||
config = getConfig(db); | ||
config = getStaticConfig(); | ||
|
||
final Database database = getDatabase(config); | ||
final Database database = getDatabase(); | ||
var tables = getAllTables(database); | ||
tables.removeAll(allTables); | ||
try { | ||
|
@@ -201,10 +178,4 @@ protected void tearDown(TestDestinationEnv testEnv) { | |
} | ||
} | ||
|
||
@AfterAll | ||
static void cleanUp() { | ||
db.stop(); | ||
db.close(); | ||
} | ||
|
||
} |
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.
this is modifying the data itself. Is there any way around this?
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.
agreed with sherif. the name transformer was intended to transform "names" (e.g. table names and column names). in general we want to avoid modifying the data if at all possible.
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'm doing the same as in BigQuery destination (this change the json path to remove any non-supported char in the stream name not change the original data):
airbyte/airbyte-integrations/connectors/destination-bigquery/src/main/java/io/airbyte/integrations/destination/bigquery/BigQueryRecordConsumer.java
Lines 124 to 129 in 1954284
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 updated the comment in PR, sorry the confuction: Oracle 19 json_value doesnt allow ' or " in keys so it we need to clean
some recordsthe key name using a formatted function. Example:column`_'with\"_quotes
becomescolumn___with\__quotes
.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.
Example of
AIRBYTE_DATA
saved using this function. The original data is kept but to run normalization I need a "cleaned" field name.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.
fair enough. this feels like a weird sacrifice we are making for dbt.
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 is something needed for the destination itself because the source is writing a json key not supported.