Generate a logical plan from a CREATE EXTERNAL TABLE statement
(
&self,
statement: CreateExternalTable,
)
| 1789 | |
| 1790 | /// Generate a logical plan from a CREATE EXTERNAL TABLE statement |
| 1791 | fn external_table_to_plan( |
| 1792 | &self, |
| 1793 | statement: CreateExternalTable, |
| 1794 | ) -> Result<LogicalPlan> { |
| 1795 | let definition = Some(statement.to_string()); |
| 1796 | let CreateExternalTable { |
| 1797 | name, |
| 1798 | columns, |
| 1799 | file_type, |
| 1800 | location, |
| 1801 | table_partition_cols, |
| 1802 | if_not_exists, |
| 1803 | temporary, |
| 1804 | order_exprs, |
| 1805 | unbounded, |
| 1806 | options, |
| 1807 | constraints, |
| 1808 | or_replace, |
| 1809 | } = statement; |
| 1810 | |
| 1811 | // Merge inline constraints and existing constraints |
| 1812 | let mut all_constraints = constraints; |
| 1813 | let inline_constraints = calc_inline_constraints_from_columns(&columns); |
| 1814 | all_constraints.extend(inline_constraints); |
| 1815 | |
| 1816 | let options_map = self.parse_options_map(options, false)?; |
| 1817 | |
| 1818 | let compression = options_map |
| 1819 | .get("format.compression") |
| 1820 | .map(|c| CompressionTypeVariant::from_str(c)) |
| 1821 | .transpose()?; |
| 1822 | if (file_type == "PARQUET" || file_type == "AVRO" || file_type == "ARROW") |
| 1823 | && compression |
| 1824 | .map(|c| c != CompressionTypeVariant::UNCOMPRESSED) |
| 1825 | .unwrap_or(false) |
| 1826 | { |
| 1827 | plan_err!( |
| 1828 | "File compression type cannot be set for PARQUET, AVRO, or ARROW files." |
| 1829 | )?; |
| 1830 | } |
| 1831 | |
| 1832 | let mut planner_context = PlannerContext::new(); |
| 1833 | |
| 1834 | let column_defaults = self |
| 1835 | .build_column_defaults(&columns, &mut planner_context)? |
| 1836 | .into_iter() |
| 1837 | .collect(); |
| 1838 | |
| 1839 | let schema = self.build_schema(columns)?; |
| 1840 | let df_schema = schema.to_dfschema_ref()?; |
| 1841 | df_schema.check_names()?; |
| 1842 | |
| 1843 | let ordered_exprs = |
| 1844 | self.build_order_by(order_exprs, &df_schema, &mut planner_context)?; |
| 1845 | |
| 1846 | let name = self.object_name_to_table_reference(name)?; |
| 1847 | let constraints = |
| 1848 | self.new_constraint_from_table_constraints(&all_constraints, &df_schema)?; |
no test coverage detected