Create new [`ListingTable`] See documentation and example on [`ListingTable`] and [`ListingTableConfig`]
(config: ListingTableConfig)
| 200 | /// |
| 201 | /// See documentation and example on [`ListingTable`] and [`ListingTableConfig`] |
| 202 | pub fn try_new(config: ListingTableConfig) -> datafusion_common::Result<Self> { |
| 203 | // Extract schema_source before moving other parts of the config |
| 204 | let schema_source = config.schema_source(); |
| 205 | |
| 206 | let file_schema = config |
| 207 | .file_schema |
| 208 | .ok_or_else(|| internal_datafusion_err!("No schema provided."))?; |
| 209 | |
| 210 | let options = config |
| 211 | .options |
| 212 | .ok_or_else(|| internal_datafusion_err!("No ListingOptions provided"))?; |
| 213 | |
| 214 | // Add the partition columns to the file schema |
| 215 | let mut builder = SchemaBuilder::from(file_schema.as_ref().to_owned()); |
| 216 | for (part_col_name, part_col_type) in &options.table_partition_cols { |
| 217 | builder.push(Field::new(part_col_name, part_col_type.clone(), false)); |
| 218 | } |
| 219 | |
| 220 | let table_schema = Arc::new( |
| 221 | builder |
| 222 | .finish() |
| 223 | .with_metadata(file_schema.metadata().clone()), |
| 224 | ); |
| 225 | |
| 226 | let table = Self { |
| 227 | table_paths: config.table_paths, |
| 228 | file_schema, |
| 229 | table_schema, |
| 230 | schema_source, |
| 231 | options, |
| 232 | definition: None, |
| 233 | collected_statistics: None, |
| 234 | constraints: Constraints::default(), |
| 235 | column_defaults: HashMap::new(), |
| 236 | expr_adapter_factory: config.expr_adapter_factory, |
| 237 | }; |
| 238 | |
| 239 | Ok(table) |
| 240 | } |
| 241 | |
| 242 | /// Assign constraints |
| 243 | pub fn with_constraints(mut self, constraints: Constraints) -> Self { |
nothing calls this directly
no test coverage detected