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

Method try_new

datafusion/catalog-listing/src/table.rs:202–240  ·  view source on GitHub ↗

Create new [`ListingTable`] See documentation and example on [`ListingTable`] and [`ListingTableConfig`]

(config: ListingTableConfig)

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
schema_sourceMethod · 0.45
as_refMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
with_metadataMethod · 0.45
finishMethod · 0.45
metadataMethod · 0.45

Tested by

no test coverage detected