-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
… paimon-catalog (#5818) ### What changes were proposed in this pull request? Support Catalog Operation DDL for paimon-catalog ### Why are the changes needed? Fix #5192 #5193 ### Does this PR introduce _any_ user-facing change? None ### How was this patch tested? org.apache.gravitino.flink.connector.paimon.TestPaimonPropertiesConverter org.apache.gravitino.flink.connector.integration.test.paimon.FlinkPaimonCatalogIT
- Loading branch information
Showing
11 changed files
with
536 additions
and
21 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
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
48 changes: 48 additions & 0 deletions
48
...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,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. | ||
*/ | ||
|
||
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 final AbstractCatalog paimonCatalog; | ||
|
||
protected GravitinoPaimonCatalog( | ||
String catalogName, | ||
AbstractCatalog paimonCatalog, | ||
PropertiesConverter propertiesConverter, | ||
PartitionConverter partitionConverter) { | ||
super(catalogName, paimonCatalog.getDefaultDatabase(), propertiesConverter, partitionConverter); | ||
this.paimonCatalog = paimonCatalog; | ||
} | ||
|
||
@Override | ||
protected AbstractCatalog realCatalog() { | ||
return paimonCatalog; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
.../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,80 @@ | ||
/* | ||
* 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 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 Collections.emptySet(); | ||
} | ||
|
||
@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; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...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,26 @@ | ||
/* | ||
* 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; | ||
|
||
public class GravitinoPaimonCatalogFactoryOptions { | ||
|
||
/** Identifier for the {@link GravitinoPaimonCatalog}. */ | ||
public static final String IDENTIFIER = "gravitino-paimon"; | ||
} |
80 changes: 80 additions & 0 deletions
80
.../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,80 @@ | ||
/* | ||
* 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.HashMap; | ||
import java.util.Map; | ||
import org.apache.flink.configuration.Configuration; | ||
import org.apache.flink.table.catalog.CommonCatalogOptions; | ||
import org.apache.gravitino.catalog.lakehouse.paimon.PaimonConstants; | ||
import org.apache.gravitino.catalog.lakehouse.paimon.PaimonPropertiesUtils; | ||
import org.apache.gravitino.flink.connector.PropertiesConverter; | ||
import org.apache.paimon.catalog.FileSystemCatalogFactory; | ||
|
||
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> gravitinoProperties = Maps.newHashMap(); | ||
Map<String, String> flinkConfMap = flinkConf.toMap(); | ||
for (Map.Entry<String, String> entry : flinkConfMap.entrySet()) { | ||
String gravitinoKey = | ||
PaimonPropertiesUtils.PAIMON_CATALOG_CONFIG_TO_GRAVITINO.get(entry.getKey()); | ||
if (gravitinoKey != null) { | ||
gravitinoProperties.put(gravitinoKey, entry.getValue()); | ||
} else if (!entry.getKey().startsWith(FLINK_PROPERTY_PREFIX)) { | ||
gravitinoProperties.put(FLINK_PROPERTY_PREFIX + entry.getKey(), entry.getValue()); | ||
} else { | ||
gravitinoProperties.put(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
gravitinoProperties.put( | ||
PaimonConstants.CATALOG_BACKEND, | ||
flinkConfMap.getOrDefault(PaimonConstants.METASTORE, FileSystemCatalogFactory.IDENTIFIER)); | ||
return gravitinoProperties; | ||
} | ||
|
||
@Override | ||
public Map<String, String> toFlinkCatalogProperties(Map<String, String> gravitinoProperties) { | ||
Map<String, String> all = new HashMap<>(); | ||
gravitinoProperties.forEach( | ||
(key, value) -> { | ||
String flinkConfigKey = key; | ||
if (key.startsWith(PropertiesConverter.FLINK_PROPERTY_PREFIX)) { | ||
flinkConfigKey = key.substring(PropertiesConverter.FLINK_PROPERTY_PREFIX.length()); | ||
} | ||
all.put(flinkConfigKey, value); | ||
}); | ||
Map<String, String> paimonCatalogProperties = | ||
PaimonPropertiesUtils.toPaimonCatalogProperties(all); | ||
paimonCatalogProperties.put( | ||
PaimonConstants.METASTORE, | ||
paimonCatalogProperties.getOrDefault( | ||
PaimonConstants.CATALOG_BACKEND, FileSystemCatalogFactory.IDENTIFIER)); | ||
paimonCatalogProperties.put( | ||
CommonCatalogOptions.CATALOG_TYPE.key(), GravitinoPaimonCatalogFactoryOptions.IDENTIFIER); | ||
return paimonCatalogProperties; | ||
} | ||
} |
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.