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

Method try_new

datafusion/catalog/src/memory/table.rs:83–109  ·  view source on GitHub ↗

Create a new in-memory table from the provided schema and record batches. Requires at least one partition. To construct an empty `MemTable`, pass `vec![vec![]]` as the `partitions` argument, this represents one partition with no batches.

(schema: SchemaRef, partitions: Vec<Vec<RecordBatch>>)

Source from the content-addressed store, hash-verified

81 /// `vec![vec![]]` as the `partitions` argument, this represents one partition with
82 /// no batches.
83 pub fn try_new(schema: SchemaRef, partitions: Vec<Vec<RecordBatch>>) -> Result<Self> {
84 if partitions.is_empty() {
85 return plan_err!("No partitions provided, expected at least one partition");
86 }
87
88 for batches in partitions.iter().flatten() {
89 let batches_schema = batches.schema();
90 if !schema.contains(&batches_schema) {
91 debug!(
92 "mem table schema does not contain batches schema. \
93 Target_schema: {schema:?}. Batches Schema: {batches_schema:?}"
94 );
95 return plan_err!("Mismatch between schema and batches");
96 }
97 }
98
99 Ok(Self {
100 schema,
101 batches: partitions
102 .into_iter()
103 .map(|e| Arc::new(RwLock::new(e)))
104 .collect::<Vec<_>>(),
105 constraints: Constraints::default(),
106 column_defaults: HashMap::new(),
107 sort_order: Arc::new(Mutex::new(vec![])),
108 })
109 }
110
111 /// Assign constraints
112 pub fn with_constraints(mut self, constraints: Constraints) -> Self {

Callers 1

tableMethod · 0.45

Calls 8

newFunction · 0.85
flattenMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
schemaMethod · 0.45
containsMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected