jonmmease commented on code in PR #6337: URL: https://github.com/apache/arrow-datafusion/pull/6337#discussion_r1194405964
########## datafusion/core/src/datasource/file_format/arrow.rs: ########## @@ -0,0 +1,94 @@ +// 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. + +//! Apache Arrow format abstractions + +use crate::datasource::file_format::FileFormat; +use crate::error::Result; +use crate::execution::context::SessionState; +use crate::physical_plan::file_format::{ArrowExec, FileScanConfig}; +use crate::physical_plan::ExecutionPlan; +use arrow::ipc::reader::FileReader; +use arrow_schema::{Schema, SchemaRef}; +use async_trait::async_trait; +use datafusion_common::Statistics; +use datafusion_physical_expr::PhysicalExpr; +use object_store::{GetResult, ObjectMeta, ObjectStore}; +use std::any::Any; +use std::io::{Read, Seek}; +use std::sync::Arc; + +/// The default file extension of arrow files +pub const DEFAULT_ARROW_EXTENSION: &str = ".arrow"; +/// Arrow `FileFormat` implementation. +#[derive(Default, Debug)] +pub struct ArrowFormat; + +#[async_trait] +impl FileFormat for ArrowFormat { + fn as_any(&self) -> &dyn Any { + self + } + + async fn infer_schema( + &self, + _state: &SessionState, + store: &Arc<dyn ObjectStore>, + objects: &[ObjectMeta], + ) -> Result<SchemaRef> { + let mut schemas = vec![]; + for object in objects { + let schema = match store.get(&object.location).await? { + GetResult::File(mut file, _) => read_arrow_schema_from_reader(&mut file)?, + r @ GetResult::Stream(_) => { + // TODO: Fetching entire file to get schema is potentially wasteful Review Comment: Haha, yeah, I carried that comment over from the Avro reader as the situation is the same here. But maybe there's some way to look at the start of the stream and parse out the schema? -- 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]
