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

Function find_first_newline

datafusion/datasource/src/mod.rs:474–501  ·  view source on GitHub ↗

Asynchronously finds the position of the first newline character in a specified byte range within an object, such as a file, in an object store. This function scans the contents of the object starting from the specified `start` position up to the `end` position, looking for the first occurrence of a newline character. It returns the position of the first newline relative to the start of the range

(
    object_store: &Arc<dyn ObjectStore>,
    location: &Path,
    start: u64,
    end: u64,
    newline: u8,
)

Source from the content-addressed store, hash-verified

472///
473/// The function returns an `Error` if any issues arise while reading from the object store or processing the data stream.
474async fn find_first_newline(
475 object_store: &Arc<dyn ObjectStore>,
476 location: &Path,
477 start: u64,
478 end: u64,
479 newline: u8,
480) -> Result<u64> {
481 let options = GetOptions {
482 range: Some(GetRange::Bounded(start..end)),
483 ..Default::default()
484 };
485
486 let result = object_store.get_opts(location, options).await?;
487 let mut result_stream = result.into_stream();
488
489 let mut index = 0;
490
491 while let Some(chunk) = result_stream.next().await.transpose()? {
492 if let Some(position) = chunk.iter().position(|&byte| byte == newline) {
493 let position = position as u64;
494 return Ok(index + position);
495 }
496
497 index += chunk.len() as u64;
498 }
499
500 Ok(index)
501}
502
503/// Generates test files with min-max statistics in different overlap patterns.
504///

Callers 1

calculate_rangeFunction · 0.85

Calls 5

get_optsMethod · 0.45
into_streamMethod · 0.45
nextMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…