Apache DataFusion SQL Query Engine
Remove unnecessary result (#9990)
张林伟fc29c3e67d43
diff --git a/datafusion/common/src/dfschema.rs b/datafusion/common/src/dfschema.rsindex 9f167fd1f6..83e53b3cc6 100644--- a/datafusion/common/src/dfschema.rs+++ b/datafusion/common/src/dfschema.rs@@ -319,7 +319,7 @@ impl DFSchema {&self,qualifier: Option<&TableReference>,name: &str,- ) -> Result<Option<usize>> {+ ) -> Option<usize> {let mut matches = self.iter().enumerate()@@ -345,19 +345,19 @@ impl DFSchema {(None, Some(_)) | (None, None) => f.name() == name,}).map(|(idx, _)| idx);- Ok(matches.next())+ matches.next()}/// Find the index of the column with the given qualifier and namepub fn index_of_column(&self, col: &Column) -> Result<usize> {- self.index_of_column_by_name(col.relation.as_ref(), &col.name)?+ self.index_of_column_by_name(col.relation.as_ref(), &col.name).ok_or_else(|| field_not_found(col.relation.clone(), &col.name, self))}/// Check if the column is in the current schema- pub fn is_column_from_schema(&self, col: &Column) -> Result<bool> {+ pub fn is_column_from_schema(&self, col: &Column) -> bool {self.index_of_column_by_name(col.relation.as_ref(), &col.name)- .map(|idx| idx.is_some())+ .is_some()}/// Find the field with the given name@@ -381,7 +381,7 @@ impl DFSchema {) -> Result<(Option<&TableReference>, &Field)> {if let Some(qualifier) = qualifier {let idx = self- .index_of_column_by_name(Some(qualifier), name)?+ .index_of_column_by_name(Some(qualifier), name).ok_or_else(|| field_not_found(Some(qualifier.clone()), name, self))?;Ok((self.field_qualifiers[idx].as_ref(), self.field(idx)))} else {@@ -519,7 +519,7 @@ impl DFSchema {name: &str,) -> Result<&Field> {let idx = self- .index_of_column_by_name(Some(qualifier), name)?+ .index_of_column_by_name(Some(qualifier), name).ok_or_else(|| field_not_found(Some(qualifier.clone()), name, self))?;Ok(self.field(idx))@@ -1190,11 +1190,8 @@ mod tests {.to_string(),expected_help);- assert!(schema.index_of_column_by_name(None, "y").unwrap().is_none());- assert!(schema- .index_of_column_by_name(None, "t1.c0")- .unwrap()- .is_none());+ assert!(schema.index_of_column_by_name(None, "y").is_none());+ assert!(schema.index_of_column_by_name(None, "t1.c0").is_none());Ok(())}@@ -1284,28 +1281,28 @@ mod tests {{let col = Column::from_qualified_name("t1.c0");let schema = DFSchema::try_from_qualified_schema("t1", &test_schema_1())?;- assert!(schema.is_column_from_schema(&col)?);+ assert!(schema.is_column_from_schema(&col));}// qualified not exists{let col = Column::from_qualified_name("t1.c2");let schema = DFSchema::try_from_qualified_schema("t1", &test_schema_1())?;- assert!(!schema.is_column_from_schema(&col)?);+ assert!(!schema.is_column_from_schema(&col));}// unqualified exists{let col = Column::from_name("c0");let schema = DFSchema::try_from_qualified_schema("t1", &test_schema_1())?;- assert!(schema.is_column_from_schema(&col)?);+ assert!(schema.is_column_from_schema(&col));}// unqualified not exists{let col = Column::from_name("c2");let schema = DFSchema::try_from_qualified_schema("t1", &test_schema_1())?;- assert!(!schema.is_column_from_schema(&col)?);+ assert!(!schema.is_column_from_schema(&col));}Ok(())diff --git a/datafusion/expr/src/utils.rs b/datafusion/expr/src/utils.rsindex 0d99d0b502..8c6b98f179 100644--- a/datafusion/expr/src/utils.rs+++ b/datafusion/expr/src/utils.rs@@ -933,7 +933,7 @@ pub fn check_all_columns_from_schema(schema: DFSchemaRef,) -> Result<bool> {for col in columns.iter() {- let exist = schema.is_column_from_schema(col)?;+ let exist = schema.is_column_from_schema(col);if !exist {return Ok(false);}diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rsindex b8c9172621..6b89f89aac 100644--- a/datafusion/sql/src/statement.rs+++ b/datafusion/sql/src/statement.rs@@ -1350,7 +1350,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {.enumerate().map(|(i, c)| {let column_index = table_schema- .index_of_column_by_name(None, &c)?+ .index_of_column_by_name(None, &c).ok_or_else(|| unqualified_field_not_found(&c, &table_schema))?;if value_indices[column_index].is_some() {return schema_err!(SchemaError::DuplicateUnqualifiedField {