Get the indices of the constraint columns in the schema. If any column is not found, return an error.
(
&self,
df_schema: &DFSchemaRef,
columns: &[IndexColumn],
constraint_name: &str,
)
| 1865 | /// Get the indices of the constraint columns in the schema. |
| 1866 | /// If any column is not found, return an error. |
| 1867 | fn get_constraint_column_indices( |
| 1868 | &self, |
| 1869 | df_schema: &DFSchemaRef, |
| 1870 | columns: &[IndexColumn], |
| 1871 | constraint_name: &str, |
| 1872 | ) -> Result<Vec<usize>> { |
| 1873 | let field_names = df_schema.field_names(); |
| 1874 | columns |
| 1875 | .iter() |
| 1876 | .map(|index_column| { |
| 1877 | let expr = &index_column.column.expr; |
| 1878 | let ident = if let SQLExpr::Identifier(ident) = expr { |
| 1879 | ident |
| 1880 | } else { |
| 1881 | return Err(plan_datafusion_err!( |
| 1882 | "Column name for {constraint_name} must be an identifier: {expr}" |
| 1883 | )); |
| 1884 | }; |
| 1885 | let column = self.ident_normalizer.normalize(ident.clone()); |
| 1886 | field_names |
| 1887 | .iter() |
| 1888 | .position(|item| *item == column) |
| 1889 | .ok_or_else(|| { |
| 1890 | plan_datafusion_err!( |
| 1891 | "Column for {constraint_name} not found in schema: {column}" |
| 1892 | ) |
| 1893 | }) |
| 1894 | }) |
| 1895 | .collect::<Result<Vec<_>>>() |
| 1896 | } |
| 1897 | |
| 1898 | /// Convert each [TableConstraint] to corresponding [Constraint] |
| 1899 | pub fn new_constraint_from_table_constraints( |
no test coverage detected