-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy paths3.rs
76 lines (67 loc) · 2.61 KB
/
s3.rs
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
// 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.
//! AWS S3 Integration: [AwsS3Extension]
use crate::config::ExecutionConfig;
use crate::extensions::{DftSessionStateBuilder, Extension};
use crate::object_stores::io_object_store::IoObjectStore;
use log::info;
use std::sync::Arc;
use url::Url;
#[derive(Debug, Default)]
pub struct AwsS3Extension {}
impl AwsS3Extension {
pub fn new() -> Self {
Self {}
}
}
impl Extension for AwsS3Extension {
fn register(
&self,
config: &ExecutionConfig,
mut builder: DftSessionStateBuilder,
) -> datafusion_common::Result<DftSessionStateBuilder> {
let Some(object_store_config) = &config.object_store else {
return Ok(builder);
};
let Some(s3_configs) = &object_store_config.s3 else {
return Ok(builder);
};
info!("S3 configs exists");
for s3_config in s3_configs {
match s3_config.to_object_store() {
Ok(object_store) => {
info!("Created object store: {}", object_store);
if let Some(object_store_url) = s3_config.object_store_url() {
info!("Endpoint exists");
if let Ok(parsed_endpoint) = Url::parse(object_store_url) {
info!("Parsed endpoint");
let io_store = IoObjectStore::new(Arc::new(object_store));
builder
.runtime_env()
.register_object_store(&parsed_endpoint, Arc::new(io_store));
info!("Registered s3 object store");
}
}
}
Err(e) => {
log::error!("Error creating object store: {:?}", e);
}
}
}
Ok(builder)
}
}