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

Method run

datafusion/core/tests/fuzz_cases/sort_fuzz.rs:226–292  ·  view source on GitHub ↗

Sort the input using SortExec and ensure the results are correct according to `Vec::sort` both with and without spilling

(&self)

Source from the content-addressed store, hash-verified

224 /// Sort the input using SortExec and ensure the results are
225 /// correct according to `Vec::sort` both with and without spilling
226 async fn run(&self) -> (Vec<Vec<RecordBatch>>, Vec<RecordBatch>) {
227 let input = self.input.clone();
228 let first_batch = input
229 .iter()
230 .flat_map(|p| p.iter())
231 .next()
232 .expect("at least one batch");
233 let schema = first_batch.schema();
234
235 let sort_ordering =
236 LexOrdering::new(self.sort_columns.iter().map(|c| PhysicalSortExpr {
237 expr: col(c, &schema).unwrap(),
238 options: SortOptions {
239 descending: false,
240 nulls_first: true,
241 },
242 }))
243 .unwrap();
244
245 let exec = MemorySourceConfig::try_new_exec(&input, schema, None).unwrap();
246 let sort = Arc::new(SortExec::new(sort_ordering, exec));
247
248 let session_config = SessionConfig::new().with_repartition_file_scans(false);
249 let session_ctx = if let Some(pool_size) = self.pool_size {
250 // Make sure there is enough space for the initial spill
251 // reservation
252 let pool_size = pool_size.saturating_add(
253 session_config
254 .options()
255 .execution
256 .sort_spill_reservation_bytes,
257 );
258
259 let runtime = RuntimeEnvBuilder::new()
260 .with_memory_pool(Arc::new(GreedyMemoryPool::new(pool_size)))
261 .build_arc()
262 .unwrap();
263 SessionContext::new_with_config_rt(session_config, runtime)
264 } else {
265 SessionContext::new_with_config(session_config)
266 };
267
268 let task_ctx = session_ctx.task_ctx();
269 let collected = collect(sort.clone(), task_ctx).await.unwrap();
270
271 if self.should_spill {
272 assert_ne!(
273 sort.metrics().unwrap().spill_count().unwrap(),
274 0,
275 "Expected spill, but did not: {self:?}"
276 );
277 } else {
278 assert_eq!(
279 sort.metrics().unwrap().spill_count().unwrap(),
280 0,
281 "Expected no spill, but did: {self:?}"
282 );
283 }

Callers 5

test_sort_10k_memFunction · 0.45
test_sort_100k_memFunction · 0.45
test_sort_unlimited_memFunction · 0.45

Calls 13

newFunction · 0.85
build_arcMethod · 0.80
colFunction · 0.50
collectFunction · 0.50
cloneMethod · 0.45
nextMethod · 0.45
iterMethod · 0.45
schemaMethod · 0.45
mapMethod · 0.45
optionsMethod · 0.45
with_memory_poolMethod · 0.45

Tested by

no test coverage detected