-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[filesystems] Supported Tencent Cloud COS filesystem
- Loading branch information
1 parent
2b894ca
commit b58c594
Showing
10 changed files
with
906 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
title: "cosn" | ||
weight: 3 | ||
type: docs | ||
aliases: | ||
- /filesystems/cosn.html | ||
--- | ||
<!-- | ||
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. | ||
--> | ||
|
||
# cosn | ||
|
||
{{< stable >}} | ||
|
||
Download [paimon-cosn-{{< version >}}.jar](https://repo.maven.apache.org/maven2/org/apache/paimon/paimon-cosn/{{< version >}}/paimon-oss-{{< version >}}.jar). | ||
|
||
{{< /stable >}} | ||
|
||
{{< unstable >}} | ||
|
||
Download [paimon-cosn-{{< version >}}.jar](https://repository.apache.org/snapshots/org/apache/paimon/paimon-cosn/{{< version >}}/). | ||
|
||
{{< /unstable >}} | ||
|
||
{{< tabs "cosn" >}} | ||
|
||
{{< tab "Flink" >}} | ||
|
||
Put `paimon-cosn-{{< version >}}.jar` into `lib` directory of your Flink home, and create catalog: | ||
|
||
```sql | ||
CREATE CATALOG my_catalog WITH ( | ||
'type' = 'paimon', | ||
'warehouse' = 'cosn://<bucket>/<path>', | ||
'fs.cosn.bucket.endpoint_suffix' = 'cos.ap-beijing.myqcloud.com', | ||
'fs.cosn.userinfo.secretId' = 'AKIDxxxx', | ||
'fs.cosn.userinfo.secretKey' = 'yyy' | ||
); | ||
``` | ||
|
||
{{< /tab >}} | ||
|
||
{{< tab "Spark" >}} | ||
|
||
{{< hint info >}} | ||
If you have already configured cosn access through Spark (Via Hadoop FileSystem), here you can skip the following configuration. | ||
{{< /hint >}} | ||
|
||
Place `paimon-cosn-{{< version >}}.jar` together with `paimon-spark-{{< version >}}.jar` under Spark's jars directory, and start like | ||
|
||
```shell | ||
spark-sql \ | ||
--conf spark.sql.catalog.paimon=org.apache.paimon.spark.SparkCatalog \ | ||
--conf spark.sql.catalog.paimon.warehouse=cosn://<bucket>/<path> \ | ||
--conf spark.sql.catalog.paimon.fs.cosn.bucket.endpoint_suffix=cos.ap-beijing.myqcloud.com \ | ||
--conf spark.sql.catalog.paimon.fs.cosn.userinfo.secretId=AKIDxxxx \ | ||
--conf spark.sql.catalog.paimon.fs.cosn.userinfo.secretKey=yyy | ||
``` | ||
|
||
{{< /tab >}} | ||
|
||
{{< tab "Hive" >}} | ||
|
||
{{< hint info >}} | ||
If you have already configured cosn access through Hive (Via Hadoop FileSystem), here you can skip the following configuration. | ||
{{< /hint >}} | ||
|
||
NOTE: You need to ensure that Hive metastore can access `cosn` | ||
|
||
Place `paimon-cosn-{{< version >}}.jar` together with `paimon-hive-connector-{{< version >}}.jar` under Hive's auxlib directory, and start like | ||
|
||
```sql | ||
SET paimon.fs.cosn.bucket.endpoint_suffix=cos.ap-beijing.myqcloud.com; | ||
SET paimon.fs.cosn.userinfo.secretId=AKIDxxxx; | ||
SET paimon.fs.cosn.userinfo.secretKey=yyy; | ||
``` | ||
|
||
And read table from hive metastore, table can be created by Flink or Spark, see [Catalog with Hive Metastore]({{< ref "how-to/creating-catalogs" >}}) | ||
```sql | ||
SELECT * FROM test_table; | ||
SELECT COUNT(1) FROM test_table; | ||
``` | ||
|
||
{{< /tab >}} | ||
|
||
{{< /tabs >}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>paimon-filesystems</artifactId> | ||
<groupId>org.apache.paimon</groupId> | ||
<version>0.8-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>paimon-cosn-impl</artifactId> | ||
<name>Paimon : FileSystems : COSN : Impl</name> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<fs.cos.sdk.version>3.13.2</fs.cos.sdk.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.paimon</groupId> | ||
<artifactId>paimon-hadoop-shaded</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.paimon</groupId> | ||
<artifactId>paimon-common</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.qcloud.cos</groupId> | ||
<artifactId>hadoop-cos</artifactId> | ||
<version>${fs.cos.qcloud.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<!-- provided by paimon-hadoop-shaded --> | ||
<groupId>org.apache.hadoop</groupId> | ||
<artifactId>hadoop-common</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>ch.qos.reload4j</groupId> | ||
<artifactId>reload4j</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-reload4j</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<!-- Hadoop requires jaxb-api for javax.xml.bind.JAXBException --> | ||
<groupId>javax.xml.bind</groupId> | ||
<artifactId>jaxb-api</artifactId> | ||
<version>${jaxb.api.version}</version> | ||
<!-- packaged as an optional dependency that is only accessible on Java 11+ --> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<!-- Relocate all cos related classes --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>shade-paimon</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<artifactSet> | ||
<includes> | ||
<include>*:*</include> | ||
</includes> | ||
</artifactSet> | ||
<filters> | ||
<filter> | ||
<artifact>*</artifact> | ||
<excludes> | ||
<exclude>.gitkeep</exclude> | ||
<exclude>mime.types</exclude> | ||
<exclude>mozilla/**</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
158 changes: 158 additions & 0 deletions
158
paimon-filesystems/paimon-cosn-impl/src/main/java/org/apache/paimon/cosn/COSNFileIO.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,158 @@ | ||
/* | ||
* 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.paimon.cosn; | ||
|
||
import org.apache.paimon.catalog.CatalogContext; | ||
import org.apache.paimon.fs.FileIO; | ||
import org.apache.paimon.options.Options; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.CosFileSystem; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** OSS {@link FileIO}. */ | ||
public class COSNFileIO extends HadoopCompliantFileIO { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(COSNFileIO.class); | ||
|
||
/** | ||
* In order to simplify, we make paimon oss configuration keys same with hadoop cos module. So, | ||
* we add all configuration key with prefix `fs.cosn` in paimon conf to hadoop conf. | ||
*/ | ||
private static final String[] CONFIG_PREFIXES = {"fs.cosn."}; | ||
|
||
private static final String COSN_SECRET_ID = "fs.cosn.userinfo.secretId"; | ||
private static final String COSN_SECRET_KEY = "fs.cosn.userinfo.secretKey"; | ||
|
||
private static final Map<String, String> CASE_SENSITIVE_KEYS = | ||
new HashMap<String, String>() { | ||
{ | ||
put(COSN_SECRET_ID.toLowerCase(), COSN_SECRET_ID); | ||
put(COSN_SECRET_KEY.toLowerCase(), COSN_SECRET_KEY); | ||
} | ||
}; | ||
|
||
/** | ||
* Cache CosFileSystem, at present, there is no good mechanism to ensure that the file system | ||
* will be shut down, so here the fs cache is used to avoid resource leakage. | ||
*/ | ||
private static final Map<CacheKey, CosFileSystem> CACHE = new ConcurrentHashMap<>(); | ||
|
||
private Options hadoopOptions; | ||
|
||
@Override | ||
public boolean isObjectStore() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void configure(CatalogContext context) { | ||
hadoopOptions = new Options(); | ||
// read all configuration with prefix 'CONFIG_PREFIXES' | ||
for (String key : context.options().keySet()) { | ||
for (String prefix : CONFIG_PREFIXES) { | ||
if (key.startsWith(prefix)) { | ||
String value = context.options().get(key); | ||
if (CASE_SENSITIVE_KEYS.containsKey(key.toLowerCase())) { | ||
key = CASE_SENSITIVE_KEYS.get(key.toLowerCase()); | ||
} | ||
hadoopOptions.set(key, value); | ||
LOG.debug( | ||
"Adding config entry for {} as {} to Hadoop config", | ||
key, | ||
hadoopOptions.get(key)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected FileSystem createFileSystem(org.apache.hadoop.fs.Path path) { | ||
final String scheme = path.toUri().getScheme(); | ||
final String authority = path.toUri().getAuthority(); | ||
return CACHE.computeIfAbsent( | ||
new CacheKey(hadoopOptions, scheme, authority), | ||
key -> { | ||
Configuration hadoopConf = new Configuration(); | ||
key.options.toMap().forEach(hadoopConf::set); | ||
URI fsUri = path.toUri(); | ||
if (scheme == null && authority == null) { | ||
fsUri = FileSystem.getDefaultUri(hadoopConf); | ||
} else if (scheme != null && authority == null) { | ||
URI defaultUri = FileSystem.getDefaultUri(hadoopConf); | ||
if (scheme.equals(defaultUri.getScheme()) | ||
&& defaultUri.getAuthority() != null) { | ||
fsUri = defaultUri; | ||
} | ||
} | ||
|
||
CosFileSystem fs = new CosFileSystem(); | ||
try { | ||
fs.initialize(fsUri, hadoopConf); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
return fs; | ||
}); | ||
} | ||
|
||
private static class CacheKey { | ||
|
||
private final Options options; | ||
private final String scheme; | ||
private final String authority; | ||
|
||
private CacheKey(Options options, String scheme, String authority) { | ||
this.options = options; | ||
this.scheme = scheme; | ||
this.authority = authority; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
CacheKey cacheKey = (CacheKey) o; | ||
return Objects.equals(options, cacheKey.options) | ||
&& Objects.equals(scheme, cacheKey.scheme) | ||
&& Objects.equals(authority, cacheKey.authority); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(options, scheme, authority); | ||
} | ||
} | ||
} |
Oops, something went wrong.