Jefffrey commented on code in PR #19515:
URL: https://github.com/apache/datafusion/pull/19515#discussion_r2653268142


##########
datafusion/common/src/parquet_config.rs:
##########
@@ -0,0 +1,108 @@
+// 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 std::fmt::{self, Display};
+use std::str::FromStr;
+
+use crate::config::{ConfigField, Visit};
+use crate::error::{DataFusionError, Result};
+
+/// Parquet writer version options for controlling the Parquet file format 
version
+///
+/// This enum validates parquet writer version values at configuration time,
+/// ensuring only valid versions ("1.0" or "2.0") can be set via `SET` commands
+/// or proto deserialization.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
+pub enum DFWriterVersion {

Review Comment:
   Maybe we should rename it to have parquet in the name, like 
`DFParquetWriterVersion`, for clarity



##########
datafusion/common/src/config.rs:
##########
@@ -3455,4 +3456,55 @@ mod tests {
         let parsed_metadata = table_config.parquet.key_value_metadata;
         assert_eq!(parsed_metadata.get("key_dupe"), Some(&Some("B".into())));
     }
+    #[cfg(feature = "parquet")]
+    #[test]
+    fn test_parquet_writer_version_validation() {
+        use crate::{config::ConfigOptions, parquet_config::DFWriterVersion};
+
+        let mut config = ConfigOptions::default();
+
+        // Valid values should work
+        config
+            .set("datafusion.execution.parquet.writer_version", "1.0")
+            .unwrap();
+        assert_eq!(
+            config.execution.parquet.writer_version,
+            DFWriterVersion::V1_0
+        );
+
+        config
+            .set("datafusion.execution.parquet.writer_version", "2.0")
+            .unwrap();
+        assert_eq!(
+            config.execution.parquet.writer_version,
+            DFWriterVersion::V2_0
+        );
+
+        // Invalid value should error immediately at SET time
+        let result = config.set("datafusion.execution.parquet.writer_version", 
"3.0");
+        assert!(
+            result.is_err(),
+            "Setting invalid writer_version '3.0' should fail at SET time"
+        );
+        let error_msg = result.unwrap_err().to_string();
+        assert!(
+            error_msg.contains("writer version")
+                || error_msg.contains("1.0")
+                || error_msg.contains("2.0"),
+            "Error message should mention valid writer version values. Got: 
{error_msg}"
+        );

Review Comment:
   Can we collapse this into a single assert? It feels weird to have two 
separate asserts; and having the second assert do 3 `contains` chained by `or` 
is not ideal, we should just assert the entire error string



##########
datafusion/proto/src/logical_plan/file_formats.rs:
##########
@@ -477,7 +477,9 @@ mod parquet {
             force_filter_selections: proto.force_filter_selections,
             data_pagesize_limit: proto.data_pagesize_limit as usize,
             write_batch_size: proto.write_batch_size as usize,
-            writer_version: proto.writer_version.clone(),
+            writer_version: proto.writer_version.parse().expect("
+                Invalid parquet writer version in proto, expected '1.0' or 
'2.0'
+            "),

Review Comment:
   We'll probably need to look into this in the future, to change this to a 
`TryFrom` instead of having this panic



##########
datafusion/common/src/config.rs:
##########
@@ -3455,4 +3456,55 @@ mod tests {
         let parsed_metadata = table_config.parquet.key_value_metadata;
         assert_eq!(parsed_metadata.get("key_dupe"), Some(&Some("B".into())));
     }
+    #[cfg(feature = "parquet")]
+    #[test]
+    fn test_parquet_writer_version_validation() {
+        use crate::{config::ConfigOptions, parquet_config::DFWriterVersion};
+
+        let mut config = ConfigOptions::default();
+
+        // Valid values should work
+        config
+            .set("datafusion.execution.parquet.writer_version", "1.0")
+            .unwrap();
+        assert_eq!(
+            config.execution.parquet.writer_version,
+            DFWriterVersion::V1_0
+        );
+
+        config
+            .set("datafusion.execution.parquet.writer_version", "2.0")
+            .unwrap();
+        assert_eq!(
+            config.execution.parquet.writer_version,
+            DFWriterVersion::V2_0
+        );
+
+        // Invalid value should error immediately at SET time
+        let result = config.set("datafusion.execution.parquet.writer_version", 
"3.0");
+        assert!(
+            result.is_err(),
+            "Setting invalid writer_version '3.0' should fail at SET time"
+        );
+        let error_msg = result.unwrap_err().to_string();
+        assert!(
+            error_msg.contains("writer version")
+                || error_msg.contains("1.0")
+                || error_msg.contains("2.0"),
+            "Error message should mention valid writer version values. Got: 
{error_msg}"
+        );
+
+        // Test case-insensitive (should work for valid values)
+        config
+            .set("datafusion.execution.parquet.writer_version", "1.0")
+            .unwrap();

Review Comment:
   We can remove this test, it seems exactly same as above



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to