1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
// 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.
#![warn(missing_docs)]
//! [DataFusion-ObjectStore-S3](https://github.com/datafusion-contrib/datafusion-objectstore-s3)
//! provides a `TableProvider` interface for using `Datafusion` to query data in S3. This includes AWS S3
//! and services such as MinIO that implement the S3 API.
//!
//! ## Examples
//! Examples for querying AWS and other implementors, such as MinIO, are shown below.
//!
//! Load credentials from default AWS credential provider (such as environment or ~/.aws/credentials)
//!
//! ```rust
//! # use std::sync::Arc;
//! # use datafusion::error::Result;
//! # use datafusion_objectstore_s3::object_store::s3::S3FileSystem;
//! # #[tokio::main]
//! # async fn main() -> Result<()> {
//! let s3_file_system = Arc::new(S3FileSystem::default().await);
//! # Ok(())
//! # }
//! ```
//!
//! `S3FileSystem::default()` is a convenience wrapper for `S3FileSystem::new(None, None, None, None, None, None)`.
//!
//! Connect to implementor of S3 API (MinIO, in this case) using access key and secret.
//!
//! ```rust
//! use datafusion_objectstore_s3::object_store::s3::S3FileSystem;
//!
//! use aws_types::credentials::SharedCredentialsProvider;
//! use aws_types::credentials::Credentials;
//! use aws_sdk_s3::Endpoint;
//! use http::Uri;
//!
//! # #[tokio::main]
//! # async fn main() {
//! // Example credentials provided by MinIO
//! const MINIO_ACCESS_KEY_ID: &str = "AKIAIOSFODNN7EXAMPLE";
//! const MINIO_SECRET_ACCESS_KEY: &str = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
//! const PROVIDER_NAME: &str = "Static";
//! const MINIO_ENDPOINT: &str = "http://localhost:9000";
//!
//! let s3_file_system = S3FileSystem::new(
//! Some(SharedCredentialsProvider::new(Credentials::new(
//! MINIO_ACCESS_KEY_ID,
//! MINIO_SECRET_ACCESS_KEY,
//! None,
//! None,
//! PROVIDER_NAME,
//! ))), // SharedCredentialsProvider
//! None, //Region
//! Some(Endpoint::immutable(Uri::from_static(MINIO_ENDPOINT))), //Endpoint
//! None, // RetryConfig
//! None, // AsyncSleep
//! None, // TimeoutConfig
//! )
//! .await;
//! # }
//! ```
//!
//! Using DataFusion's `ListingOtions` and `ListingTable` we register a table into a DataFusion `ExecutionContext` so that it can be queried.
//!
//! ```rust
//! use std::sync::Arc;
//!
//! use datafusion::datasource::listing::*;
//! use datafusion::datasource::TableProvider;
//! use datafusion::prelude::SessionContext;
//! use datafusion::datasource::file_format::parquet::ParquetFormat;
//! use datafusion::error::Result;
//!
//! use datafusion_objectstore_s3::object_store::s3::S3FileSystem;
//!
//! use aws_types::credentials::SharedCredentialsProvider;
//! use aws_types::credentials::Credentials;
//! use aws_sdk_s3::Endpoint;
//! use http::Uri;
//!
//! # const MINIO_ACCESS_KEY_ID: &str = "AKIAIOSFODNN7EXAMPLE";
//! # const MINIO_SECRET_ACCESS_KEY: &str = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
//! # const PROVIDER_NAME: &str = "Static";
//! # const MINIO_ENDPOINT: &str = "http://localhost:9000";
//!
//! # #[tokio::main]
//! # async fn main() -> Result<()> {
//! let filename = "data/alltypes_plain.snappy.parquet";
//!
//! # let s3_file_system = Arc::new(S3FileSystem::new(
//! # Some(SharedCredentialsProvider::new(Credentials::new(
//! # MINIO_ACCESS_KEY_ID,
//! # MINIO_SECRET_ACCESS_KEY,
//! # None,
//! # None,
//! # PROVIDER_NAME,
//! # ))),
//! # None,
//! # Some(Endpoint::immutable(Uri::from_static(MINIO_ENDPOINT))),
//! # None,
//! # None,
//! # None,
//! # )
//! # .await);
//!
//! let config = ListingTableConfig::new(s3_file_system, filename).infer().await?;
//!
//! let table = ListingTable::try_new(config)?;
//!
//! let mut ctx = SessionContext::new();
//!
//! ctx.register_table("tbl", Arc::new(table))?;
//!
//! let df = ctx.sql("SELECT * FROM tbl").await?;
//! df.show();
//! # Ok(())
//! # }
//! ```
//!
//! We can also register the `S3FileSystem` directly as an `ObjectStore` on an `ExecutionContext`. This provides an idiomatic way of creating `TableProviders` that can be queried.
//!
//! ```rust
//! use std::sync::Arc;
//!
//! use datafusion::datasource::listing::*;
//! use datafusion::error::Result;
//!
//! use datafusion_objectstore_s3::object_store::s3::S3FileSystem;
//!
//! use aws_sdk_s3::Endpoint;
//! use aws_types::credentials::Credentials;
//! use aws_types::credentials::SharedCredentialsProvider;
//! use datafusion::prelude::SessionContext;
//! use http::Uri;
//!
//! const MINIO_ACCESS_KEY_ID: &str = "AKIAIOSFODNN7EXAMPLE";
//! const MINIO_SECRET_ACCESS_KEY: &str = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
//! const PROVIDER_NAME: &str = "Static";
//! const MINIO_ENDPOINT: &str = "http://localhost:9000";
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let s3_file_system = Arc::new(
//! S3FileSystem::new(
//! Some(SharedCredentialsProvider::new(Credentials::new(
//! MINIO_ACCESS_KEY_ID,
//! MINIO_SECRET_ACCESS_KEY,
//! None,
//! None,
//! PROVIDER_NAME,
//! ))),
//! None,
//! Some(Endpoint::immutable(Uri::from_static(MINIO_ENDPOINT))),
//! None,
//! None,
//! None,
//! )
//! .await,
//! );
//!
//! let ctx = SessionContext::new();
//!
//! let uri = "s3://data/alltypes_plain.snappy.parquet";
//! let (_, filename) = uri.split_once("://").unwrap();
//!
//! let config = ListingTableConfig::new(s3_file_system, filename)
//! .infer()
//! .await?;
//!
//! let table = ListingTable::try_new(config)?;
//!
//! ctx.register_table("tbl", Arc::new(table))?;
//!
//! let df = ctx.sql("SELECT * FROM tbl").await?;
//! df.show().await?;
//! Ok(())
//! }
//! ```
pub mod error;
pub mod object_store;