Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.

Add ClickHouse support#2467

Merged
edmundito merged 49 commits into
mainfrom
180005482-clickhouse-plugin
Nov 12, 2021
Merged

Add ClickHouse support#2467
edmundito merged 49 commits into
mainfrom
180005482-clickhouse-plugin

Conversation

@edmundito
Copy link
Copy Markdown
Contributor

@edmundito edmundito commented Oct 26, 2021

Change description

image

This change adds a plugin and demo generator for the ClickHouse OLAP DB. Supports source and destination, table and query imports. The plugin is based on on the MySQL plugin.

Demo usage:

grouparoo demo --clickhouse

Checklists

Development

  • Application changes have been tested appropriately

Impact

  • Code follows company security practices and guidelines
  • Security impact of change has been considered
  • Performance impact of change has been considered
  • Possible migration needs considered (model migrations, config migrations, etc.)

Please explain any security, performance, migration, or other impacts if relevant:

Code review

  • Pull request has a descriptive title and context useful to a reviewer. Screenshots or screencasts are attached where applicable.
  • Relevant tags have been added to the PR (bug, enhancement, internal, etc.)

@edmundito edmundito added the enhancement New feature or request label Oct 26, 2021
@edmundito edmundito requested a review from evantahler October 26, 2021 19:58
Copy link
Copy Markdown
Member

@evantahler evantahler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! You've set up the boilerplate.

There are some changes to make the package.json, but otherwise this looks good!

Comment thread plugins/@grouparoo/clickhouse/package.json
Comment thread plugins/@grouparoo/clickhouse/package.json Outdated
Comment thread plugins/@grouparoo/clickhouse/package.json Outdated
Comment thread plugins/@grouparoo/clickhouse/src/initializers/plugin.ts Outdated
Comment thread plugins/@grouparoo/clickhouse/README.md
Copy link
Copy Markdown
Member

@evantahler evantahler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the next step is to wire up CI. Then there are few TODOs to fixup, and this will be ready!

Comment thread core/src/classes/plugin.ts Outdated
Comment thread plugins/@grouparoo/clickhouse/src/lib/export/exportRecord.ts Outdated
@edmundito edmundito force-pushed the 180005482-clickhouse-plugin branch from 60bb6ed to be90b6d Compare November 9, 2021 21:58
@edmundito
Copy link
Copy Markdown
Contributor Author

All the tests are no passing, fixed the template issues and rebased with main. I still need to apply the changes from #2522

@edmundito edmundito changed the title Add ClickHouse plugin Add ClickHouse plugin and demo generator Nov 10, 2021
@edmundito edmundito marked this pull request as ready for review November 10, 2021 22:33
Comment thread plugins/@grouparoo/clickhouse/public/@grouparoo/clickhouse/clickhouse.svg Outdated
Comment thread plugins/@grouparoo/clickhouse/src/lib/query-import/connection.ts Outdated
Comment thread plugins/@grouparoo/clickhouse/src/lib/table-import/connection.ts Outdated
Comment thread plugins/@grouparoo/clickhouse/src/lib/export/connection.ts Outdated
edmundito and others added 19 commits November 11, 2021 09:10
* Add custom getColumns function to identify CH types
* Cleanup types in MySQL plugin
* Update connection ifaces in plugin to accept type instead of `any`
* Update table import to use own implementation of getting data
* Implement selects to do type casting based on column types in order to be able to apply the queries
* Update `cleanupDataType` to not change case and move to `utils`
@edmundito edmundito force-pushed the 180005482-clickhouse-plugin branch from 208c4ec to f0f2a72 Compare November 11, 2021 14:21
@edmundito
Copy link
Copy Markdown
Contributor Author

Applied feedback from the review.

After looking into how to resolve the problems with the mysql query conflicts while running the tests in parallel, I couldn't find a good answer online and I feared that this would be come a problem in production. I saw the same issue occur while running exports from the UI app. So, I implemented a custom connect with the clickhouse npm module, which uses the HTTP interface.

Copy link
Copy Markdown
Member

@evantahler evantahler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

Just lock that dependency, and this is 👍!

Comment thread plugins/@grouparoo/clickhouse/package.json Outdated
Comment thread plugins/@grouparoo/clickhouse/src/lib/connect.ts
Comment thread plugins/@grouparoo/clickhouse/src/lib/connect.ts Outdated
@edmundito
Copy link
Copy Markdown
Contributor Author

Addressed review comments and pushed changes!

Comment on lines +1 to +22
import path from "path";
import fs from "fs-extra";
import os from "os";

process.env.GROUPAROO_INJECTED_PLUGINS = JSON.stringify({
"@grouparoo/clickhouse": { path: path.join(__dirname, "..", "..") },
});

import { helper } from "@grouparoo/spec-helper";
import { api } from "actionhero";
import { Generate } from "@grouparoo/core/src/bin/generate";
import { Apply } from "@grouparoo/core/src/bin/apply";
import {
beforeData,
afterData,
appOptions,
usersTableName,
} from "../utils/data";

process.env.GROUPAROO_CONFIG_DIR = `${os.tmpdir()}/test/${
process.env.JEST_WORKER_ID
}/config`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a little odd that these aren't all imports -> env
Do the later imports require they be set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evantahler is this intentional for a reason?

Comment on lines +89 to +90
// .replace(`host: "localhost"`, `host: "${appOptions.host}"`)
// .replace(`port: 5432`, `port: "${appOptions.port}"`)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are commented out, do we need them?

Comment on lines +121 to +122
// mapping: { id: "userId" },
// state: "ready",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

session
);
expect(bootstrapResponse.error).toBeUndefined();
expect(bootstrapResponse.property).toBeTruthy();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a complex object, assuming it doesn't change, could do a snapshot against it.
Or test the object+properties directly if we want that level of detail.

Comment thread plugins/@grouparoo/clickhouse/src/lib/connect.ts
groupForeignKey = groupForeignKey?.toString();
groupColumnName = groupColumnName?.toString();

if (Object.keys(newRecordProperties).length === 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Object.keys(newRecordProperties).length === 0) {
if (!Object.keys(newRecordProperties).length) {

Purely stylistic choice.

oldRecordProperties[k] !== undefined)
);

if (columnsToErase.length > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (columnsToErase.length > 0) {
if (columnsToErase.length) {

Minor nitpick!

Comment thread plugins/@grouparoo/clickhouse/src/lib/export/exportRecord.ts
Comment on lines +133 to +137
error = e;
} finally {
if (error) {
throw error;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just let this throw? Or is error getting grabbed at a higher level?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but this is how it's implemented in all the SQL-based plugins.

Comment on lines +58 to +61
const out: DataResponseRow[] = [];
const rows = await connection.asyncQuery(query, params);
rows.forEach((row) => out.push(row));
return out;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just return await connection.asyncQuery(query, params)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure either, this was a copy and paste from mysql and there may be a reason why copying the values into anew array ([...out]) ?

@edmundito
Copy link
Copy Markdown
Contributor Author

Pushed one more change to address @krishnaglick's feedback and update the version to match main. Ready to merge.

const { host, port, database, user, password } = appOptions;

let url = String(host);
if (url && !url.match(/^localhost/i) && !url.match(/^https?/)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to combine these match calls.

@edmundito edmundito merged commit 49f5734 into main Nov 12, 2021
@edmundito edmundito deleted the 180005482-clickhouse-plugin branch November 12, 2021 17:07
@evantahler evantahler linked an issue Nov 12, 2021 that may be closed by this pull request
@bleonard bleonard changed the title Add ClickHouse plugin and demo generator Add ClickHouse support Nov 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Clickhouse Source

4 participants