houqp commented on a change in pull request #811: URL: https://github.com/apache/arrow-datafusion/pull/811#discussion_r683230259
########## File path: datafusion/src/datasource/protocol_registry.rs ########## @@ -0,0 +1,83 @@ +// 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. + +use crate::datasource::local::LocalFSHandler; +use crate::error::Result; +use parquet::file::reader::ChunkReader; +use std::any::Any; +use std::collections::HashMap; +use std::sync::{Arc, RwLock}; + +pub trait ProtocolHandler<R>: Sync + Send { Review comment: I agree with Andrew that `ObjectStore` would have been a better name :) ########## File path: datafusion/src/datasource/local.rs ########## @@ -0,0 +1,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. + +use crate::datasource::protocol_registry::ProtocolHandler; +use crate::error::DataFusionError; +use crate::error::Result; +use parquet::file::reader::ChunkReader; +use std::any::Any; +use std::fs; +use std::fs::{metadata, File}; +use std::sync::Arc; + +pub struct LocalFSHandler; + +impl ProtocolHandler<File> for LocalFSHandler { + fn as_any(&self) -> &dyn Any { + return self; + } + + fn list_all_files(&self, root_path: &str, ext: &str) -> Result<Vec<String>> { + list_all(root_path, ext) + } + + fn get_reader(&self, file_path: &str) -> Result<Arc<dyn ChunkReader<T = File>>> { Review comment: Just my quick thoughts on possible designs to avoid the chunkreader trait here. We could declare a `read_file` method here instead that would take start and length as argument, then return a Vector or Iterator of bytes. Then in `ParquetRootDesc`, we use a local struct to implement `ChunkReader` leveraging the `ObjectStore::read_file` method, which gets passed to `SerializedFileReader`. ########## File path: datafusion/src/execution/context.rs ########## @@ -125,12 +127,26 @@ pub struct ExecutionContext { pub state: Arc<Mutex<ExecutionContextState>>, } +lazy_static! { Review comment: I agree with @alamb on this one, would be better to have discussion about global static in a separate PR. This way, it will be easier for us to approve and merge code change specific to remote data source. ########## File path: datafusion/src/datasource/protocol_registry.rs ########## @@ -0,0 +1,83 @@ +// 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. + +use crate::datasource::local::LocalFSHandler; +use crate::error::Result; +use parquet::file::reader::ChunkReader; +use std::any::Any; +use std::collections::HashMap; +use std::sync::{Arc, RwLock}; + +pub trait ProtocolHandler<R>: Sync + Send { + /// Returns the protocol handler as [`Any`](std::any::Any) + /// so that it can be downcast to a specific implementation. + fn as_any(&self) -> &dyn Any; + + fn list_all_files(&self, root_path: &str, ext: &str) -> Result<Vec<String>>; Review comment: Perhaps the name `root_path` here is a bit misleading here, maybe it should be named `path` or `prefix`? To list sub directory, I am thinking one would pass in `root_path/subdir1/subdir2`. But I think we need to be more specific on whether the return value should contain relative path or absolute path. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
