Skip to content

Commit

Permalink
Add a basic skeleton for Doris catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoukangcn committed Mar 16, 2024
1 parent ffb80e7 commit e2c4cda
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ tasks {
dependsOn(
":catalogs:catalog-hive:copyLibAndConfig",
":catalogs:catalog-lakehouse-iceberg:copyLibAndConfig",
":catalogs:catalog-jdbc-doris:copyLibAndConfig",
":catalogs:catalog-jdbc-mysql:copyLibAndConfig",
":catalogs:catalog-jdbc-postgresql:copyLibAndConfig",
":catalogs:catalog-hadoop:copyLibAndConfig",
Expand Down
87 changes: 87 additions & 0 deletions catalogs/catalog-jdbc-doris/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
description = "catalog-jdbc-doris"

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

dependencies {
implementation(project(":api"))
implementation(project(":catalogs:catalog-jdbc-common"))
implementation(project(":common"))
implementation(project(":core"))

implementation(libs.bundles.log4j)
implementation(libs.commons.collections4)
implementation(libs.commons.lang3)
implementation(libs.guava)
implementation(libs.jsqlparser)
implementation(libs.slf4j.api)

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.commons.lang3)
testImplementation(libs.guava)
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testImplementation(libs.mysql.driver)
testImplementation(libs.testcontainers)
testImplementation(libs.testcontainers.mysql)

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")
into("$rootDir/distribution/package/catalogs/jdbc-doris/libs")
}

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

include("jdbc-doris.conf")

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

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

tasks.test {
val skipUTs = project.hasProperty("skipTests")
if (skipUTs) {
// Only run integration tests
include("**/integration/**")
}

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

val init = project.extra.get("initIntegrationTest") as (Test) -> Unit
init(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.catalog.doris;

import com.datastrato.gravitino.catalog.doris.converter.DorisColumnDefaultValueConverter;
import com.datastrato.gravitino.catalog.doris.converter.DorisExceptionConverter;
import com.datastrato.gravitino.catalog.doris.converter.DorisTypeConverter;
import com.datastrato.gravitino.catalog.doris.operation.DorisDatabaseOperations;
import com.datastrato.gravitino.catalog.doris.operation.DorisTableOperations;
import com.datastrato.gravitino.catalog.jdbc.JdbcCatalog;
import com.datastrato.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;
import com.datastrato.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import com.datastrato.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
import com.datastrato.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
import com.datastrato.gravitino.catalog.jdbc.operation.JdbcTableOperations;

/** Implementation of a Doris catalog in Gravitino. */
public class DorisCatalog extends JdbcCatalog {

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

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

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

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

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

@Override
protected JdbcColumnDefaultValueConverter createJdbcColumnDefaultValueConverter() {
return new DorisColumnDefaultValueConverter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.catalog.doris.converter;

import static com.datastrato.gravitino.rel.Column.DEFAULT_VALUE_NOT_SET;

import com.datastrato.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;
import com.datastrato.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
import com.datastrato.gravitino.rel.expressions.Expression;

public class DorisColumnDefaultValueConverter extends JdbcColumnDefaultValueConverter {
@Override
public Expression toGravitino(
JdbcTypeConverter.JdbcTypeBean columnType,
String columnDefaultValue,
boolean isExpression,
boolean nullable) {
// TODO: add implementation for doris catalog
return DEFAULT_VALUE_NOT_SET;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.catalog.doris.converter;

import com.datastrato.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import com.datastrato.gravitino.exceptions.GravitinoRuntimeException;
import java.sql.SQLException;

/** Exception converter to gravitino exception for Doris. */
public class DorisExceptionConverter extends JdbcExceptionConverter {
@SuppressWarnings("FormatStringAnnotation")
@Override
public GravitinoRuntimeException toGravitinoException(SQLException se) {
// TODO: add implementation for doris catalog

return super.toGravitinoException(se);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.catalog.doris.converter;

import com.datastrato.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
import com.datastrato.gravitino.rel.types.Type;
import com.datastrato.gravitino.rel.types.Types;

/** Type converter for Doris. */
public class DorisTypeConverter extends JdbcTypeConverter<String> {
// TODO: add implementation for doris catalog

@Override
public Type toGravitinoType(JdbcTypeBean typeBean) {
return Types.UnparsedType.of(typeBean.getTypeName());
}

@Override
public String fromGravitinoType(Type type) {
throw new IllegalArgumentException("unsupported type: " + type.simpleString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.catalog.doris.operation;

import com.datastrato.gravitino.catalog.jdbc.JdbcSchema;
import com.datastrato.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
import com.datastrato.gravitino.exceptions.NoSuchSchemaException;
import java.util.Map;

/** Database operations for Doris. */
public class DorisDatabaseOperations extends JdbcDatabaseOperations {
// TODO: add implementation for doris catalog

@Override
public JdbcSchema load(String databaseName) throws NoSuchSchemaException {
throw new UnsupportedOperationException();
}

@Override
protected String generateCreateDatabaseSql(
String databaseName, String comment, Map<String, String> properties) {
throw new UnsupportedOperationException();
}

@Override
protected String generateDropDatabaseSql(String databaseName, boolean cascade) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.catalog.doris.operation;

import com.datastrato.gravitino.catalog.jdbc.JdbcColumn;
import com.datastrato.gravitino.catalog.jdbc.JdbcTable;
import com.datastrato.gravitino.catalog.jdbc.operation.JdbcTableOperations;
import com.datastrato.gravitino.rel.TableChange;
import com.datastrato.gravitino.rel.expressions.transforms.Transform;
import com.datastrato.gravitino.rel.indexes.Index;
import java.util.Map;

/** Table operations for Doris. */
public class DorisTableOperations extends JdbcTableOperations {
// TODO: add implementation for doris catalog

@Override
protected String generateCreateTableSql(
String tableName,
JdbcColumn[] columns,
String comment,
Map<String, String> properties,
Transform[] partitioning,
Index[] indexes) {
throw new UnsupportedOperationException();
}

@Override
protected String generateRenameTableSql(String oldTableName, String newTableName) {
throw new UnsupportedOperationException();
}

@Override
protected String generateDropTableSql(String tableName) {
throw new UnsupportedOperationException();
}

@Override
protected String generatePurgeTableSql(String tableName) {
throw new UnsupportedOperationException();
}

@Override
protected String generateAlterTableSql(
String databaseName, String tableName, TableChange... changes) {
throw new UnsupportedOperationException();
}

@Override
protected JdbcTable getOrCreateTable(
String databaseName, String tableName, JdbcTable lazyLoadCreateTable) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Copyright 2024 Datastrato Pvt Ltd.
# This software is licensed under the Apache License version 2.
#
com.datastrato.gravitino.catalog.doris.DorisCatalog
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright 2024 Datastrato Pvt Ltd.
# This software is licensed under the Apache License version 2.
#
# jdbc-url: jdbc:mysql://localhost:9030/
# jdbc-user: strato
# jdbc-password: strato
# jdbc-driver: com.mysql.jdbc.Driver
7 changes: 6 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ include("api", "common", "core", "meta", "server", "integration-test", "server-c
include("catalogs:bundled-catalog")
include("catalogs:catalog-hive")
include("catalogs:catalog-lakehouse-iceberg")
include("catalogs:catalog-jdbc-common", "catalogs:catalog-jdbc-mysql", "catalogs:catalog-jdbc-postgresql")
include(
"catalogs:catalog-jdbc-common",
"catalogs:catalog-jdbc-mysql",
"catalogs:catalog-jdbc-postgresql",
"catalogs:catalog-jdbc-doris"
)
include("catalogs:catalog-hadoop")
include("catalogs:catalog-messaging-kafka")
include("clients:client-java", "clients:client-java-runtime")
Expand Down

0 comments on commit e2c4cda

Please sign in to comment.