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

Feature(jdbc-catalog):Add code skeleton for oceanbase-ce jdbc catalog #4918

Merged
merged 4 commits into from
Sep 19, 2024
Merged
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
48 changes: 48 additions & 0 deletions catalogs/catalog-jdbc-oceanbase/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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-oceanbase"

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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.oceanbase;

import java.util.Map;
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.catalog.oceanbase.converter.OceanBaseColumnDefaultValueConverter;
import org.apache.gravitino.catalog.oceanbase.converter.OceanBaseExceptionConverter;
import org.apache.gravitino.catalog.oceanbase.converter.OceanBaseTypeConverter;
import org.apache.gravitino.catalog.oceanbase.operation.OceanBaseDatabaseOperations;
import org.apache.gravitino.catalog.oceanbase.operation.OceanBaseTableOperations;
import org.apache.gravitino.connector.CatalogOperations;
import org.apache.gravitino.connector.capability.Capability;

/** Implementation of a OceanBase catalog in Apache Gravitino. */
public class OceanBaseCatalog extends JdbcCatalog {

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

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

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

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

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

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

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

@Override
protected JdbcColumnDefaultValueConverter createJdbcColumnDefaultValueConverter() {
return new OceanBaseColumnDefaultValueConverter();
}
}
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.oceanbase;

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

public class OceanBaseCatalogCapability 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 OCEANBASE_NAME_PATTERN = "^[\\w\\p{L}-$/=]{1,64}$";
mchades marked this conversation as resolved.
Show resolved Hide resolved

@Override
public CapabilityResult specificationOnName(Scope scope, String name) {
if (!name.matches(OCEANBASE_NAME_PATTERN)) {
return CapabilityResult.unsupported(
String.format("The %s name '%s' is illegal.", scope, name));
}
return CapabilityResult.SUPPORTED;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.oceanbase.converter;

import org.apache.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;
import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;
import org.apache.gravitino.rel.expressions.Expression;

public class OceanBaseColumnDefaultValueConverter extends JdbcColumnDefaultValueConverter {

@Override
public Expression toGravitino(
mchades marked this conversation as resolved.
Show resolved Hide resolved
JdbcTypeConverter.JdbcTypeBean type,
String columnDefaultValue,
boolean isExpression,
boolean nullable) {
throw new GravitinoRuntimeException("Not implemented yet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.oceanbase.converter;

import java.sql.SQLException;
import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;

/** Exception converter to Apache Gravitino exception for OceanBase. */
public class OceanBaseExceptionConverter extends JdbcExceptionConverter {

@SuppressWarnings("FormatStringAnnotation")
@Override
public GravitinoRuntimeException toGravitinoException(SQLException se) {
return new GravitinoRuntimeException("Not implemented yet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.oceanbase.converter;

import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;
import org.apache.gravitino.rel.types.Type;

/** Type converter for OceanBase. */
public class OceanBaseTypeConverter extends JdbcTypeConverter {

// More data types will be added.
static final String TINYINT = "tinyint";

@Override
public Type toGravitino(JdbcTypeBean typeBean) {
throw new GravitinoRuntimeException("Not implemented yet.");
}

@Override
public String fromGravitino(Type type) {
throw new GravitinoRuntimeException("Not implemented yet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.oceanbase.operation;

import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.gravitino.catalog.jdbc.JdbcSchema;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
import org.apache.gravitino.exceptions.NoSuchSchemaException;

/** Database operations for OceanBase. */
public class OceanBaseDatabaseOperations extends JdbcDatabaseOperations {

public static final Set<String> SYS_OCEANBASE_DATABASE_NAMES = createSysOceanBaseDatabaseNames();

private static Set<String> createSysOceanBaseDatabaseNames() {
Set<String> set = new HashSet<>();
set.add("information_schema");
set.add("mysql");
set.add("sys");
set.add("oceanbase");
return Collections.unmodifiableSet(set);
}

@Override
public String generateCreateDatabaseSql(
String databaseName, String comment, Map<String, String> properties) {

throw new UnsupportedOperationException("Not implemented yet.");
}

@Override
public String generateDropDatabaseSql(String databaseName, boolean cascade) {
throw new UnsupportedOperationException("Not implemented yet.");
}

@Override
public JdbcSchema load(String databaseName) throws NoSuchSchemaException {
mchades marked this conversation as resolved.
Show resolved Hide resolved
throw new UnsupportedOperationException("Not implemented yet.");
}

@Override
protected boolean isSystemDatabase(String dbName) {
return SYS_OCEANBASE_DATABASE_NAMES.contains(dbName.toLowerCase(Locale.ROOT));
}
}
Loading
Loading