alamb commented on code in PR #6337: URL: https://github.com/apache/arrow-datafusion/pull/6337#discussion_r1194292621
########## 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: Yes I agree it is more than potentially 😆 I don't think we need to fix it for this PR, however. Maybe @tustvold has some ideas, and if not then I think we can just file a follow on ticket to track fetching only the parts that are needed ########## datafusion/core/tests/sql/arrow_files.rs: ########## @@ -0,0 +1,70 @@ +// 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 datafusion::execution::options::ArrowReadOptions; + +use super::*; + +async fn register_arrow(ctx: &mut SessionContext) { Review Comment: I actually tried creating an arrow table via SQL and unfortunately it did not work: ``` datafusion-cli ❯ create external table example stored as arrow location '../datafusion/core/tests/data/example.arrow'; Execution error: Unable to find factory for ARROW ``` To support that I think all we need is to add another entry to this list: https://github.com/apache/arrow-datafusion/blob/b578c5819fc05801f2972dd427fbc13cf4773ea8/datafusion/core/src/execution/context.rs#L1358-L1362 ########## datafusion/core/tests/sql/arrow_files.rs: ########## @@ -0,0 +1,70 @@ +// 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 datafusion::execution::options::ArrowReadOptions; + +use super::*; + +async fn register_arrow(ctx: &mut SessionContext) { Review Comment: Looks good -- I think we should also write a sqllogictest version of this (e.g. https://github.com/apache/arrow-datafusion/blob/b578c5819fc05801f2972dd427fbc13cf4773ea8/datafusion/core/tests/sqllogictests/test_files/ddl.slt#LL259C1-L260C1) So that we have coverage of creating an arrow backed table via SQL But I also think that could be added as a follow on PR ########## 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 Review Comment: Can you link to the format docs to make it clear this writer writes the IPC format https://arrow.apache.org/docs/format/Columnar.html#ipc-file-format ? -- 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]
