forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Connector-V2][Jdbc] Add OceanBase catalog (apache#5439)
* feat: add oceanbase jdbc catalog * remove oceanbase-client and disable it cases * update EXCLUDE_SCHEMAS and skip database check in OceanBase Oracle mode
- Loading branch information
Showing
11 changed files
with
466 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...apache/seatunnel/connectors/seatunnel/jdbc/catalog/oceanbase/OceanBaseCatalogFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.jdbc.catalog.oceanbase; | ||
|
||
import org.apache.seatunnel.shade.com.google.common.base.Preconditions; | ||
|
||
import org.apache.seatunnel.api.configuration.ReadonlyConfig; | ||
import org.apache.seatunnel.api.configuration.util.OptionRule; | ||
import org.apache.seatunnel.api.configuration.util.OptionValidationException; | ||
import org.apache.seatunnel.api.table.catalog.Catalog; | ||
import org.apache.seatunnel.api.table.factory.CatalogFactory; | ||
import org.apache.seatunnel.api.table.factory.Factory; | ||
import org.apache.seatunnel.common.utils.JdbcUrlUtil; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.JdbcCatalogOptions; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
import java.util.Optional; | ||
|
||
@AutoService(Factory.class) | ||
public class OceanBaseCatalogFactory implements CatalogFactory { | ||
|
||
public static final String IDENTIFIER = "OceanBase"; | ||
|
||
@Override | ||
public String factoryIdentifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Catalog createCatalog(String catalogName, ReadonlyConfig options) { | ||
String urlWithDatabase = options.get(JdbcCatalogOptions.BASE_URL); | ||
Preconditions.checkArgument( | ||
StringUtils.isNoneBlank(urlWithDatabase), | ||
"Miss config <base-url>! Please check your config."); | ||
JdbcUrlUtil.UrlInfo urlInfo = JdbcUrlUtil.getUrlInfo(urlWithDatabase); | ||
Optional<String> defaultDatabase = urlInfo.getDefaultDatabase(); | ||
if (!defaultDatabase.isPresent()) { | ||
throw new OptionValidationException(JdbcCatalogOptions.BASE_URL); | ||
} | ||
|
||
String compatibleMode = options.get(JdbcCatalogOptions.COMPATIBLE_MODE); | ||
Preconditions.checkArgument( | ||
StringUtils.isNoneBlank(compatibleMode), | ||
"Miss config <compatibleMode>! Please check your config."); | ||
|
||
if ("oracle".equalsIgnoreCase(compatibleMode.trim())) { | ||
return new OceanBaseOracleCatalog( | ||
catalogName, | ||
options.get(JdbcCatalogOptions.USERNAME), | ||
options.get(JdbcCatalogOptions.PASSWORD), | ||
urlInfo, | ||
options.get(JdbcCatalogOptions.SCHEMA)); | ||
} | ||
return new OceanBaseMySqlCatalog( | ||
catalogName, | ||
options.get(JdbcCatalogOptions.USERNAME), | ||
options.get(JdbcCatalogOptions.PASSWORD), | ||
urlInfo); | ||
} | ||
|
||
@Override | ||
public OptionRule optionRule() { | ||
return JdbcCatalogOptions.BASE_RULE.required(JdbcCatalogOptions.COMPATIBLE_MODE).build(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...g/apache/seatunnel/connectors/seatunnel/jdbc/catalog/oceanbase/OceanBaseMySqlCatalog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.jdbc.catalog.oceanbase; | ||
|
||
import org.apache.seatunnel.common.utils.JdbcUrlUtil; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.mysql.MySqlCatalog; | ||
|
||
public class OceanBaseMySqlCatalog extends MySqlCatalog { | ||
|
||
static { | ||
SYS_DATABASES.clear(); | ||
SYS_DATABASES.add("information_schema"); | ||
SYS_DATABASES.add("mysql"); | ||
SYS_DATABASES.add("oceanbase"); | ||
SYS_DATABASES.add("LBACSYS"); | ||
SYS_DATABASES.add("ORAAUDITOR"); | ||
SYS_DATABASES.add("SYS"); | ||
} | ||
|
||
public OceanBaseMySqlCatalog( | ||
String catalogName, String username, String pwd, JdbcUrlUtil.UrlInfo urlInfo) { | ||
super(catalogName, username, pwd, urlInfo); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
.../apache/seatunnel/connectors/seatunnel/jdbc/catalog/oceanbase/OceanBaseOracleCatalog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.jdbc.catalog.oceanbase; | ||
|
||
import org.apache.seatunnel.api.table.catalog.CatalogTable; | ||
import org.apache.seatunnel.api.table.catalog.TablePath; | ||
import org.apache.seatunnel.api.table.catalog.exception.CatalogException; | ||
import org.apache.seatunnel.api.table.catalog.exception.DatabaseNotExistException; | ||
import org.apache.seatunnel.api.table.catalog.exception.TableAlreadyExistException; | ||
import org.apache.seatunnel.common.utils.JdbcUrlUtil; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.oracle.OracleCatalog; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.apache.seatunnel.shade.com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public class OceanBaseOracleCatalog extends OracleCatalog { | ||
|
||
static { | ||
EXCLUDED_SCHEMAS = | ||
Collections.unmodifiableList( | ||
Arrays.asList("oceanbase", "LBACSYS", "ORAAUDITOR", "SYS")); | ||
} | ||
|
||
public OceanBaseOracleCatalog( | ||
String catalogName, | ||
String username, | ||
String pwd, | ||
JdbcUrlUtil.UrlInfo urlInfo, | ||
String defaultSchema) { | ||
super(catalogName, username, pwd, urlInfo, defaultSchema); | ||
} | ||
|
||
@Override | ||
protected String getListDatabaseSql() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public List<String> listTables(String databaseName) | ||
throws CatalogException, DatabaseNotExistException { | ||
String dbUrl = getUrlFromDatabaseName(databaseName); | ||
try { | ||
return queryString(dbUrl, getListTableSql(databaseName), this::getTableName); | ||
} catch (Exception e) { | ||
throw new CatalogException( | ||
String.format("Failed listing database in catalog %s", catalogName), e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean tableExists(TablePath tablePath) throws CatalogException { | ||
try { | ||
return listTables(tablePath.getDatabaseName()).contains(getTableName(tablePath)); | ||
} catch (DatabaseNotExistException e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void createTable(TablePath tablePath, CatalogTable table, boolean ignoreIfExists) | ||
throws TableAlreadyExistException, DatabaseNotExistException, CatalogException { | ||
checkNotNull(tablePath, "Table path cannot be null"); | ||
|
||
if (defaultSchema.isPresent()) { | ||
tablePath = | ||
new TablePath( | ||
tablePath.getDatabaseName(), | ||
defaultSchema.get(), | ||
tablePath.getTableName()); | ||
} | ||
|
||
if (tableExists(tablePath)) { | ||
if (ignoreIfExists) { | ||
return; | ||
} | ||
throw new TableAlreadyExistException(catalogName, tablePath); | ||
} | ||
|
||
createTableInternal(tablePath, table); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.