-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
603 additions
and
2 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
47 changes: 47 additions & 0 deletions
47
...ink/src/main/java/org/apache/gravitino/flink/connector/paimon/GravitinoPaimonCatalog.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.paimon; | ||
|
||
import org.apache.flink.table.catalog.AbstractCatalog; | ||
import org.apache.gravitino.flink.connector.PartitionConverter; | ||
import org.apache.gravitino.flink.connector.PropertiesConverter; | ||
import org.apache.gravitino.flink.connector.catalog.BaseCatalog; | ||
|
||
/** | ||
* The GravitinoPaimonCatalog class is an implementation of the BaseCatalog class that is used to | ||
* proxy the PaimonCatalog class. | ||
*/ | ||
public class GravitinoPaimonCatalog extends BaseCatalog { | ||
|
||
private AbstractCatalog paimonCatalog; | ||
|
||
protected GravitinoPaimonCatalog( | ||
String catalogName, | ||
AbstractCatalog paimonCatalog, | ||
PropertiesConverter propertiesConverter, | ||
PartitionConverter partitionConverter) { | ||
super(catalogName, paimonCatalog.getDefaultDatabase(), propertiesConverter, partitionConverter); | ||
} | ||
|
||
@Override | ||
protected AbstractCatalog realCatalog() { | ||
return paimonCatalog; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
.../main/java/org/apache/gravitino/flink/connector/paimon/GravitinoPaimonCatalogFactory.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,81 @@ | ||
/* | ||
* 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.paimon; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import org.apache.flink.configuration.ConfigOption; | ||
import org.apache.flink.table.catalog.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.paimon.flink.FlinkCatalog; | ||
import org.apache.paimon.flink.FlinkCatalogFactory; | ||
|
||
/** | ||
* Factory for creating instances of {@link GravitinoPaimonCatalog}. It will be created by SPI | ||
* discovery in Flink. | ||
*/ | ||
public class GravitinoPaimonCatalogFactory implements BaseCatalogFactory { | ||
|
||
@Override | ||
public Catalog createCatalog(Context context) { | ||
FlinkCatalog catalog = new FlinkCatalogFactory().createCatalog(context); | ||
return new GravitinoPaimonCatalog( | ||
context.getName(), catalog, propertiesConverter(), partitionConverter()); | ||
} | ||
|
||
@Override | ||
public String factoryIdentifier() { | ||
return GravitinoPaimonCatalogFactoryOptions.IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Set<ConfigOption<?>> requiredOptions() { | ||
return ImmutableSet.of(GravitinoPaimonCatalogFactoryOptions.CATALOG_BACKEND); | ||
} | ||
|
||
@Override | ||
public Set<ConfigOption<?>> optionalOptions() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public String gravitinoCatalogProvider() { | ||
return "lakehouse-paimon"; | ||
} | ||
|
||
@Override | ||
public org.apache.gravitino.Catalog.Type gravitinoCatalogType() { | ||
return org.apache.gravitino.Catalog.Type.RELATIONAL; | ||
} | ||
|
||
@Override | ||
public PropertiesConverter propertiesConverter() { | ||
return PaimonPropertiesConverter.INSTANCE; | ||
} | ||
|
||
@Override | ||
public PartitionConverter partitionConverter() { | ||
return DefaultPartitionConverter.INSTANCE; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ava/org/apache/gravitino/flink/connector/paimon/GravitinoPaimonCatalogFactoryOptions.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,46 @@ | ||
/* | ||
* 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.paimon; | ||
|
||
import org.apache.flink.configuration.ConfigOption; | ||
import org.apache.flink.configuration.ConfigOptions; | ||
|
||
public class GravitinoPaimonCatalogFactoryOptions { | ||
|
||
/** Identifier for the {@link GravitinoPaimonCatalog}. */ | ||
public static final String IDENTIFIER = "gravitino-paimon"; | ||
|
||
public static ConfigOption<String> CATALOG_BACKEND = | ||
ConfigOptions.key("catalog.backend") | ||
.stringType() | ||
.defaultValue("fileSystem") | ||
.withDescription(""); | ||
|
||
public static ConfigOption<String> WAREHOUSE = | ||
ConfigOptions.key("warehouse").stringType().noDefaultValue(); | ||
|
||
public static ConfigOption<String> URI = ConfigOptions.key("uri").stringType().noDefaultValue(); | ||
|
||
public static ConfigOption<String> JDBC_USER = | ||
ConfigOptions.key("jdbc.user").stringType().noDefaultValue(); | ||
|
||
public static ConfigOption<String> JDBC_PASSWORD = | ||
ConfigOptions.key("jdbc.password").stringType().noDefaultValue(); | ||
} |
90 changes: 90 additions & 0 deletions
90
.../src/main/java/org/apache/gravitino/flink/connector/paimon/PaimonPropertiesConverter.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,90 @@ | ||
/* | ||
* 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.paimon; | ||
|
||
import com.google.common.collect.Maps; | ||
import java.util.Map; | ||
import org.apache.flink.configuration.Configuration; | ||
import org.apache.flink.table.catalog.CommonCatalogOptions; | ||
import org.apache.gravitino.catalog.lakehouse.paimon.PaimonCatalogBackend; | ||
import org.apache.gravitino.catalog.lakehouse.paimon.PaimonCatalogPropertiesMetadata; | ||
import org.apache.gravitino.catalog.lakehouse.paimon.PaimonConfig; | ||
import org.apache.gravitino.flink.connector.PropertiesConverter; | ||
import org.apache.paimon.options.CatalogOptions; | ||
|
||
public class PaimonPropertiesConverter implements PropertiesConverter { | ||
|
||
public static final PaimonPropertiesConverter INSTANCE = new PaimonPropertiesConverter(); | ||
|
||
private PaimonPropertiesConverter() {} | ||
|
||
@Override | ||
public Map<String, String> toGravitinoCatalogProperties(Configuration flinkConf) { | ||
Map<String, String> gravitinoCatalogProperties = flinkConf.toMap(); | ||
String warehouse = flinkConf.get(GravitinoPaimonCatalogFactoryOptions.WAREHOUSE); | ||
gravitinoCatalogProperties.put(PaimonConfig.CATALOG_WAREHOUSE.getKey(), warehouse); | ||
String backendType = flinkConf.get(GravitinoPaimonCatalogFactoryOptions.CATALOG_BACKEND); | ||
gravitinoCatalogProperties.put( | ||
PaimonCatalogPropertiesMetadata.GRAVITINO_CATALOG_BACKEND, backendType); | ||
if (PaimonCatalogBackend.JDBC.name().equalsIgnoreCase(backendType)) { | ||
gravitinoCatalogProperties.put( | ||
PaimonConfig.CATALOG_URI.getKey(), | ||
flinkConf.get(GravitinoPaimonCatalogFactoryOptions.URI)); | ||
gravitinoCatalogProperties.put( | ||
PaimonConfig.CATALOG_JDBC_USER.getKey(), | ||
flinkConf.get(GravitinoPaimonCatalogFactoryOptions.JDBC_USER)); | ||
gravitinoCatalogProperties.put( | ||
PaimonConfig.CATALOG_JDBC_PASSWORD.getKey(), | ||
flinkConf.get(GravitinoPaimonCatalogFactoryOptions.JDBC_PASSWORD)); | ||
} else if (PaimonCatalogBackend.HIVE.name().equalsIgnoreCase(backendType)) { | ||
throw new UnsupportedOperationException( | ||
"The Gravitino Connector does not currently support creating a Paimon Catalog that uses Hive Metastore."); | ||
} | ||
return gravitinoCatalogProperties; | ||
} | ||
|
||
@Override | ||
public Map<String, String> toFlinkCatalogProperties(Map<String, String> gravitinoProperties) { | ||
Map<String, String> flinkCatalogProperties = Maps.newHashMap(); | ||
flinkCatalogProperties.putAll(gravitinoProperties); | ||
String backendType = | ||
flinkCatalogProperties.get(PaimonCatalogPropertiesMetadata.GRAVITINO_CATALOG_BACKEND); | ||
if (PaimonCatalogBackend.JDBC.name().equalsIgnoreCase(backendType)) { | ||
flinkCatalogProperties.put(CatalogOptions.METASTORE.key(), backendType); | ||
flinkCatalogProperties.put( | ||
GravitinoPaimonCatalogFactoryOptions.URI.key(), | ||
gravitinoProperties.get(PaimonConfig.CATALOG_URI.getKey())); | ||
flinkCatalogProperties.put( | ||
GravitinoPaimonCatalogFactoryOptions.JDBC_USER.key(), | ||
gravitinoProperties.get(PaimonConfig.CATALOG_JDBC_USER.getKey())); | ||
flinkCatalogProperties.put( | ||
GravitinoPaimonCatalogFactoryOptions.JDBC_PASSWORD.key(), | ||
gravitinoProperties.get(PaimonConfig.CATALOG_JDBC_PASSWORD.getKey())); | ||
} else if (PaimonCatalogBackend.HIVE.name().equalsIgnoreCase(backendType)) { | ||
throw new UnsupportedOperationException( | ||
"The Gravitino Connector does not currently support creating a Paimon Catalog that uses Hive Metastore."); | ||
} | ||
flinkCatalogProperties.put( | ||
GravitinoPaimonCatalogFactoryOptions.CATALOG_BACKEND.key(), backendType); | ||
flinkCatalogProperties.put( | ||
CommonCatalogOptions.CATALOG_TYPE.key(), GravitinoPaimonCatalogFactoryOptions.IDENTIFIER); | ||
return flinkCatalogProperties; | ||
} | ||
} |
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.