/// Print the random sample of given size in either json or json-like format
Print the random sample of given size in either json or json-like format
Print the random sample of given size in either json or json - like format
pub fn print_rows_random(
    file: File,
    sample_size: i64,
    json: bool,
) -> Result<(), PQRSError> {
    let parquet_reader = SerializedFileReader::new(file.try_clone()?)?;
    let mut iter = parquet_reader.get_row_iter(None)?;
    // find the number of records present in the file
    let total_records_in_file: i64 = get_row_count(file)?;
    // push all the indexes into the vector initially
    let mut indexes = (0..total_records_in_file).collect::<Vec<_>>();
    debug!("Original indexes: {:?}", indexes);
    // shuffle the indexes to randomize the vector
    let mut rng = thread_rng();
    indexes.shuffle(&mut rng);
    debug!("Shuffled indexes: {:?}", indexes);
    // take only the given number of records from the vector
    indexes = indexes
        .into_iter()
        .take(sample_size as usize)
        .collect::<Vec<_>>();
    debug!("Sampled indexes: {:?}", indexes);
    let mut start: i64 = 0;
    while let Some(row) = iter.next() {
        if indexes.contains(&start) {
            print_row(&row, json)
        }
        start += 1;
    }
    Ok(())
}
pub fn print_rows_random ( file : File , sample_size : i64 , json : bool , ) -> Result < ( ) , PQRSError > { let parquet_reader = SerializedFileReader :: new ( file . try_clone ( ) ? ) ? ; let mut iter = parquet_reader . get_row_iter ( None ) ? ; // find the number of records present in the file let total_records_in_file : i64 = get_row_count ( file ) ? ; // push all the indexes into the vector initially let mut indexes = ( 0 .. total_records_in_file ) . collect :: < Vec < _ > > ( ) ; debug ! ( " " indexes ) ; // shuffle the indexes to randomize the vector let mut rng = thread_rng ( ) ; indexes . shuffle ( & mut rng ) ; debug ! ( " " indexes ) ; // take only the given number of records from the vector indexes = indexes . into_iter ( ) . take ( sample_size as usize ) . collect :: < Vec < _ > > ( ) ; debug ! ( " " indexes ) ; let mut start : i64 = 0 ; while let Some ( row ) = iter . next ( ) { if indexes . contains ( & start ) { print_row ( & row , json ) } start += 1 ; } Ok ( ( ) ) }
Print the random sample of given size in either json or json-like format
Print the random sample of given size in either json or json - like format
file
File
sample_size
i64
json
bool