Skip to content

Commit 7cf2e9d

Browse files
authored
doc: Add documentation for native_datafusion Parquet scanner's S3 support (#1832)
1 parent 42dfb35 commit 7cf2e9d

File tree

2 files changed

+105
-18
lines changed

2 files changed

+105
-18
lines changed

docs/source/user-guide/datasources.md

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,92 @@ JAVA_HOME="/opt/homebrew/opt/openjdk@11" make release PROFILES="-Pspark-3.5" COM
154154
}
155155
```
156156
Or use `spark-shell` with HDFS support as described [above](#using-experimental-native-datafusion-reader)
157+
157158
## S3
158-
In progress
159+
160+
DataFusion Comet has [multiple Parquet scan implementations](./compatibility.md#parquet-scans) that use different approaches to read data from S3.
161+
162+
### `native_comet`
163+
164+
The default `native_comet` Parquet scan implementation reads data from S3 using the [Hadoop-AWS module](https://hadoop.apache.org/docs/stable/hadoop-aws/tools/hadoop-aws/index.html), which is identical to the approach commonly used with vanilla Spark. AWS credential configuration and other Hadoop S3A configurations works the same way as in vanilla Spark.
165+
166+
### `native_datafusion`
167+
168+
The `native_datafusion` Parquet scan implementation completely offloads data loading to native code. It uses the [`object_store` crate](https://crates.io/crates/object_store) to read data from S3 and supports configuring S3 access using standard [Hadoop S3A configurations](https://hadoop.apache.org/docs/stable/hadoop-aws/tools/hadoop-aws/index.html#General_S3A_Client_configuration) by translating them to the `object_store` crate's format.
169+
170+
This implementation maintains compatibility with existing Hadoop S3A configurations, so existing code will continue to work as long as the configurations are supported and can be translated without loss of functionality.
171+
172+
#### Supported Credential Providers
173+
174+
AWS credential providers can be configured using the `fs.s3a.aws.credentials.provider` configuration. The following table shows the supported credential providers and their configuration options:
175+
176+
| Credential provider | Description | Supported Options |
177+
|---------------------|-------------|-------------------|
178+
| `org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider` | Access S3 using access key and secret key | `fs.s3a.access.key`, `fs.s3a.secret.key` |
179+
| `org.apache.hadoop.fs.s3a.TemporaryAWSCredentialsProvider` | Access S3 using temporary credentials | `fs.s3a.access.key`, `fs.s3a.secret.key`, `fs.s3a.session.token` |
180+
| `org.apache.hadoop.fs.s3a.auth.AssumedRoleCredentialProvider` | Access S3 using AWS STS assume role | `fs.s3a.assumed.role.arn`, `fs.s3a.assumed.role.session.name` (optional), `fs.s3a.assumed.role.credentials.provider` (optional) |
181+
| `org.apache.hadoop.fs.s3a.auth.IAMInstanceCredentialsProvider` | Access S3 using EC2 instance profile or ECS task credentials (tries ECS first, then IMDS) | None (auto-detected) |
182+
| `org.apache.hadoop.fs.s3a.AnonymousAWSCredentialsProvider`<br/>`com.amazonaws.auth.AnonymousAWSCredentials`<br/>`software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider` | Access S3 without authentication (public buckets only) | None |
183+
| `com.amazonaws.auth.EnvironmentVariableCredentialsProvider`<br/>`software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider` | Load credentials from environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`) | None |
184+
| `com.amazonaws.auth.InstanceProfileCredentialsProvider`<br/>`software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider` | Access S3 using EC2 instance metadata service (IMDS) | None |
185+
| `com.amazonaws.auth.ContainerCredentialsProvider`<br/>`software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider`<br/>`com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper` | Access S3 using ECS task credentials | None |
186+
| `com.amazonaws.auth.WebIdentityTokenCredentialsProvider`<br/>`software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider` | Authenticate using web identity token file | None |
187+
188+
Multiple credential providers can be specified in a comma-separated list using the `fs.s3a.aws.credentials.provider` configuration, just as Hadoop AWS supports. If `fs.s3a.aws.credentials.provider` is not configured, Hadoop S3A's default credential provider chain will be used. All configuration options also support bucket-specific overrides using the pattern `fs.s3a.bucket.{bucket-name}.{option}`.
189+
190+
#### Additional S3 Configuration Options
191+
192+
Beyond credential providers, the `native_datafusion` implementation supports additional S3 configuration options:
193+
194+
| Option | Description |
195+
|--------|-------------|
196+
| `fs.s3a.endpoint` | The endpoint of the S3 service |
197+
| `fs.s3a.endpoint.region` | The AWS region for the S3 service. If not specified, the region will be auto-detected. |
198+
| `fs.s3a.path.style.access` | Whether to use path style access for the S3 service (true/false, defaults to virtual hosted style) |
199+
| `fs.s3a.requester.pays.enabled` | Whether to enable requester pays for S3 requests (true/false) |
200+
201+
All configuration options support bucket-specific overrides using the pattern `fs.s3a.bucket.{bucket-name}.{option}`.
202+
203+
#### Examples
204+
205+
The following examples demonstrate how to configure S3 access with the `native_datafusion` Parquet scan implementation using different authentication methods.
206+
207+
**Example 1: Simple Credentials**
208+
209+
This example shows how to access a private S3 bucket using an access key and secret key. The `fs.s3a.aws.credentials.provider` configuration can be omitted since `org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider` is included in Hadoop S3A's default credential provider chain.
210+
211+
```shell
212+
$SPARK_HOME/bin/spark-shell \
213+
...
214+
--conf spark.comet.scan.impl=native_datafusion \
215+
--conf spark.hadoop.fs.s3a.access.key=my-access-key \
216+
--conf spark.hadoop.fs.s3a.secret.key=my-secret-key
217+
...
218+
```
219+
220+
**Example 2: Assume Role with Web Identity Token**
221+
222+
This example demonstrates using an assumed role credential to access a private S3 bucket, where the base credential for assuming the role is provided by a web identity token credentials provider.
223+
224+
```shell
225+
$SPARK_HOME/bin/spark-shell \
226+
...
227+
--conf spark.comet.scan.impl=native_datafusion \
228+
--conf spark.hadoop.fs.s3a.aws.credentials.provider=org.apache.hadoop.fs.s3a.auth.AssumedRoleCredentialProvider \
229+
--conf spark.hadoop.fs.s3a.assumed.role.arn=arn:aws:iam::123456789012:role/my-role \
230+
--conf spark.hadoop.fs.s3a.assumed.role.session.name=my-session \
231+
--conf spark.hadoop.fs.s3a.assumed.role.credentials.provider=com.amazonaws.auth.WebIdentityTokenCredentialsProvider
232+
...
233+
```
234+
235+
#### Limitations
236+
237+
The S3 support of `native_datafusion` has the following limitations:
238+
239+
1. **Partial Hadoop S3A configuration support**: Not all Hadoop S3A configurations are currently supported. Only the configurations listed in the tables above are translated and applied to the underlying `object_store` crate.
240+
241+
2. **Custom credential providers**: Custom implementations of AWS credential providers are not supported. The implementation only supports the standard credential providers listed in the table above. We are planning to add support for custom credential providers through a JNI-based adapter that will allow calling Java credential providers from native code. See [issue #1829](https://github.com/apache/datafusion-comet/issues/1829) for more details.
242+
243+
### `native_iceberg_compat`
244+
245+
The `native_iceberg_compat` Parquet scan implementation does not support reading data from S3 yet, but we are working on it.

spark/src/test/scala/org/apache/comet/parquet/ParquetReadFromS3Suite.scala

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,23 @@ class ParquetReadFromS3Suite extends CometTestBase with AdaptiveSparkPlanHelper
104104
df.write.format("parquet").mode(SaveMode.Overwrite).save(filePath)
105105
}
106106

