You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by xu...@apache.org on 2022/04/25 04:25:52 UTC

[arrow-datafusion] branch master updated: deprecate `index_of` and make `index_of_column_by_name` public (#2320)

This is an automated email from the ASF dual-hosted git repository.

xudong963 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new c40784d5d deprecate `index_of` and make `index_of_column_by_name` public (#2320)
c40784d5d is described below

commit c40784d5ddef44e7fddde7314ac61830eaf0b86b
Author: Jeremy Dyer <jd...@gmail.com>
AuthorDate: Mon Apr 25 00:25:46 2022 -0400

    deprecate `index_of` and make `index_of_column_by_name` public (#2320)
    
    * deprecate  and make  public
    
    * Remove hidden tailing character causing linter issues
    
    * Allow clippy::pendantic for `helpful_error_messages\' only linter cfg
    
    * #[allow(deprecated)] for the single test function that is testing an exception thrown from a deprecated index_of
---
 datafusion/common/src/dfschema.rs | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/datafusion/common/src/dfschema.rs b/datafusion/common/src/dfschema.rs
index 311f196b5..168ab8442 100644
--- a/datafusion/common/src/dfschema.rs
+++ b/datafusion/common/src/dfschema.rs
@@ -152,13 +152,30 @@ impl DFSchema {
         &self.fields[i]
     }
 
+    #[deprecated(since = "8.0.0", note = "please use `index_of_column_by_name` instead")]
     /// Find the index of the column with the given unqualified name
     pub fn index_of(&self, name: &str) -> Result<usize> {
         for i in 0..self.fields.len() {
             if self.fields[i].name() == name {
                 return Ok(i);
+            } else {
+                // Now that `index_of` is deprecated an error is thrown if
+                // a fully qualified field name is provided.
+                match &self.fields[i].qualifier {
+                    Some(qualifier) => {
+                        if (qualifier.to_owned() + "." + self.fields[i].name()) == name {
+                            return Err(DataFusionError::Plan(format!(
+                                "Fully qualified field name '{}' was supplied to `index_of` \
+                                which is deprecated. Please use `index_of_column_by_name` instead",
+                                name
+                            )));
+                        }
+                    }
+                    None => (),
+                }
             }
         }
+
         Err(DataFusionError::Plan(format!(
             "No field named '{}'. Valid fields are {}.",
             name,
@@ -166,7 +183,7 @@ impl DFSchema {
         )))
     }
 
-    fn index_of_column_by_name(
+    pub fn index_of_column_by_name(
         &self,
         qualifier: Option<&str>,
         name: &str,
@@ -716,10 +733,13 @@ mod tests {
         Ok(())
     }
 
+    #[allow(deprecated)]
     #[test]
     fn helpful_error_messages() -> Result<()> {
         let schema = DFSchema::try_from_qualified_schema("t1", &test_schema_1())?;
         let expected_help = "Valid fields are \'t1.c0\', \'t1.c1\'.";
+        // Pertinent message parts
+        let expected_err_msg = "Fully qualified field name \'t1.c0\'";
         assert!(schema
             .field_with_qualified_name("x", "y")
             .unwrap_err()
@@ -735,6 +755,11 @@ mod tests {
             .unwrap_err()
             .to_string()
             .contains(expected_help));
+        assert!(schema
+            .index_of("t1.c0")
+            .unwrap_err()
+            .to_string()
+            .contains(expected_err_msg));
         Ok(())
     }