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

[#5014]feat: add the basic module of catalog-jdbc-maxcompute #5488

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.gradle.internal.hash.ChecksumService
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.support.serviceOf
import java.io.IOException
import java.util.Locale
import java.util.*

plugins {
`maven-publish`
Expand Down Expand Up @@ -809,6 +809,7 @@ tasks {
":catalogs:catalog-jdbc-mysql:copyLibAndConfig",
":catalogs:catalog-jdbc-oceanbase:copyLibAndConfig",
":catalogs:catalog-jdbc-postgresql:copyLibAndConfig",
":catalogs:catalog-jdbc-maxcompute:copyLibAndConfig",
":catalogs:catalog-hadoop:copyLibAndConfig",
":catalogs:catalog-kafka:copyLibAndConfig"
)
Expand Down
103 changes: 103 additions & 0 deletions catalogs/catalog-jdbc-maxcompute/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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-maxcompute"

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

dependencies {

implementation(project(":api")) {
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.odps.jdbc)
implementation(libs.postgresql.driver)
implementation(project(mapOf("path" to ":catalogs:catalog-jdbc-common")))

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.odps.jdbc)
testImplementation(libs.postgresql.driver)
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-maxcompute/libs")
}

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

include("jdbc-maxcompute.conf")

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

fileMode = 0b111101101
}

val copyLibAndConfig by registering(Copy::class) {
dependsOn(copyCatalogLibs, copyCatalogConfig)
}
}

tasks.test{
enabled = false
}

tasks.getByName("generateMetadataFileForMavenJavaPublication") {
dependsOn("runtimeJars")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.maxcompute;

import java.util.Map;
import org.apache.gravitino.catalog.jdbc.JdbcCatalog;
import org.apache.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;
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.catalog.maxcompute.converter.MaxComputeColumnDefaultValueConverter;
import org.apache.gravitino.catalog.maxcompute.converter.MaxComputeTypeConverter;
import org.apache.gravitino.catalog.maxcompute.operation.MaxComputeSchemaOpeartions;
import org.apache.gravitino.catalog.maxcompute.operation.MaxComputeTableOpeations;
import org.apache.gravitino.connector.CatalogOperations;

public class MaxComputeCatalog extends JdbcCatalog {

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

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

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

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

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

@Override
protected JdbcColumnDefaultValueConverter createJdbcColumnDefaultValueConverter() {
return new MaxComputeColumnDefaultValueConverter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.maxcompute;

import org.apache.gravitino.catalog.jdbc.JdbcCatalogCapability;

public class MaxComputeCatalogCapability extends JdbcCatalogCapability {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.maxcompute;

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;

public class MaxComputeCatalogOperations extends JdbcCatalogOperations {

public MaxComputeCatalogOperations(
JdbcExceptionConverter exceptionConverter,
JdbcTypeConverter jdbcTypeConverter,
JdbcDatabaseOperations databaseOperation,
JdbcTableOperations tableOperation,
JdbcColumnDefaultValueConverter columnDefaultValueConverter) {
super(
exceptionConverter,
jdbcTypeConverter,
databaseOperation,
tableOperation,
columnDefaultValueConverter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.maxcompute.converter;

import static org.apache.gravitino.rel.Column.DEFAULT_VALUE_NOT_SET;
import static org.apache.gravitino.rel.Column.DEFAULT_VALUE_OF_CURRENT_TIMESTAMP;

import java.time.LocalDate;
import java.time.LocalDateTime;
import org.apache.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;
import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
import org.apache.gravitino.rel.expressions.Expression;
import org.apache.gravitino.rel.expressions.UnparsedExpression;
import org.apache.gravitino.rel.expressions.literals.Literals;
import org.apache.gravitino.rel.types.Decimal;
import org.apache.gravitino.rel.types.Types;

public class MaxComputeColumnDefaultValueConverter extends JdbcColumnDefaultValueConverter {

@Override
public Expression toGravitino(
JdbcTypeConverter.JdbcTypeBean type,
String columnDefaultValue,
boolean isExpression,
boolean nullable) {
if (columnDefaultValue == null) {
return nullable ? Literals.NULL : DEFAULT_VALUE_NOT_SET;
}

if (columnDefaultValue.equalsIgnoreCase(NULL)) {
return Literals.NULL;
}

if (isExpression) {
if (columnDefaultValue.equals(CURRENT_TIMESTAMP)) {
return DEFAULT_VALUE_OF_CURRENT_TIMESTAMP;
}
// The parsing of MaxCompute expressions is complex, so we are not currently undertaking the
// parsing.
return UnparsedExpression.of(columnDefaultValue);
}

switch (type.getTypeName().toLowerCase()) {
case MaxComputeTypeConverter.TINYINT:
return Literals.byteLiteral(Byte.valueOf(columnDefaultValue));
case MaxComputeTypeConverter.SMALLINT:
return Literals.shortLiteral(Short.valueOf(columnDefaultValue));
case MaxComputeTypeConverter.INT:
return Literals.integerLiteral(Integer.valueOf(columnDefaultValue));
case MaxComputeTypeConverter.BIGINT:
return Literals.longLiteral(Long.valueOf(columnDefaultValue));
case MaxComputeTypeConverter.FLOAT:
return Literals.floatLiteral(Float.valueOf(columnDefaultValue));
case MaxComputeTypeConverter.DOUBLE:
return Literals.doubleLiteral(Double.valueOf(columnDefaultValue));
case MaxComputeTypeConverter.DECIMAL:
return Literals.decimalLiteral(
Decimal.of(
columnDefaultValue,
Integer.parseInt(type.getColumnSize()),
Integer.parseInt(type.getScale())));
case JdbcTypeConverter.DATE:
return Literals.dateLiteral(LocalDate.parse(columnDefaultValue, DATE_FORMATTER));
case JdbcTypeConverter.TIMESTAMP:
case MaxComputeTypeConverter.DATETIME:
return CURRENT_TIMESTAMP.equals(columnDefaultValue)
? DEFAULT_VALUE_OF_CURRENT_TIMESTAMP
: Literals.timestampLiteral(
LocalDateTime.parse(columnDefaultValue, DATE_TIME_FORMATTER));
case JdbcTypeConverter.VARCHAR:
return Literals.of(
columnDefaultValue, Types.VarCharType.of(Integer.parseInt(type.getColumnSize())));
case MaxComputeTypeConverter.CHAR:
return Literals.of(
columnDefaultValue, Types.FixedCharType.of(Integer.parseInt(type.getColumnSize())));
case MaxComputeTypeConverter.STRING:
return Literals.stringLiteral(columnDefaultValue);
case MaxComputeTypeConverter.BOOLEAN:
return Literals.booleanLiteral(Boolean.valueOf(columnDefaultValue));
default:
return UnparsedExpression.of(columnDefaultValue);
}
}
}
Loading
Loading