-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 New destination: Yugabytedb (#18039)
* add yugabytedb destination connector * add dest def + add changelog * auto-bump connector version Co-authored-by: marcosmarxm <[email protected]> Co-authored-by: Marcos Marx <[email protected]> Co-authored-by: Octavia Squidington III <[email protected]>
- Loading branch information
1 parent
8afddb4
commit 72a642b
Showing
21 changed files
with
1,238 additions
and
1 deletion.
There are no files selected for viewing
409 changes: 409 additions & 0 deletions
409
airbyte-config/init/src/main/resources/icons/yugabytedb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
3 changes: 3 additions & 0 deletions
3
airbyte-integrations/connectors/destination-yugabytedb/.dockerignore
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,3 @@ | ||
* | ||
!Dockerfile | ||
!build |
18 changes: 18 additions & 0 deletions
18
airbyte-integrations/connectors/destination-yugabytedb/Dockerfile
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 @@ | ||
FROM airbyte/integration-base-java:dev AS build | ||
|
||
WORKDIR /airbyte | ||
ENV APPLICATION destination-yugabytedb | ||
|
||
COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar | ||
|
||
RUN tar xf ${APPLICATION}.tar --strip-components=1 && rm -rf ${APPLICATION}.tar | ||
|
||
FROM airbyte/integration-base-java:dev | ||
|
||
WORKDIR /airbyte | ||
ENV APPLICATION destination-yugabytedb | ||
|
||
COPY --from=build /airbyte /airbyte | ||
|
||
LABEL io.airbyte.version=0.1.0 | ||
LABEL io.airbyte.name=airbyte/destination-yugabytedb |
68 changes: 68 additions & 0 deletions
68
airbyte-integrations/connectors/destination-yugabytedb/README.md
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,68 @@ | ||
# Destination Yugabytedb | ||
|
||
This is the repository for the Yugabytedb destination connector in Java. | ||
For information about how to use this connector within Airbyte, see [the User Documentation](https://docs.airbyte.io/integrations/destinations/yugabytedb). | ||
|
||
## Local development | ||
|
||
#### Building via Gradle | ||
From the Airbyte repository root, run: | ||
``` | ||
./gradlew :airbyte-integrations:connectors:destination-yugabytedb:build | ||
``` | ||
|
||
#### Create credentials | ||
**If you are a community contributor**, generate the necessary credentials and place them in `secrets/config.json` conforming to the spec file in `src/main/resources/spec.json`. | ||
Note that the `secrets` directory is git-ignored by default, so there is no danger of accidentally checking in sensitive information. | ||
|
||
**If you are an Airbyte core member**, follow the [instructions](https://docs.airbyte.io/connector-development#using-credentials-in-ci) to set up the credentials. | ||
|
||
### Locally running the connector docker image | ||
|
||
#### Build | ||
Build the connector image via Gradle: | ||
``` | ||
./gradlew :airbyte-integrations:connectors:destination-yugabytedb:airbyteDocker | ||
``` | ||
When building via Gradle, the docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in | ||
the Dockerfile. | ||
|
||
#### Run | ||
Then run any of the connector commands as follows: | ||
``` | ||
docker run --rm airbyte/destination-yugabytedb:dev spec | ||
docker run --rm -v $(pwd)/secrets:/secrets airbyte/destination-yugabytedb:dev check --config /secrets/config.json | ||
docker run --rm -v $(pwd)/secrets:/secrets airbyte/destination-yugabytedb:dev discover --config /secrets/config.json | ||
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/destination-yugabytedb:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json | ||
``` | ||
|
||
## Testing | ||
We use `JUnit` for Java tests. | ||
|
||
### Unit and Integration Tests | ||
Place unit tests under `src/test/io/airbyte/integrations/destinations/yugabytedb`. | ||
|
||
#### Acceptance Tests | ||
Airbyte has a standard test suite that all destination connectors must pass. Implement the `TODO`s in | ||
`src/test-integration/java/io/airbyte/integrations/destinations/yugabytedbDestinationAcceptanceTest.java`. | ||
|
||
### Using gradle to run tests | ||
All commands should be run from airbyte project root. | ||
To run unit tests: | ||
``` | ||
./gradlew :airbyte-integrations:connectors:destination-yugabytedb:unitTest | ||
``` | ||
To run acceptance and custom integration tests: | ||
``` | ||
./gradlew :airbyte-integrations:connectors:destination-yugabytedb:integrationTest | ||
``` | ||
|
||
## Dependency Management | ||
|
||
### Publishing a new version of the connector | ||
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what? | ||
1. Make sure your changes are passing unit and integration tests. | ||
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)). | ||
1. Create a Pull Request. | ||
1. Pat yourself on the back for being an awesome contributor. | ||
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master. |
Empty file.
32 changes: 32 additions & 0 deletions
32
airbyte-integrations/connectors/destination-yugabytedb/build.gradle
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,32 @@ | ||
plugins { | ||
id 'application' | ||
id 'airbyte-docker' | ||
id 'airbyte-integration-test-java' | ||
} | ||
|
||
application { | ||
mainClass = 'io.airbyte.integrations.destination.yugabytedb.YugabytedbDestination' | ||
} | ||
|
||
dependencies { | ||
implementation project(':airbyte-config:config-models') | ||
implementation project(':airbyte-protocol:protocol-models') | ||
implementation project(':airbyte-integrations:bases:base-java') | ||
implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs) | ||
implementation project(':airbyte-integrations:connectors:destination-jdbc') | ||
implementation project(':airbyte-db:db-lib') | ||
|
||
implementation 'com.yugabyte:jdbc-yugabytedb:42.3.5-yb-1' | ||
|
||
testImplementation project(':airbyte-integrations:bases:standard-destination-test') | ||
|
||
testImplementation "org.assertj:assertj-core:3.21.0" | ||
testImplementation "org.junit.jupiter:junit-jupiter:5.8.1" | ||
testImplementation "org.testcontainers:junit-jupiter:1.17.5" | ||
testImplementation "org.testcontainers:jdbc:1.17.5" | ||
|
||
|
||
|
||
integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-destination-test') | ||
integrationTestJavaImplementation project(':airbyte-integrations:connectors:destination-yugabytedb') | ||
} |
31 changes: 31 additions & 0 deletions
31
airbyte-integrations/connectors/destination-yugabytedb/docker-compose.yml
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,31 @@ | ||
version: '3' | ||
|
||
|
||
# Note: add mount points at /mnt/master and /mnt/tserver for persistence | ||
|
||
services: | ||
yb-master: | ||
image: yugabytedb/yugabyte:latest | ||
container_name: yb-master-n1 | ||
command: [ "/home/yugabyte/bin/yb-master", | ||
"--fs_data_dirs=/mnt/master", | ||
"--master_addresses=yb-master-n1:7100", | ||
"--rpc_bind_addresses=yb-master-n1:7100", | ||
"--replication_factor=1"] | ||
ports: | ||
- "7000:7000" | ||
|
||
yb-tserver: | ||
image: yugabytedb/yugabyte:latest | ||
container_name: yb-tserver-n1 | ||
command: [ "/home/yugabyte/bin/yb-tserver", | ||
"--fs_data_dirs=/mnt/tserver", | ||
"--start_pgsql_proxy", | ||
"--rpc_bind_addresses=yb-tserver-n1:9100", | ||
"--tserver_master_addrs=yb-master-n1:7100"] | ||
ports: | ||
- "9042:9042" | ||
- "5433:5433" | ||
- "9000:9000" | ||
depends_on: | ||
- yb-master |
66 changes: 66 additions & 0 deletions
66
...b/src/main/java/io/airbyte/integrations/destination/yugabytedb/YugabytedbDestination.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,66 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.yugabytedb; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.db.factory.DatabaseDriver; | ||
import io.airbyte.db.jdbc.JdbcUtils; | ||
import io.airbyte.integrations.base.IntegrationRunner; | ||
import io.airbyte.integrations.destination.jdbc.AbstractJdbcDestination; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class YugabytedbDestination extends AbstractJdbcDestination { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(YugabytedbDestination.class); | ||
|
||
public static final String DRIVER_CLASS = DatabaseDriver.YUGABYTEDB.getDriverClassName(); | ||
|
||
public YugabytedbDestination() { | ||
super(DRIVER_CLASS, new YugabytedbNamingTransformer(), new YugabytedbSqlOperations()); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
LOGGER.info("starting destination: {}", YugabytedbDestination.class); | ||
new IntegrationRunner(new YugabytedbDestination()).run(args); | ||
LOGGER.info("completed destination: {}", YugabytedbDestination.class); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getDefaultConnectionProperties(JsonNode config) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
@Override | ||
public JsonNode toJdbcConfig(JsonNode config) { | ||
String schema = | ||
Optional.ofNullable(config.get(JdbcUtils.SCHEMA_KEY)).map(JsonNode::asText).orElse("public"); | ||
|
||
String jdbcUrl = "jdbc:yugabytedb://" + config.get(JdbcUtils.HOST_KEY).asText() + ":" | ||
+ config.get(JdbcUtils.PORT_KEY).asText() + "/" | ||
+ config.get(JdbcUtils.DATABASE_KEY).asText(); | ||
|
||
ImmutableMap.Builder<Object, Object> configBuilder = ImmutableMap.builder() | ||
.put(JdbcUtils.USERNAME_KEY, config.get(JdbcUtils.USERNAME_KEY).asText()) | ||
.put(JdbcUtils.JDBC_URL_KEY, jdbcUrl) | ||
.put(JdbcUtils.SCHEMA_KEY, schema); | ||
|
||
if (config.has(JdbcUtils.PASSWORD_KEY)) { | ||
configBuilder.put(JdbcUtils.PASSWORD_KEY, config.get(JdbcUtils.PASSWORD_KEY).asText()); | ||
} | ||
|
||
if (config.has(JdbcUtils.JDBC_URL_PARAMS_KEY)) { | ||
configBuilder.put(JdbcUtils.JDBC_URL_PARAMS_KEY, config.get(JdbcUtils.JDBC_URL_PARAMS_KEY).asText()); | ||
} | ||
|
||
return Jsons.jsonNode(configBuilder.build()); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...main/java/io/airbyte/integrations/destination/yugabytedb/YugabytedbNamingTransformer.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,16 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.yugabytedb; | ||
|
||
import io.airbyte.integrations.destination.ExtendedNameTransformer; | ||
|
||
public class YugabytedbNamingTransformer extends ExtendedNameTransformer { | ||
|
||
@Override | ||
public String applyDefaultCase(final String input) { | ||
return input.toLowerCase(); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...src/main/java/io/airbyte/integrations/destination/yugabytedb/YugabytedbSqlOperations.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,58 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.yugabytedb; | ||
|
||
import com.yugabyte.copy.CopyManager; | ||
import com.yugabyte.core.BaseConnection; | ||
import io.airbyte.db.jdbc.JdbcDatabase; | ||
import io.airbyte.integrations.destination.jdbc.JdbcSqlOperations; | ||
import io.airbyte.protocol.models.AirbyteRecordMessage; | ||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
|
||
public class YugabytedbSqlOperations extends JdbcSqlOperations { | ||
|
||
@Override | ||
protected void insertRecordsInternal(JdbcDatabase database, | ||
List<AirbyteRecordMessage> records, | ||
String schemaName, | ||
String tableName) | ||
throws Exception { | ||
|
||
if (records.isEmpty()) { | ||
return; | ||
} | ||
|
||
File tempFile = null; | ||
try { | ||
tempFile = Files.createTempFile(tableName + "-", ".tmp").toFile(); | ||
writeBatchToFile(tempFile, records); | ||
|
||
File finalTempFile = tempFile; | ||
database.execute(connection -> { | ||
|
||
var copyManager = new CopyManager(connection.unwrap(BaseConnection.class)); | ||
var sql = String.format("COPY %s.%s FROM STDIN DELIMITER ',' CSV", schemaName, tableName); | ||
|
||
try (var bufferedReader = new BufferedReader(new FileReader(finalTempFile, StandardCharsets.UTF_8))) { | ||
copyManager.copyIn(sql, bufferedReader); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
}); | ||
} finally { | ||
if (tempFile != null) { | ||
Files.delete(tempFile.toPath()); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.