datafusion_common/
parquet_config.rs1use std::fmt::{self, Display};
19use std::str::FromStr;
20
21use crate::config::{ConfigField, Visit};
22use crate::error::{DataFusionError, Result};
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
30pub enum DFParquetWriterVersion {
31 #[default]
33 V1_0,
34 V2_0,
36}
37
38impl FromStr for DFParquetWriterVersion {
40 type Err = DataFusionError;
41
42 fn from_str(s: &str) -> Result<Self, Self::Err> {
43 match s.to_lowercase().as_str() {
44 "1.0" => Ok(DFParquetWriterVersion::V1_0),
45 "2.0" => Ok(DFParquetWriterVersion::V2_0),
46 other => Err(DataFusionError::Configuration(format!(
47 "Invalid parquet writer version: {other}. Expected one of: 1.0, 2.0"
48 ))),
49 }
50 }
51}
52
53impl Display for DFParquetWriterVersion {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 let s = match self {
56 DFParquetWriterVersion::V1_0 => "1.0",
57 DFParquetWriterVersion::V2_0 => "2.0",
58 };
59 write!(f, "{s}")
60 }
61}
62
63impl ConfigField for DFParquetWriterVersion {
64 fn visit<V: Visit>(&self, v: &mut V, key: &str, description: &'static str) {
65 v.some(key, self, description)
66 }
67
68 fn set(&mut self, _: &str, value: &str) -> Result<()> {
69 *self = DFParquetWriterVersion::from_str(value)?;
70 Ok(())
71 }
72}
73
74#[cfg(feature = "parquet")]
79impl From<DFParquetWriterVersion> for parquet::file::properties::WriterVersion {
80 fn from(value: DFParquetWriterVersion) -> Self {
81 match value {
82 DFParquetWriterVersion::V1_0 => {
83 parquet::file::properties::WriterVersion::PARQUET_1_0
84 }
85 DFParquetWriterVersion::V2_0 => {
86 parquet::file::properties::WriterVersion::PARQUET_2_0
87 }
88 }
89 }
90}
91
92#[cfg(feature = "parquet")]
97impl From<parquet::file::properties::WriterVersion> for DFParquetWriterVersion {
98 fn from(version: parquet::file::properties::WriterVersion) -> Self {
99 match version {
100 parquet::file::properties::WriterVersion::PARQUET_1_0 => {
101 DFParquetWriterVersion::V1_0
102 }
103 parquet::file::properties::WriterVersion::PARQUET_2_0 => {
104 DFParquetWriterVersion::V2_0
105 }
106 }
107 }
108}