Skip to content

Commit

Permalink
remove more #cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Oct 26, 2023
1 parent 4881b5d commit 85f9e43
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 27 deletions.
4 changes: 0 additions & 4 deletions datafusion/common/src/file_options/file_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub enum FileType {
/// Apache Avro file
AVRO,
/// Apache Parquet file
#[cfg(feature = "parquet")]
PARQUET,
/// CSV file
CSV,
Expand All @@ -61,7 +60,6 @@ impl GetExt for FileType {
match self {
FileType::ARROW => DEFAULT_ARROW_EXTENSION.to_owned(),
FileType::AVRO => DEFAULT_AVRO_EXTENSION.to_owned(),
#[cfg(feature = "parquet")]
FileType::PARQUET => DEFAULT_PARQUET_EXTENSION.to_owned(),
FileType::CSV => DEFAULT_CSV_EXTENSION.to_owned(),
FileType::JSON => DEFAULT_JSON_EXTENSION.to_owned(),
Expand All @@ -74,7 +72,6 @@ impl Display for FileType {
let out = match self {
FileType::CSV => "csv",
FileType::JSON => "json",
#[cfg(feature = "parquet")]
FileType::PARQUET => "parquet",
FileType::AVRO => "avro",
FileType::ARROW => "arrow",
Expand All @@ -91,7 +88,6 @@ impl FromStr for FileType {
match s.as_str() {
"ARROW" => Ok(FileType::ARROW),
"AVRO" => Ok(FileType::AVRO),
#[cfg(feature = "parquet")]
"PARQUET" => Ok(FileType::PARQUET),
"CSV" => Ok(FileType::CSV),
"JSON" | "NDJSON" => Ok(FileType::JSON),
Expand Down
10 changes: 2 additions & 8 deletions datafusion/common/src/file_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod avro_writer;
pub mod csv_writer;
pub mod file_type;
pub mod json_writer;
#[cfg(feature = "parquet")]
pub mod parquet_writer;
pub(crate) mod parse_utils;

Expand All @@ -38,14 +37,13 @@ use crate::{
DataFusionError, FileType, Result,
};

#[cfg(feature = "parquet")]
use self::parquet_writer::ParquetWriterOptions;

use self::{
arrow_writer::ArrowWriterOptions, avro_writer::AvroWriterOptions,
csv_writer::CsvWriterOptions, json_writer::JsonWriterOptions,
};

use self::parquet_writer::ParquetWriterOptions;

/// Represents a single arbitrary setting in a
/// [StatementOptions] where OptionTuple.0 determines
/// the specific setting to be modified and OptionTuple.1
Expand Down Expand Up @@ -148,7 +146,6 @@ impl StatementOptions {
/// plus any DataFusion specific writing options (e.g. CSV compression)
#[derive(Clone, Debug)]
pub enum FileTypeWriterOptions {
#[cfg(feature = "parquet")]
Parquet(ParquetWriterOptions),
CSV(CsvWriterOptions),
JSON(JsonWriterOptions),
Expand All @@ -168,7 +165,6 @@ impl FileTypeWriterOptions {
let options = (config_defaults, statement_options);

let file_type_write_options = match file_type {
#[cfg(feature = "parquet")]
FileType::PARQUET => {
FileTypeWriterOptions::Parquet(ParquetWriterOptions::try_from(options)?)
}
Expand Down Expand Up @@ -198,7 +194,6 @@ impl FileTypeWriterOptions {
let options = (config_defaults, &empty_statement);

let file_type_write_options = match file_type {
#[cfg(feature = "parquet")]
FileType::PARQUET => {
FileTypeWriterOptions::Parquet(ParquetWriterOptions::try_from(options)?)
}
Expand Down Expand Up @@ -288,7 +283,6 @@ impl Display for FileTypeWriterOptions {
FileTypeWriterOptions::Avro(_) => "AvroWriterOptions",
FileTypeWriterOptions::CSV(_) => "CsvWriterOptions",
FileTypeWriterOptions::JSON(_) => "JsonWriterOptions",
#[cfg(feature = "parquet")]
FileTypeWriterOptions::Parquet(_) => "ParquetWriterOptions",
};
write!(f, "{}", name)
Expand Down
28 changes: 28 additions & 0 deletions datafusion/common/src/file_options/parquet_writer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.

#[cfg(feature = "parquet")]
mod parquet;

#[cfg(feature = "parquet")]
pub use parquet::*;

#[cfg(not(feature = "parquet"))]
mod parquet_stub;

#[cfg(not(feature = "parquet"))]
pub use parquet_stub::*;
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use parquet::file::properties::{WriterProperties, WriterPropertiesBuilder};

use crate::{config::ConfigOptions, DataFusionError, Result};

use super::StatementOptions;

use crate::file_options::StatementOptions;
use parquet::{
basic::{BrotliLevel, GzipLevel, ZstdLevel},
file::properties::{EnabledStatistics, WriterVersion},
Expand Down
35 changes: 35 additions & 0 deletions datafusion/common/src/file_options/parquet_writer/parquet_stub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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::config::ConfigOptions;
use crate::file_options::StatementOptions;
use crate::not_impl_err;

/// Stub implementation of `ParquetFormat` that always returns a
/// NotYetImplemented error used when parquet feature is not activated.
#[derive(Clone, Debug)]
pub struct ParquetWriterOptions {}

impl TryFrom<(&ConfigOptions, &StatementOptions)> for ParquetWriterOptions {
type Error = DataFusionError;

fn try_from(_: (&ConfigOptions, &StatementOptions)) -> Result<Self> {
not_impl_err!(
"Parquet format is not enabled, Hint enable the `parquet` feature flag"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ impl FileTypeExt for FileType {
"FileCompressionType can be specified for CSV/JSON FileType.".into(),
)),
},
#[cfg(feature = "parquet")]
FileType::PARQUET => match c.variant {
UNCOMPRESSED => Ok(ext),
_ => Err(DataFusionError::Internal(
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/datasource/file_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub mod csv;
pub mod file_compression_type;
pub mod json;
pub mod options;
#[cfg(feature = "parquet")]
pub mod parquet;

pub mod write;

use std::any::Any;
Expand Down
30 changes: 30 additions & 0 deletions datafusion/core/src/datasource/file_format/parquet/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.

//! FileFormat for parquet
/// If parquet is enabled, use actual implementation
#[cfg(feature = "parquet")]
mod parquet;
#[cfg(feature = "parquet")]
pub use parquet::*;

/// If parquet is not enabled, use dummy implementation
#[cfg(not(feature = "parquet"))]
mod parquet_stub;
#[cfg(not(feature = "parquet"))]
pub use parquet_stub::ParquetFormat;
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@ use parquet::file::metadata::ParquetMetaData;
use parquet::file::properties::WriterProperties;
use parquet::file::statistics::Statistics as ParquetStatistics;

use super::write::demux::start_demuxer_task;
use super::write::{create_writer, AbortableWrite, FileWriterMode};
use super::{FileFormat, FileScanConfig};
use crate::arrow::array::{
BooleanArray, Float32Array, Float64Array, Int32Array, Int64Array,
};
use crate::arrow::datatypes::DataType;
use crate::config::ConfigOptions;
use crate::datasource::file_format::write::demux::start_demuxer_task;
use crate::datasource::file_format::write::{
create_writer, AbortableWrite, FileWriterMode,
};
use crate::datasource::file_format::FileFormat;

use crate::datasource::get_col_stats;
use crate::datasource::physical_plan::{
FileGroupDisplay, FileMeta, FileSinkConfig, ParquetExec, SchemaAdapter,
FileGroupDisplay, FileMeta, FileScanConfig, FileSinkConfig, ParquetExec,
SchemaAdapter,
};

use crate::error::Result;
Expand Down Expand Up @@ -1206,14 +1209,14 @@ pub(crate) mod test_util {

#[cfg(test)]
mod tests {
use super::super::test_util::scan_format;
use crate::physical_plan::collect;
use std::fmt::{Display, Formatter};
use std::sync::atomic::{AtomicUsize, Ordering};

use super::*;

use crate::datasource::file_format::parquet::test_util::store_parquet;
use crate::datasource::file_format::test_util::scan_format;
use crate::physical_plan::metrics::MetricValue;
use crate::prelude::{SessionConfig, SessionContext};
use arrow::array::{Array, ArrayRef, StringArray};
Expand Down
84 changes: 84 additions & 0 deletions datafusion/core/src/datasource/file_format/parquet/parquet_stub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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::file_format::FileFormat;
use crate::datasource::physical_plan::FileScanConfig;
use crate::execution::context::SessionState;
use arrow_schema::SchemaRef;
use async_trait::async_trait;
use datafusion_common::{DataFusionError, FileType, Result, Statistics};
use datafusion_physical_expr::PhysicalExpr;
use datafusion_physical_plan::ExecutionPlan;
use object_store::{ObjectMeta, ObjectStore};
use std::any::Any;
use std::sync::Arc;

/// Stub implementation of `ParquetFormat` that always returns a NotYetImplemented error.
#[derive(Debug, Default)]
pub struct ParquetFormat;

impl ParquetFormat {
/// Create a new instance of the Parquet format
pub fn new() -> Self {
Self
}
}

fn nyi_error() -> DataFusionError {
DataFusionError::NotImplemented(
"Parquet support not enabled. Hint enable the `parquet` crate feature".into(),
)
}

#[async_trait]
impl FileFormat for ParquetFormat {
fn as_any(&self) -> &dyn Any {
self
}

async fn infer_schema(
&self,
_: &SessionState,
_: &Arc<dyn ObjectStore>,
_: &[ObjectMeta],
) -> Result<SchemaRef> {
Err(nyi_error())
}

async fn infer_stats(
&self,
_: &SessionState,
_: &Arc<dyn ObjectStore>,
_: SchemaRef,
_: &ObjectMeta,
) -> Result<Statistics> {
Err(nyi_error())
}

async fn create_physical_plan(
&self,
_: &SessionState,
_: FileScanConfig,
_: Option<&Arc<dyn PhysicalExpr>>,
) -> Result<Arc<dyn ExecutionPlan>> {
Err(nyi_error())
}

fn file_type(&self) -> FileType {
FileType::PARQUET
}
}
5 changes: 5 additions & 0 deletions datafusion/core/src/datasource/listing/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ impl ListingTableConfig {
),
#[cfg(feature = "parquet")]
FileType::PARQUET => Arc::new(ParquetFormat::default()),
#[cfg(not(feature = "parquet"))]
FileType::PARQUET => return Err(DataFusionError::NotImplemented(
"Parquet format is not enabled, Hint enable the `parquet` feature flag"
.to_string(),
)),
};

Ok((file_format, ext))
Expand Down
4 changes: 0 additions & 4 deletions datafusion/core/src/datasource/listing_table_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::sync::Arc;

use super::listing::ListingTableInsertMode;

#[cfg(feature = "parquet")]
use crate::datasource::file_format::parquet::ParquetFormat;
use crate::datasource::file_format::{
arrow::ArrowFormat, avro::AvroFormat, csv::CsvFormat,
Expand Down Expand Up @@ -80,7 +79,6 @@ impl TableProviderFactory for ListingTableFactory {
.with_delimiter(cmd.delimiter as u8)
.with_file_compression_type(file_compression_type),
),
#[cfg(feature = "parquet")]
FileType::PARQUET => Arc::new(ParquetFormat::default()),
FileType::AVRO => Arc::new(AvroFormat),
FileType::JSON => Arc::new(
Expand Down Expand Up @@ -159,7 +157,6 @@ impl TableProviderFactory for ListingTableFactory {
Some(mode) => ListingTableInsertMode::from_str(mode.as_str()),
None => match file_type {
FileType::CSV => Ok(ListingTableInsertMode::AppendToFile),
#[cfg(feature = "parquet")]
FileType::PARQUET => Ok(ListingTableInsertMode::AppendNewFiles),
FileType::AVRO => Ok(ListingTableInsertMode::AppendNewFiles),
FileType::JSON => Ok(ListingTableInsertMode::AppendToFile),
Expand Down Expand Up @@ -199,7 +196,6 @@ impl TableProviderFactory for ListingTableFactory {
json_writer_options.compression = cmd.file_compression_type;
FileTypeWriterOptions::JSON(json_writer_options)
}
#[cfg(feature = "parquet")]
FileType::PARQUET => file_type_writer_options,
FileType::ARROW => file_type_writer_options,
FileType::AVRO => file_type_writer_options,
Expand Down
2 changes: 0 additions & 2 deletions datafusion/core/src/physical_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::datasource::file_format::arrow::ArrowFormat;
use crate::datasource::file_format::avro::AvroFormat;
use crate::datasource::file_format::csv::CsvFormat;
use crate::datasource::file_format::json::JsonFormat;
#[cfg(feature = "parquet")]
use crate::datasource::file_format::parquet::ParquetFormat;
use crate::datasource::file_format::write::FileWriterMode;
use crate::datasource::file_format::FileFormat;
Expand Down Expand Up @@ -600,7 +599,6 @@ impl DefaultPhysicalPlanner {

let sink_format: Arc<dyn FileFormat> = match file_format {
FileType::CSV => Arc::new(CsvFormat::default()),
#[cfg(feature = "parquet")]
FileType::PARQUET => Arc::new(ParquetFormat::default()),
FileType::JSON => Arc::new(JsonFormat::default()),
FileType::AVRO => Arc::new(AvroFormat {} ),
Expand Down

0 comments on commit 85f9e43

Please sign in to comment.