Convert each [TableConstraint] to corresponding [Constraint]
(
&self,
constraints: &[TableConstraint],
df_schema: &DFSchemaRef,
)
| 1897 | |
| 1898 | /// Convert each [TableConstraint] to corresponding [Constraint] |
| 1899 | pub fn new_constraint_from_table_constraints( |
| 1900 | &self, |
| 1901 | constraints: &[TableConstraint], |
| 1902 | df_schema: &DFSchemaRef, |
| 1903 | ) -> Result<Constraints> { |
| 1904 | let constraints = constraints |
| 1905 | .iter() |
| 1906 | .map(|c: &TableConstraint| match c { |
| 1907 | TableConstraint::Unique(UniqueConstraint { |
| 1908 | name, |
| 1909 | index_name: _, |
| 1910 | index_type_display: _, |
| 1911 | index_type: _, |
| 1912 | columns, |
| 1913 | index_options: _, |
| 1914 | characteristics: _, |
| 1915 | nulls_distinct: _, |
| 1916 | }) => { |
| 1917 | let constraint_name = match &name { |
| 1918 | Some(name) => &format!("unique constraint with name '{name}'"), |
| 1919 | None => "unique constraint", |
| 1920 | }; |
| 1921 | // Get unique constraint indices in the schema |
| 1922 | let indices = self.get_constraint_column_indices( |
| 1923 | df_schema, |
| 1924 | columns, |
| 1925 | constraint_name, |
| 1926 | )?; |
| 1927 | Ok(Constraint::Unique(indices)) |
| 1928 | } |
| 1929 | TableConstraint::PrimaryKey(PrimaryKeyConstraint { |
| 1930 | name: _, |
| 1931 | index_name: _, |
| 1932 | index_type: _, |
| 1933 | columns, |
| 1934 | index_options: _, |
| 1935 | characteristics: _, |
| 1936 | }) => { |
| 1937 | // Get primary key indices in the schema |
| 1938 | let indices = self.get_constraint_column_indices( |
| 1939 | df_schema, |
| 1940 | columns, |
| 1941 | "primary key", |
| 1942 | )?; |
| 1943 | Ok(Constraint::PrimaryKey(indices)) |
| 1944 | } |
| 1945 | TableConstraint::ForeignKey { .. } => { |
| 1946 | _plan_err!("Foreign key constraints are not currently supported") |
| 1947 | } |
| 1948 | TableConstraint::Check { .. } => { |
| 1949 | _plan_err!("Check constraints are not currently supported") |
| 1950 | } |
| 1951 | TableConstraint::Index { .. } => { |
| 1952 | _plan_err!("Indexes are not currently supported") |
| 1953 | } |
| 1954 | TableConstraint::FulltextOrSpatial { .. } => { |
| 1955 | _plan_err!("Indexes are not currently supported") |
| 1956 | } |
no test coverage detected