107-
// native_iceberg_compat mode does not have comprehensive S3 support, so we don't run tests
108-
// under this mode.
109-
if (sys.env.getOrElse("COMET_PARQUET_SCAN_IMPL", "") != SCAN_NATIVE_ICEBERG_COMPAT) {
110-
test("read parquet file from MinIO") {
111-
val testFilePath = s"s3a://$testBucketName/data/test-file.parquet"
112-
writeTestParquetFile(testFilePath)
113-
114-
val df = spark.read.format("parquet").load(testFilePath).agg(sum(col("id")))
115-
val scans = collect(df.queryExecution.executedPlan) {
116-
case p: CometScanExec =>
117-
p
118-
case p: CometNativeScanExec =>
119-
p
120-
}
121-
assert(scans.size == 1)
122-
123-
assert(df.first().getLong(0) == 499500)
107+
test("read parquet file from MinIO") {
108+
// native_iceberg_compat mode does not have comprehensive S3 support, so we don't run tests
109+
// under this mode.
110+
assume(sys.env.getOrElse("COMET_PARQUET_SCAN_IMPL", "") != SCAN_NATIVE_ICEBERG_COMPAT)
111+
112+
val testFilePath = s"s3a://$testBucketName/data/test-file.parquet"
113+
writeTestParquetFile(testFilePath)
114+
115+
val df = spark.read.format("parquet").load(testFilePath).agg(sum(col("id")))
116+
val scans = collect(df.queryExecution.executedPlan) {
117+
case p: CometScanExec =>
118+
p
119+
case p: CometNativeScanExec =>
120+
p
124121
}
122+
assert(scans.size == 1)
123+
124+
assert(df.first().getLong(0) == 499500)
125125
}
126126
}

0 commit comments

Comments
 (0)