Skip to content
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

New destination: databend (community PR #19815) #20909

Merged
merged 36 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8d73aa0
feat: Add databend destination
hantmac Nov 27, 2022
9d39710
docs
hantmac Nov 27, 2022
48414c3
fix
hantmac Nov 27, 2022
a6c3ce1
fix
hantmac Nov 28, 2022
74ddc14
fix tests
hantmac Nov 28, 2022
ee83f67
support normalization for databend
hantmac Dec 1, 2022
5b3eee5
update
hantmac Dec 1, 2022
06ba911
fix gradle build
hantmac Dec 1, 2022
748bee5
fix
hantmac Dec 2, 2022
d326285
update
hantmac Dec 2, 2022
936c02b
fix transform
hantmac Dec 2, 2022
34efd07
fix spec.json
hantmac Dec 5, 2022
75b3367
fix
hantmac Dec 14, 2022
7d41ae8
more check
hantmac Dec 14, 2022
ef35195
add finally for connector
hantmac Dec 16, 2022
5ddc5d9
fix comment
hantmac Dec 16, 2022
28081fd
fix
hantmac Dec 16, 2022
d324ef3
add section to destination_definitions
hantmac Dec 20, 2022
cee19c3
default port
hantmac Dec 20, 2022
20ef8fc
add databend icon
hantmac Dec 20, 2022
687aa9b
add sample_config.json
hantmac Dec 21, 2022
7d91bff
Fix formatting
Dec 30, 2022
a9ec256
Remove databend from seed file and UI (this will have to be a separat…
Dec 31, 2022
6cecea8
Add databend dependency
Jan 4, 2023
7238ce8
remove normalization from databend destination
Jan 5, 2023
1677951
remove normalization and dedupe from databend destination spec
Jan 5, 2023
b007618
removing normalization from databend destination
Jan 5, 2023
f1fee84
Update logo
Jan 6, 2023
104de0a
make databend logo square
josephkmh Jan 6, 2023
61d727f
removing normalization artifacts
Jan 6, 2023
131be25
format fix
Jan 6, 2023
4e920d7
Generate seed files for databend destination
Jan 7, 2023
421692a
Trying to fix git diff quirkiness
Jan 7, 2023
a630700
run format
Jan 7, 2023
9139ca2
Merge branch 'master' into greg/databend-destination
sajarin Jan 9, 2023
431941a
Merge branch 'master' into greg/databend-destination
grishick Jan 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airbyte-config/init/src/main/resources/icons/databend.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,10 @@
documentationUrl: https://docs.airbyte.com/integrations/destinations/yugabytedb
icon: yugabytedb.svg
releaseStage: alpha
- name: Databend
destinationDefinitionId: 302e4d8e-08d3-4098-acd4-ac67ca365b88
dockerRepository: airbyte/destination-databend
dockerImageTag: 0.1.0
icon: databend.svg
documentationUrl: https://docs.airbyte.com/integrations/destinations/databend
releaseStage: alpha
66 changes: 66 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 @@ -7140,3 +7140,69 @@
supported_destination_sync_modes:
- "overwrite"
- "append"
- dockerImage: "airbyte/destination-databend:0.1.0"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/destinations/databend"
connectionSpecification:
$schema: "http://json-schema.org/draft-07/schema#"
title: "Destination Databend"
type: "object"
required:
- "host"
- "username"
- "database"
additionalProperties: true
properties:
host:
title: "Host"
description: "Hostname of the database."
type: "string"
order: 0
protocol:
title: "Protocol"
description: "Protocol of the host."
type: "string"
examples:
- "https"
default: "https"
order: 1
port:
title: "Port"
description: "Port of the database."
type: "integer"
minimum: 0
maximum: 65536
default: 443
examples:
- "443"
order: 2
database:
title: "DB Name"
description: "Name of the database."
type: "string"
order: 3
table:
title: "Default Table"
description: "The default table was written to."
type: "string"
examples:
- "default"
default: "default"
order: 4
username:
title: "User"
description: "Username to use to access the database."
type: "string"
order: 5
password:
title: "Password"
description: "Password associated with the username."
type: "string"
airbyte_secret: true
order: 6
supportsIncremental: true
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes:
- "overwrite"
- "append"
2 changes: 0 additions & 2 deletions airbyte-integrations/bases/base-normalization/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.nio.file.Paths

plugins {
id 'airbyte-docker'
id 'airbyte-python'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!Dockerfile
!main.py
!destination_databend
!setup.py
38 changes: 38 additions & 0 deletions airbyte-integrations/connectors/destination-databend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM python:3.9.11-alpine3.15 as base

# build and load all requirements
FROM base as builder
WORKDIR /airbyte/integration_code

# upgrade pip to the latest version
RUN apk --no-cache upgrade \
&& pip install --upgrade pip \
&& apk --no-cache add tzdata build-base


COPY setup.py ./
# install necessary packages to a temporary folder
RUN pip install --prefix=/install .

# build a clean environment
FROM base
WORKDIR /airbyte/integration_code

# copy all loaded and built libraries to a pure basic image
COPY --from=builder /install /usr/local
# add default timezone settings
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN echo "Etc/UTC" > /etc/timezone

# bash is installed for more convenient debugging.
RUN apk --no-cache add bash

# copy payload code only
COPY main.py ./
COPY destination_databend ./destination_databend

ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

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

This is the repository for the Databend destination connector, written in Python.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/destinations/databend).

## Local development

### Prerequisites
**To iterate on this connector, make sure to complete this prerequisites section.**

#### Minimum Python version required `= 3.7.0`

#### Build & Activate Virtual Environment and install dependencies
From this connector directory, create a virtual environment:
```
python -m venv .venv
```

This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
development environment of choice. To activate it from the terminal, run:
```
source .venv/bin/activate
pip install -r requirements.txt
```
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.

Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
If this is mumbo jumbo to you, don't worry about it, just put your deps in `setup.py` but install using `pip install -r requirements.txt` and everything
should work as you expect.

#### Building via Gradle
From the Airbyte repository root, run:
```
./gradlew :airbyte-integrations:connectors:destination-databend:build
```

#### Create credentials
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/destinations/databend)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `destination_databend/spec.json` file.
Note that the `secrets` directory is gitignored by default, so there is no danger of accidentally checking in sensitive information.
See `integration_tests/sample_config.json` for a sample config file.

**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `destination databend test creds`
and place them into `secrets/config.json`.

### Locally running the connector
```
python main.py spec
python main.py check --config secrets/config.json
python main.py discover --config secrets/config.json
python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
```

### Locally running the connector docker image

#### Build
First, make sure you build the latest Docker image:
```
docker build . -t airbyte/destination-databend:dev
```

You can also build the connector image via Gradle:
```
./gradlew :airbyte-integrations:connectors:destination-databend: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-databend:dev spec
docker run --rm -v $(pwd)/secrets:/secrets airbyte/destination-databend:dev check --config /secrets/config.json
# messages.jsonl is a file containing line-separated JSON representing AirbyteMessages
cat messages.jsonl | docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/destination-databend:dev write --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
```
## Testing
Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named.
First install test dependencies into your virtual environment:
```
pip install .[tests]
```
### Unit Tests
To run unit tests locally, from the connector directory run:
```
python -m pytest unit_tests
```

### Integration Tests
There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all destination connectors) and custom integration tests (which are specific to this connector).
#### Custom Integration tests
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
```
python -m pytest integration_tests
```
#### Acceptance Tests
Coming soon:

### Using gradle to run tests
All commands should be run from airbyte project root.
To run unit tests:
```
./gradlew :airbyte-integrations:connectors:destination-databend:unitTest
```
To run acceptance and custom integration tests:
```
./gradlew :airbyte-integrations:connectors:destination-databend:integrationTest
```

## Dependency Management
All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development.
We split dependencies between two groups, dependencies that are:
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
* required for the testing need to go to `TEST_REQUIREMENTS` list

### 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'airbyte-python'
id 'airbyte-docker'
}

airbytePython {
moduleDirectory 'destination_databend'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#


from .destination import DestinationDatabend

__all__ = ["DestinationDatabend"]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from databend_sqlalchemy import connector


class DatabendClient:
def __init__(self, protocol: str, host: str, port: int, database: str, table: str, username: str, password: str = None):
self.protocol = protocol
self.host = host
self.port = port
self.database = database
self.table = table
self.username = username
self.password = password

def open(self):
handle = connector.connect(f"{self.protocol}://{self.username}:{self.password}@{self.host}:{self.port}").cursor()

return handle
Loading