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

Method load

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

Create a mem table by reading from another data source

(
        t: Arc<dyn TableProvider>,
        output_partitions: Option<usize>,
        state: &dyn Session,
    )

Source from the content-addressed store, hash-verified

140
141 /// Create a mem table by reading from another data source
142 pub async fn load(
143 t: Arc<dyn TableProvider>,
144 output_partitions: Option<usize>,
145 state: &dyn Session,
146 ) -> Result<Self> {
147 let schema = t.schema();
148 let constraints = t.constraints();
149 let exec = t.scan(state, None, &[], None).await?;
150 let partition_count = exec.output_partitioning().partition_count();
151
152 let mut join_set = JoinSet::new();
153
154 for part_idx in 0..partition_count {
155 let task = state.task_ctx();
156 let exec = Arc::clone(&exec);
157 join_set.spawn(async move {
158 let stream = exec.execute(part_idx, task)?;
159 common::collect(stream).await
160 });
161 }
162
163 let mut data: Vec<Vec<RecordBatch>> =
164 Vec::with_capacity(exec.output_partitioning().partition_count());
165
166 while let Some(result) = join_set.join_next().await {
167 match result {
168 Ok(res) => data.push(res?),
169 Err(e) => {
170 if e.is_panic() {
171 std::panic::resume_unwind(e.into_panic());
172 } else {
173 unreachable!();
174 }
175 }
176 }
177 }
178
179 let mut exec = DataSourceExec::new(Arc::new(MemorySourceConfig::try_new(
180 &data,
181 Arc::clone(&schema),
182 None,
183 )?));
184 if let Some(cons) = constraints {
185 exec = exec.with_constraints(cons.clone());
186 }
187
188 if let Some(num_partitions) = output_partitions {
189 let exec = RepartitionExec::try_new(
190 Arc::new(exec),
191 Partitioning::RoundRobinBatch(num_partitions),
192 )?;
193
194 // execute and collect results
195 let mut output_partitions = vec![];
196 for i in 0..exec.properties().output_partitioning().partition_count() {
197 // execute this *output* partition and collect all batches
198 let task_ctx = state.task_ctx();
199 let mut stream = exec.execute(i, task_ctx)?;

Callers 15

use_row_selectionsMethod · 0.45
last_num_prunedMethod · 0.45
create_writing_threadFunction · 0.45
pollMethod · 0.45
dropMethod · 0.45
decr_empty_channelsMethod · 0.45
wokenMethod · 0.45
process_probe_batchMethod · 0.45
request_countMethod · 0.45

Calls 15

newFunction · 0.85
partition_countMethod · 0.80
join_nextMethod · 0.80
collectFunction · 0.50
schemaMethod · 0.45
constraintsMethod · 0.45
scanMethod · 0.45
output_partitioningMethod · 0.45
task_ctxMethod · 0.45
spawnMethod · 0.45
executeMethod · 0.45
pushMethod · 0.45

Tested by 8

create_writing_taskFunction · 0.36
evaluate_all_calledMethod · 0.36
evaluate_calledMethod · 0.36
update_batchMethod · 0.36
retract_batchMethod · 0.36
measure_max_rssFunction · 0.36