MCPcopy Create free account
hub / github.com/apache/datafusion / create_view

Method create_view

datafusion/core/src/execution/context/mod.rs:939–972  ·  view source on GitHub ↗
(&self, cmd: CreateView)

Source from the content-addressed store, hash-verified

937 }
938
939 async fn create_view(&self, cmd: CreateView) -> Result<DataFrame> {
940 let CreateView {
941 name,
942 input,
943 or_replace,
944 definition,
945 temporary,
946 } = cmd;
947
948 let view = self.table(name.clone()).await;
949
950 if temporary {
951 return not_impl_err!("Temporary views not supported");
952 }
953
954 match (or_replace, view) {
955 (true, Ok(_)) => {
956 let input = Self::apply_type_coercion(Arc::unwrap_or_clone(input))?;
957 Self::ensure_unique_column_names(input.schema())?;
958 self.deregister_table(name.clone())?;
959 let table = Arc::new(ViewTable::new(input, definition));
960 self.register_table(name, table)?;
961 self.return_empty_dataframe()
962 }
963 (_, Err(_)) => {
964 let input = Self::apply_type_coercion(Arc::unwrap_or_clone(input))?;
965 Self::ensure_unique_column_names(input.schema())?;
966 let table = Arc::new(ViewTable::new(input, definition));
967 self.register_table(name, table)?;
968 self.return_empty_dataframe()
969 }
970 (false, Ok(_)) => exec_err!("Table '{name}' already exists"),
971 }
972 }
973
974 fn ensure_unique_column_names(schema: &DFSchema) -> Result<()> {
975 // DFSchema name checks allow duplicate unqualified names as long as their

Callers 1

execute_logical_planMethod · 0.80

Calls 7

newFunction · 0.85
tableMethod · 0.45
cloneMethod · 0.45
schemaMethod · 0.45
deregister_tableMethod · 0.45
register_tableMethod · 0.45

Tested by

no test coverage detected