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

Source #12

Merged
merged 36 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2a0a644
add general config
maksenius Jan 3, 2023
f7ae992
Merge pull request #1 from conduitio-labs/general/config
maksenius Jan 3, 2023
ecd46a6
add destination
maksenius Jan 4, 2023
07aef7b
Merge pull request #2 from conduitio-labs/destination
maksenius Jan 4, 2023
56cd656
add column types conversion
maksenius Jan 5, 2023
e0db11c
Merge pull request #3 from conduitio-labs/feature/destinaton/columntypes
maksenius Jan 5, 2023
9649fb8
fix make file
maksenius Jan 6, 2023
ac35eb9
fix validation
maksenius Jan 6, 2023
c2982e2
add unit tests
maksenius Jan 12, 2023
765d80c
Merge pull request #5 from conduitio-labs/feature/destination-test
maksenius Jan 12, 2023
90679eb
add sdk validation
maksenius Jan 16, 2023
ae63470
add sdk validation
maksenius Jan 16, 2023
d8e1428
add source struct
maksenius Jan 16, 2023
2d1c7ff
update validation
maksenius Jan 17, 2023
9d77aea
add snapshot logic
maksenius Jan 17, 2023
d7d6f76
add source test
maksenius Jan 18, 2023
274045e
implement cdc setup logic
maksenius Jan 19, 2023
b961b0a
combine iterator logic
maksenius Jan 20, 2023
5ccd973
Merge pull request #7 from conduitio-labs/source
maksenius Jan 20, 2023
47eb964
add suffix name
maksenius Jan 23, 2023
05fe926
Merge pull request #8 from conduitio-labs/feature/suffixname
maksenius Jan 23, 2023
e64fc12
add test and docs
maksenius Jan 24, 2023
417d00c
Merge pull request #11 from conduitio-labs/feature/integration_test
maksenius Jan 24, 2023
a93c2aa
update readme
maksenius Jan 25, 2023
ee6de47
add source connector
maksenius Jan 26, 2023
c67697b
Merge branch 'main' of github.com:conduitio-labs/conduit-connector-sa…
maksenius Jan 26, 2023
c83c995
update validation rule
maksenius Jan 31, 2023
c980393
fix table description
maksenius Jan 31, 2023
4ee3909
fix problem has next function on cdc switching
maksenius Jan 31, 2023
36b6ec4
fix comments
maksenius Jan 31, 2023
bdb3fa7
update params
maksenius Feb 1, 2023
cdad314
add check if table exist
maksenius Feb 2, 2023
48bfe7a
update readme
maksenius Feb 3, 2023
11964d6
Merge branch 'main' of github.com:conduitio-labs/conduit-connector-sa…
maksenius Feb 3, 2023
5b8e563
update conduit sdk
maksenius Feb 3, 2023
211b7c6
refactoring changes
maksenius Feb 6, 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
2 changes: 1 addition & 1 deletion .golangci.goheader.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ issues:
- paralleltest # we don't want to run the integration tests in parallel because we want deterministic results
- path: acceptance_test
linters:
- paralleltest
- paralleltest
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
VERSION=$(shell git describe --tags --dirty --always)

build:
go build -ldflags "-X 'github.com/conduitio-labs/conduit-connector-sap-hana.version=${VERSION}'" -o conduit-connector-sap-hanaAAF cmd/connector/main.go
go build -ldflags "-X 'github.com/conduitio-labs/conduit-connector-sap-hana.version=${VERSION}'" -o conduit-connector-sap-hana cmd/connector/main.go


test:
go test $(GOTEST_FLAGS) ./...
go test $(GOTEST_FLAGS) -race ./...

lint:
golangci-lint run --config .golangci.yml

paramgen:
paramgen -path=./destination -output=destination_params.go Config
paramgen -path=./source -output=source_params.go Config

mockgen:
mockgen -package mock -source destination/interface.go -destination destination/mock/destination.go
mockgen -package mock -source source/interface.go -destination source/mock/iterator.go
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,109 @@

## General

