Skip to content

Commit

Permalink
🎉 New Destination: Rockset (airbytehq#8006)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaldwin-rs authored Dec 15, 2021
1 parent be2ed7d commit 3748c66
Show file tree
Hide file tree
Showing 18 changed files with 1,007 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"destinationDefinitionId": "2c9d93a7-9a17-4789-9de9-f46f0097eb70",
"name": "Rockset",
"dockerRepository": "airbyte/destination-rockset",
"dockerImageTag": "0.1.0",
"documentationUrl": "https://docs.airbyte.io/integrations/destinations/rockset"
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
dockerImageTag: 0.3.21
documentationUrl: https://docs.airbyte.io/integrations/destinations/redshift
icon: redshift.svg
- name: Rockset
destinationDefinitionId: 2c9d93a7-9a17-4789-9de9-f46f0097eb70
dockerRepository: airbyte/destination-rockset
dockerImageTag: 0.1.0
documentationUrl: https://docs.airbyte.io/integrations/destinations/rockset
- name: S3
destinationDefinitionId: 4816b78f-1489-44c1-9060-4b19d5fa9362
dockerRepository: airbyte/destination-s3
Expand Down
43 changes: 43 additions & 0 deletions airbyte-config/init/src/main/resources/seed/destination_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,49 @@
- "overwrite"
- "append"
- "append_dedup"
- dockerImage: "airbyte/destination-rockset:0.1.0"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/destinations/rockset"
connectionSpecification:
$schema: "http://json-schema.org/draft-07/schema#"
title: "Rockset Destination Spec"
type: "object"
required:
- "api_key"
- "workspace"
additionalProperties: false
properties:
api_key:
title: "Api Key"
description: "Rockset api key"
type: "string"
order: 0
airbyte_secret: true
workspace:
title: "Workspace"
description: "The Rockset workspace in which collections will be created\
\ + written to."
type: "string"
examples:
- "commons"
- "my_workspace"
default: "commons"
airbyte_secret: false
order: 1
api_server:
title: "Api Server"
description: "Rockset api URL"
type: "string"
airbyte_secret: false
default: "https://api.rs2.usw2.rockset.com"
pattern: "^https:\\/\\/.*.rockset.com$"
order: 2
supportsIncremental: true
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes:
- "append"
- "overwrite"
- dockerImage: "airbyte/destination-s3:0.1.16"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/destinations/s3"
Expand Down
1 change: 1 addition & 0 deletions airbyte-integrations/builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
| Postgres | [![destination-postgres](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fdestination-postgres%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/destination-postgres) |
| Pulsar | [![destination-pulsar](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fdestination-pulsar%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/destination-pulsar) |
| Redshift | [![destination-redshift](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fdestination-redshift%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/destination-redshift) |
| Rockset | [![destination-rockset](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fdestination-rockset%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/destination-rockset) |
| S3 | [![destination-s3](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fdestination-s3%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/destination-s3) |
| SFTP-JSON | [![destination-sftp-json](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fdestination-sftp-json%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/destination-sftp-json) |
| Snowflake | [![destination-snowflake](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fdestination-snowflake%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/destination-snowflake) |\
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!Dockerfile
!build
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Rockset Destination Connector Bootstrap

[Rockset](https://rockset.com/) is a real-time analytics database for fast queries on fresh data from databases, lakes and streams.
An [API key](https://rockset.com/docs/rest-api/#authentication) is required.
Configured collections will be created as required and data will be written via the [write API](https://rockset.com/docs/rest-api/#adddocuments).

11 changes: 11 additions & 0 deletions airbyte-integrations/connectors/destination-rockset/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM airbyte/integration-base-java:dev

WORKDIR /airbyte
ENV APPLICATION destination-rockset

COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar

RUN tar xf ${APPLICATION}.tar --strip-components=1

LABEL io.airbyte.version=0.1.0
LABEL io.airbyte.name=airbyte/destination-rockset
68 changes: 68 additions & 0 deletions airbyte-integrations/connectors/destination-rockset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Destination Rockset

This is the repository for the Rockset destination connector in Java.
For information about how to use this connector within Airbyte, see [the User Documentation](https://docs.airbyte.io/integrations/destinations/rockset).

## Local development

#### Building via Gradle
From the Airbyte repository root, run:
```
./gradlew :airbyte-integrations:connectors:destination-rockset: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/contributing-to-airbyte/building-new-connector#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-rockset: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-rockset:dev spec
docker run --rm -v $(pwd)/secrets:/secrets airbyte/destination-rockset:dev check --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets airbyte/destination-rockset:dev discover --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/destination-rockset: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/rockset`.

#### 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/rocksetDestinationAcceptanceTest.java`.

### Using gradle to run tests
All commands should be run from airbyte project root.
To run unit tests:
```
./gradlew :airbyte-integrations:connectors:destination-rockset:unitTest
```
To run acceptance and custom integration tests:
```
./gradlew :airbyte-integrations:connectors:destination-rockset: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.
29 changes: 29 additions & 0 deletions airbyte-integrations/connectors/destination-rockset/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
id 'application'
id 'airbyte-docker'
id 'airbyte-integration-test-java'
}

application {
mainClass = 'io.airbyte.integrations.destination.rockset.RocksetDestination'
}

repositories {
maven { url "https://mvnrepository.com/artifact/com.rockset/rockset-java" }
maven { url "https://mvnrepository.com/artifact/org.awaitility/awaitility" }
}

dependencies {
implementation project(':airbyte-config:models')
implementation project(':airbyte-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 group: 'com.rockset', name: 'rockset-java', version: '0.9.0'
implementation group: 'org.awaitility', name: 'awaitility', version: '4.1.1'


integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-destination-test')
integrationTestJavaImplementation project(':airbyte-integrations:connectors:destination-rockset')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2021 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.integrations.destination.rockset;

import static io.airbyte.integrations.destination.rockset.RocksetUtils.ROCKSET_WORKSPACE_ID;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.rockset.client.ApiClient;
import com.rockset.client.api.DocumentsApi;
import com.rockset.client.model.AddDocumentsRequest;
import io.airbyte.integrations.BaseConnector;
import io.airbyte.integrations.base.AirbyteMessageConsumer;
import io.airbyte.integrations.base.Destination;
import io.airbyte.integrations.base.IntegrationRunner;
import io.airbyte.protocol.models.AirbyteConnectionStatus;
import io.airbyte.protocol.models.AirbyteConnectionStatus.Status;
import io.airbyte.protocol.models.AirbyteMessage;
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog;

import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;

import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RocksetDestination extends BaseConnector implements Destination {

private static final Logger LOGGER = LoggerFactory.getLogger(RocksetDestination.class);
private static final ObjectMapper mapper = new ObjectMapper();

public static void main(String[] args) throws Exception {
new IntegrationRunner(new RocksetDestination()).run(args);
}

@Override
public AirbyteConnectionStatus check(final JsonNode config) {
ApiClient client = null;
String workspace = null;
// Create a temporary table
final String cname = "tmp_test_airbyte_collection_" + RandomStringUtils.randomAlphabetic(7).toLowerCase();

try {
client = RocksetUtils.apiClientFromConfig(config);

workspace = config.get(ROCKSET_WORKSPACE_ID).asText();
RocksetUtils.createWorkspaceIfNotExists(client, workspace);


RocksetUtils.createCollectionIfNotExists(client, workspace, cname);
RocksetUtils.waitUntilCollectionReady(client, workspace, cname);

// Write a single document
final String unique = UUID.randomUUID().toString();
final Map<String, String> dummyRecord = ImmutableMap.of("_id", unique);
final AddDocumentsRequest req = new AddDocumentsRequest();
req.addDataItem(mapper.convertValue(dummyRecord, new TypeReference<>() {
}));
new DocumentsApi(client).add(workspace, cname, req);

// Verify that the doc shows up
final String sql = String.format("SELECT * FROM %s.%s WHERE _id = '%s';", workspace, cname, unique);
RocksetUtils.waitUntilDocCount(client, sql, 1);

LOGGER.info("Check succeeded");
return new AirbyteConnectionStatus().withStatus(Status.SUCCEEDED);
} catch (Exception e) {
LOGGER.info("Check failed.", e);
return new AirbyteConnectionStatus().withStatus(Status.FAILED).withMessage(e.getMessage() != null ? e.getMessage() : e.toString());
} finally {
// Delete the collection
if (client != null && workspace != null) {
RocksetUtils.deleteCollectionIfExists(client, workspace, cname);
}

}
}

@Override
public AirbyteMessageConsumer getConsumer(
JsonNode config,
ConfiguredAirbyteCatalog catalog,
Consumer<AirbyteMessage> outputRecordCollector)
throws Exception {
return new RocksetWriteApiConsumer(config, catalog, outputRecordCollector);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2021 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.integrations.destination.rockset;

import io.airbyte.integrations.destination.ExtendedNameTransformer;

public class RocksetSQLNameTransformer extends ExtendedNameTransformer {

@Override
public String convertStreamName(String input) {
return super.convertStreamName(input).toLowerCase();
}

@Override
protected String applyDefaultCase(String input) {
return input.toLowerCase();
}

}
Loading

0 comments on commit 3748c66

Please sign in to comment.