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

[#3888] Metadata Support ClickHouse #5819

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class Indexes {
/** MySQL does not support setting the name of the primary key, so the default name is used. */
public static final String DEFAULT_MYSQL_PRIMARY_KEY_NAME = "PRIMARY";

/**
* ClickHouse does not support setting the name of the primary key, so the default name is used.
*/
public static final String DEFAULT_CLICKHOUSE_PRIMARY_KEY_NAME = "PRIMARY";
/**
* Create a unique index on columns. Like unique (a) or unique (a, b), for complex like unique
*
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ tasks {
"catalogs:catalog-lakehouse-hudi:copyLibAndConfig",
":catalogs:catalog-jdbc-doris:copyLibAndConfig",
":catalogs:catalog-jdbc-mysql:copyLibAndConfig",
":catalogs:catalog-jdbc-clickhouse:copyLibAndConfig",
":catalogs:catalog-jdbc-oceanbase:copyLibAndConfig",
":catalogs:catalog-jdbc-postgresql:copyLibAndConfig",
":catalogs:catalog-hadoop:copyLibAndConfig",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.apache.gravitino.catalog.clickhouse;

public class ClickHouseConstants {
public static final String GRAVITINO_ENGINE_KEY = "engine";
public static final String CLICKHOUSE_ENGINE_KEY = "ENGINE";
}
114 changes: 114 additions & 0 deletions catalogs/catalog-jdbc-clickhouse/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
description = "catalog-jdbc-clickhouse"

plugins {
`maven-publish`
id("java")
id("idea")
}

dependencies {
implementation(project(":api")) {
exclude(group = "*")
}
implementation(project(":catalogs:catalog-common")) {
exclude(group = "*")
}
implementation(project(":catalogs:catalog-jdbc-common")) {
exclude(group = "*")
}
implementation(project(":common")) {
exclude(group = "*")
}
implementation(project(":core")) {
exclude(group = "*")
}

implementation(libs.bundles.log4j)
implementation(libs.commons.collections4)
implementation(libs.commons.lang3)
implementation(libs.guava)
implementation(libs.httpclient5)
implementation(libs.lz4.java)

testImplementation(project(":catalogs:catalog-jdbc-common", "testArtifacts"))
testImplementation(project(":clients:client-java"))
testImplementation(project(":integration-test-common", "testArtifacts"))
testImplementation(project(":server"))
testImplementation(project(":server-common"))

testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testImplementation(libs.clickhouse.driver)
testImplementation(libs.lz4.java)
testImplementation(libs.postgresql.driver)
testImplementation(libs.testcontainers)
testImplementation(libs.testcontainers.clickhouse)

testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks {
val runtimeJars by registering(Copy::class) {
from(configurations.runtimeClasspath)
into("build/libs")
}

val copyCatalogLibs by registering(Copy::class) {
dependsOn("jar", "runtimeJars")
from("build/libs") {
exclude("guava-*.jar")
exclude("log4j-*.jar")
exclude("slf4j-*.jar")
}
into("$rootDir/distribution/package/catalogs/jdbc-clickhouse/libs")
}

val copyCatalogConfig by registering(Copy::class) {
from("src/main/resources")
into("$rootDir/distribution/package/catalogs/jdbc-clickhouse/conf")

include("jdbc-clickhouse.conf")

exclude { details ->
details.file.isDirectory()
}

fileMode = 0b111101101
}

register("copyLibAndConfig", Copy::class) {
dependsOn(copyCatalogLibs, copyCatalogConfig)
}
}

tasks.test {
val skipITs = project.hasProperty("skipITs")
if (skipITs) {
// Exclude integration tests
exclude("**/integration/test/**")
} else {
dependsOn(tasks.jar)
}
}

tasks.getByName("generateMetadataFileForMavenJavaPublication") {
dependsOn("runtimeJars")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.apache.gravitino.catalog.clickhouse;

import java.util.Map;
import org.apache.gravitino.catalog.clickhouse.converter.ClickHouseColumnDefaultValueConverter;
import org.apache.gravitino.catalog.clickhouse.converter.ClickHouseExceptionConverter;
import org.apache.gravitino.catalog.clickhouse.converter.ClickHouseTypeConverter;
import org.apache.gravitino.catalog.clickhouse.operation.ClickHouseDatabaseOperations;
import org.apache.gravitino.catalog.clickhouse.operation.ClickHouseTableOperations;
import org.apache.gravitino.catalog.jdbc.JdbcCatalog;
import org.apache.gravitino.catalog.jdbc.JdbcCatalogOperations;
import org.apache.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;
import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
import org.apache.gravitino.catalog.jdbc.operation.JdbcTableOperations;
import org.apache.gravitino.connector.CatalogOperations;
import org.apache.gravitino.connector.PropertiesMetadata;
import org.apache.gravitino.connector.capability.Capability;

/** Implementation of a Clickhouse catalog in Apache Gravitino. */
public class ClickHouseCatalog extends JdbcCatalog {

private static final ClickHouseTablePropertiesMetadata TABLE_PROPERTIES_META =
new ClickHouseTablePropertiesMetadata();

@Override
public String shortName() {
return "jdbc-clickhouse";
}

@Override
protected CatalogOperations newOps(Map<String, String> config) {
JdbcTypeConverter jdbcTypeConverter = createJdbcTypeConverter();
return new JdbcCatalogOperations(
createExceptionConverter(),
jdbcTypeConverter,
createJdbcDatabaseOperations(),
createJdbcTableOperations(),
createJdbcColumnDefaultValueConverter());
}

@Override
public Capability newCapability() {
return new ClickHouseCatalogCapability();
}

@Override
protected JdbcExceptionConverter createExceptionConverter() {
return new ClickHouseExceptionConverter();
}

@Override
protected JdbcTypeConverter createJdbcTypeConverter() {
return new ClickHouseTypeConverter();
}

@Override
protected JdbcDatabaseOperations createJdbcDatabaseOperations() {
return new ClickHouseDatabaseOperations();
}

@Override
protected JdbcTableOperations createJdbcTableOperations() {
return new ClickHouseTableOperations();
}

@Override
protected JdbcColumnDefaultValueConverter createJdbcColumnDefaultValueConverter() {
return new ClickHouseColumnDefaultValueConverter();
}

@Override
public PropertiesMetadata tablePropertiesMetadata() throws UnsupportedOperationException {
return TABLE_PROPERTIES_META;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.apache.gravitino.catalog.clickhouse;

import org.apache.gravitino.connector.capability.Capability;
import org.apache.gravitino.connector.capability.CapabilityResult;

public class ClickHouseCatalogCapability implements Capability {
/**
* Regular expression explanation: ^[\w\p{L}-$/=]{1,64}$
*
* <p>^ - Start of the string
*
* <p>[\w\p{L}-$/=]{1,64} - Consist of 1 to 64 characters of letters (both cases), digits,
* underscores, any kind of letter from any language, hyphens, dollar signs, slashes or equal
* signs
*
* <p>\w - matches [a-zA-Z0-9_]
*
* <p>\p{L} - matches any kind of letter from any language
*
* <p>$ - End of the string
*/
public static final String CLICKHOUSE_NAME_PATTERN = "^[\\w\\p{L}-$/=]{1,64}$";

@Override
public CapabilityResult specificationOnName(Scope scope, String name) {
// TODO: Validate the name against reserved words
if (!name.matches(CLICKHOUSE_NAME_PATTERN)) {
return CapabilityResult.unsupported(
String.format("The %s name '%s' is illegal.", scope, name));
}
return CapabilityResult.SUPPORTED;
}
}
Loading