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>>)
| 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 { |