-
Notifications
You must be signed in to change notification settings - Fork 406
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
[#6233] feat(flink): flink jdbc catalog #6543
Open
hdygxsj
wants to merge
3
commits into
apache:main
Choose a base branch
from
hdygxsj:jdbc-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
47 changes: 47 additions & 0 deletions
47
...r/flink/src/main/java/org/apache/gravitino/flink/connector/jdbc/GravitinoJdbcCatalog.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,47 @@ | ||
/* | ||
* 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.flink.connector.jdbc; | ||
|
||
import org.apache.flink.connector.jdbc.catalog.factory.JdbcCatalogFactory; | ||
import org.apache.flink.table.catalog.Catalog; | ||
import org.apache.flink.table.factories.CatalogFactory; | ||
import org.apache.gravitino.flink.connector.PartitionConverter; | ||
import org.apache.gravitino.flink.connector.PropertiesConverter; | ||
import org.apache.gravitino.flink.connector.catalog.BaseCatalog; | ||
|
||
public class GravitinoJdbcCatalog extends BaseCatalog { | ||
|
||
Catalog jdbcCatalog; | ||
|
||
protected GravitinoJdbcCatalog( | ||
CatalogFactory.Context context, | ||
String defaultDatabase, | ||
PropertiesConverter propertiesConverter, | ||
PartitionConverter partitionConverter) { | ||
super(context.getName(), defaultDatabase, propertiesConverter, partitionConverter); | ||
JdbcCatalogFactory jdbcCatalogFactory = new JdbcCatalogFactory(); | ||
this.jdbcCatalog = jdbcCatalogFactory.createCatalog(context); | ||
} | ||
|
||
@Override | ||
protected Catalog realCatalog() { | ||
return jdbcCatalog; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../src/main/java/org/apache/gravitino/flink/connector/jdbc/GravitinoJdbcCatalogFactory.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,50 @@ | ||
/* | ||
* 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.flink.connector.jdbc; | ||
|
||
import org.apache.gravitino.Catalog; | ||
import org.apache.gravitino.flink.connector.DefaultPartitionConverter; | ||
import org.apache.gravitino.flink.connector.PartitionConverter; | ||
import org.apache.gravitino.flink.connector.PropertiesConverter; | ||
import org.apache.gravitino.flink.connector.catalog.BaseCatalogFactory; | ||
import org.apache.gravitino.flink.connector.paimon.GravitinoPaimonCatalogFactoryOptions; | ||
|
||
public class GravitinoJdbcCatalogFactory implements BaseCatalogFactory { | ||
|
||
@Override | ||
public String gravitinoCatalogProvider() { | ||
return GravitinoPaimonCatalogFactoryOptions.IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Catalog.Type gravitinoCatalogType() { | ||
return Catalog.Type.RELATIONAL; | ||
} | ||
|
||
@Override | ||
public PropertiesConverter propertiesConverter() { | ||
return JdbcPropertiesConverter.INSTANCE; | ||
} | ||
|
||
@Override | ||
public PartitionConverter partitionConverter() { | ||
return DefaultPartitionConverter.INSTANCE; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...in/java/org/apache/gravitino/flink/connector/jdbc/GravitinoJdbcCatalogFactoryOptions.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,25 @@ | ||
/* | ||
* 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.flink.connector.jdbc; | ||
|
||
public class GravitinoJdbcCatalogFactoryOptions { | ||
|
||
public static final String IDENTIFIER = "gravitino-jdbc"; | ||
} |
54 changes: 54 additions & 0 deletions
54
...link/src/main/java/org/apache/gravitino/flink/connector/jdbc/JdbcPropertiesConstants.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,54 @@ | ||
/* | ||
* 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.flink.connector.jdbc; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class JdbcPropertiesConstants { | ||
|
||
private JdbcPropertiesConstants() {} | ||
|
||
public static final String GRAVITINO_JDBC_USER = "jdbc-user"; | ||
public static final String GRAVITINO_JDBC_PASSWORD = "jdbc-password"; | ||
public static final String GRAVITINO_JDBC_URL = "jdbc-url"; | ||
public static final String GRAVITINO_JDBC_DRIVER = "jdbc-driver"; | ||
public static final String GRAVITINO_JDBC_DEFAULT_DATABASE = "default-database"; | ||
|
||
public static final String FLINK_JDBC_URL = "base-url"; | ||
public static final String FLINK_JDBC_USER = "user"; | ||
public static final String FLINK_JDBC_PASSWORD = "password"; | ||
public static final String FLINK_JDBC_DEFAULT_DATABASE = "default-database"; | ||
|
||
public static Map<String, String> flinkToGravitinoMap = new HashMap<>(); | ||
public static Map<String, String> gravitinoToFlinkMap = new HashMap<>(); | ||
|
||
static { | ||
flinkToGravitinoMap.put(FLINK_JDBC_URL, GRAVITINO_JDBC_URL); | ||
flinkToGravitinoMap.put(FLINK_JDBC_USER, GRAVITINO_JDBC_USER); | ||
flinkToGravitinoMap.put(FLINK_JDBC_PASSWORD, GRAVITINO_JDBC_PASSWORD); | ||
flinkToGravitinoMap.put(FLINK_JDBC_DEFAULT_DATABASE, GRAVITINO_JDBC_DEFAULT_DATABASE); | ||
|
||
gravitinoToFlinkMap.put(GRAVITINO_JDBC_URL, FLINK_JDBC_URL); | ||
gravitinoToFlinkMap.put(GRAVITINO_JDBC_USER, FLINK_JDBC_USER); | ||
gravitinoToFlinkMap.put(GRAVITINO_JDBC_PASSWORD, FLINK_JDBC_PASSWORD); | ||
gravitinoToFlinkMap.put(GRAVITINO_JDBC_DEFAULT_DATABASE, FLINK_JDBC_DEFAULT_DATABASE); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...link/src/main/java/org/apache/gravitino/flink/connector/jdbc/JdbcPropertiesConverter.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,44 @@ | ||
/* | ||
* 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.flink.connector.jdbc; | ||
|
||
import org.apache.gravitino.flink.connector.PropertiesConverter; | ||
|
||
public class JdbcPropertiesConverter implements PropertiesConverter { | ||
|
||
public static final JdbcPropertiesConverter INSTANCE = new JdbcPropertiesConverter(); | ||
|
||
private JdbcPropertiesConverter() {} | ||
|
||
@Override | ||
public String transformPropertyToGravitinoCatalog(String configKey) { | ||
return JdbcPropertiesConstants.flinkToGravitinoMap.get(configKey); | ||
} | ||
|
||
@Override | ||
public String transformPropertyToFlinkCatalog(String configKey) { | ||
return JdbcPropertiesConstants.gravitinoToFlinkMap.get(configKey); | ||
} | ||
|
||
@Override | ||
public String getFlinkCatalogType() { | ||
return GravitinoJdbcCatalogFactoryOptions.IDENTIFIER; | ||
} | ||
} |
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
96 changes: 96 additions & 0 deletions
96
...a/org/apache/gravitino/flink/connector/integration/test/jdbc/FlinkJdbcMysqlCatalogIT.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,96 @@ | ||
/* | ||
* 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.flink.connector.integration.test.jdbc; | ||
|
||
import static org.apache.gravitino.integration.test.util.TestDatabaseName.MYSQL_CATALOG_MYSQL_IT; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.gravitino.Catalog; | ||
import org.apache.gravitino.flink.connector.integration.test.FlinkCommonIT; | ||
import org.apache.gravitino.flink.connector.jdbc.JdbcPropertiesConstants; | ||
import org.apache.gravitino.integration.test.container.ContainerSuite; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Tag; | ||
|
||
@Tag("gravitino-docker-test") | ||
public class FlinkJdbcMysqlCatalogIT extends FlinkCommonIT { | ||
|
||
protected String mysqlUrl; | ||
protected String mysqlUsername; | ||
protected String mysqlPassword; | ||
protected String mysqlDriver; | ||
protected String mysqlDefaultDatabase = MYSQL_CATALOG_MYSQL_IT.name(); | ||
|
||
protected Catalog catalog; | ||
|
||
protected static final String CATALOG_NAME = "test_flink_jdbc_catalog"; | ||
|
||
@Override | ||
protected Catalog currentCatalog() { | ||
return catalog; | ||
} | ||
|
||
@Override | ||
protected String getProvider() { | ||
return "jdbc-mysql"; | ||
} | ||
|
||
@BeforeAll | ||
void setup() { | ||
init(); | ||
} | ||
|
||
@Override | ||
protected boolean supportDropCascade() { | ||
return true; | ||
} | ||
|
||
private void init() { | ||
Preconditions.checkNotNull(metalake); | ||
catalog = | ||
metalake.createCatalog( | ||
CATALOG_NAME, | ||
org.apache.gravitino.Catalog.Type.RELATIONAL, | ||
getProvider(), | ||
null, | ||
ImmutableMap.of( | ||
JdbcPropertiesConstants.GRAVITINO_JDBC_USER, | ||
mysqlUsername, | ||
JdbcPropertiesConstants.GRAVITINO_JDBC_PASSWORD, | ||
mysqlPassword, | ||
JdbcPropertiesConstants.GRAVITINO_JDBC_URL, | ||
mysqlUrl, | ||
JdbcPropertiesConstants.GRAVITINO_JDBC_DRIVER, | ||
mysqlDriver, | ||
JdbcPropertiesConstants.GRAVITINO_JDBC_DEFAULT_DATABASE, | ||
mysqlDefaultDatabase)); | ||
} | ||
|
||
@Override | ||
protected void initCatalogEnv() throws Exception { | ||
ContainerSuite containerSuite = ContainerSuite.getInstance(); | ||
containerSuite.startMySQLContainer(MYSQL_CATALOG_MYSQL_IT); | ||
mysqlUrl = containerSuite.getMySQLContainer().getJdbcUrl(); | ||
mysqlUsername = containerSuite.getMySQLContainer().getUsername(); | ||
mysqlPassword = containerSuite.getMySQLContainer().getPassword(); | ||
mysqlDriver = containerSuite.getMySQLContainer().getDriverClassName(MYSQL_CATALOG_MYSQL_IT); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we need to add some javadocs for some public classes.