The [SAP HANA](https://neo4j.com/) connector is one of Conduit plugins. It provides both, a source and a destination Sap Hana connector.
The [SAP HANA](https://www.sap.com/products/technology-platform/hana/what-is-sap-hana.html) connector is one of Conduit plugins.
It provides the source Sap Hana connector.
hariso marked this conversation as resolved.
Show resolved Hide resolved

### Prerequisites
hariso marked this conversation as resolved.
Show resolved Hide resolved

- [Go](https://go.dev/) 1.19
- [Conduit Paramgen](https://github.com/ConduitIO/conduit-connector-sdk/tree/main/cmd/paramgen)
- (optional) [golangci-lint](https://github.com/golangci/golangci-lint) 1.50.1

### How to build it

Run `make build`.

### Testing

Run `make test` to run all the unit and integration tests.

## Source
hariso marked this conversation as resolved.
Show resolved Hide resolved

The SAP HANA source connects to the database using the provided connection and starts creating records for each table row
and each detected change. It supports gets snapshot from table and catches CDC (Change Data Captured) changes.

### Configuration options

| Name | Description | Required | Example | By default |
|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|---------------------------------------------------|------------|
| `table` | The name of a table in the database that the connector should read from. | **true** | users | |
hariso marked this conversation as resolved.
Show resolved Hide resolved
| `orderingColumn` | The name of a column that the connector will use for ordering rows. Its values must be unique and suitable for sorting, otherwise, the snapshot won't work correctly. | **true** | id | |
| `primaryKeys` | Comma separated list of column names that records could use for their `Key` fields. By default connector uses primary keys from table if they are not exist connector will use ordering column. | false | id | |
| `snapshot` | Whether or not the plugin will take a snapshot of the entire table before starting cdc mode, by default true. | false | false | |
| `batchSize` | Size of rows batch. | false | 100 | 1000 |
| `auth.mechanism` | Mechanism type of auth. Valid types: DSN, Basic, JWT, X509. | false | JWT | DSN |
| `auth.dsn` | DSN connection string | Required for DSN auth type. | hdb://user:password@host443?TLSServerName=name | |
| `auth.host` | Sap Hana database host. | Required for Basic, JWT, X509 auth types. | hdb://hanacloud.ondemand.com:443 | |
| `auth.username` | Sap Hana user | Required for Basic type. | hbadmin | |
| `auth.password` | Sap Hana password | Required for Basic type. | pass | |
| `auth.token` | JWT token | Required for JWT type. | jwt_token | |
| `auth.clientCertFilePath` | Path for certification file | Required for X509 type. | /tmp/file.cert | |
| `auth.clientKeyFilePath` | Path for key file | Required for X509 type. | /tmp/key.cert | |

### Snapshot
By default when the connector starts for the first time, snapshot mode is enabled, which means that existing data will
be read. To skip reading existing, change config parameter `snapshot` to `false`.
All rows which exist in a table at the time the snapshot started, are considered part of snapshot.
When all snapshot records are returned, the connector switches to the CDC iterator.

### Change Data Capture (CDC)

This connector implements CDC features for DB2 by adding a tracking table and triggers to populate it. The tracking
table has the same name as a target table with the prefix `CONDUIT_` and suffix from time when pipeline started on
format "hhmmss". For example for table `PRODUCTS` the tracking table's name will be looks like `CONDUIT_PRODUCTS_213315`.
The tracking table has all the same columns as the target table plus two additional columns:

| name | description |
|---------------------------------|--------------------------------------------------|
| `CONDUIT_TRACKING_ID` | Autoincrement index for the position. |
| `CONDUIT_OPERATION_TYPE` | Operation type: `INSERT`, `UPDATE`, or `DELETE`. |

The connector saves information about update, delete, insert `table` operations inside tracking table.
For example if user inserts new row into `table` connector will save all new columns values inside tracking table
with `CONDUIT_OPERATION_TYPE` = `INSERT`

Triggers have name pattern `CD_{{TABLENAME}}_{{OPERATION_TYPE}}_{{SUFFIXNAME}}`. For example:
`CD_PRODUCTS_INSERT_213315`


Queries to retrieve change data from a tracking table are very similar to queries in a Snapshot iterator, but with
`CONDUIT_TRACKING_ID` ordering column.

The connector cleans up the tracking table every 5 seconds.

Iterator saves the last `CONDUIT_TRACKING_ID` to the position from the last successfully recorded row.

If connector stops, it will parse position from the last record and will try
to get row where `{{CONDUIT_TRACKING_ID}}` > `{{position.CDCLastID}}`.



<b>Please pay attention</b>

The tracking table and the triggers are not automatically removed when a pipeline is deleted.
That needs to be done manually, for example by using the following commands:
```sql
DROP TABLE CONDUIT_{{YOUR_TABLE_NAME}}_{{SUFFIXNAME}};
DROP TRIGGER CD_{{TABLENAME}}_INSERT_{{SUFFIXNAME}};
DROP TRIGGER CD_{{TABLENAME}}_UPDATE_{{SUFFIXNAME}};
DROP TRIGGER CD_{{TABLENAME}}_DELETE_{{SUFFIXNAME}};
```

### CDC FAQ

#### Is it possible to add/remove/rename column to table?

Yes. You have to stop the pipeline and do the same with conduit tracking table.
For example:
```sql
ALTER TABLE CLIENTS
ADD COLUMN phone VARCHAR(18);

ALTER TABLE CONDUIT_CLIENTS_{suffix}
ADD COLUMN phone VARCHAR(18);
```

#### I accidentally removed tracking table.

You have to restart pipeline, tracking table will be recreated by connector.
Loading