fn validate_result(check: &Check, rows: &[Row]) -> bool {
    let mut decoded_rows: Vec<Result<HashMap<String, String>, String>> =
        rows.iter().map(decode).collect();
    for row_check in &check.rows {
        // Identify a row that matches the check. Iterate over
        // all decoded rows and return the index of the first matching row
        let matching = decoded_rows.iter().position(|row| {
            match row {
                Ok(row) => {
                    // Check that all columns specified in the check
                    // have the expected value in the decoded row
                    for col in &row_check.columns {
                        let result = row.get(&col.column).unwrap();
                        if *result != col.value {
                            return false;
                        }
                    }
                    // If all match, then return row index
                    true
                }
                Err(e) => {
                    error!("{}", e);
                    false
                }
            }
        });

        // Remove item that we found (if any)
        if let Some(matched) = matching {
            decoded_rows.remove(matched).expect("Row must exist");
        } else {
            // No row matched our check, the validation should fail
            return false;
        }
    }

    // If there are any rows left in checked, the validation should fail
    decoded_rows.len() == 0
}
/// This method iterates over all checks and removes the first row that matches
/// the check, as well as the check.
/// The result is considered valid when
/// all checks have identified a row which matches the outlined equality
/// Given that we have no guarantee on the order in which rows are returned in the database,
/// checks are considered valid if one row matches the check. That row is then removed. This function
/// assumes that checks are already sorted by specificity
/// (number of columns that the check applies to). Once a row is found that satisfies the check, we remove the row from
/// the result vector. Once all row-checks within a check have passed, and there are no more rows in the result set
/// return true, otherwise, return false
/// TODO(natacha): this requires knowing the number of rows returned a priori. We should expand the correctness
/// to support unknown number of rows
This method iterates over all checks and removes the first row that matches
the check, as well as the check.
The result is considered valid when
all checks have identified a row which matches the outlined equality
Given that we have no guarantee on the order in which rows are returned in the database,
checks are considered valid if one row matches the check. That row is then removed. This function
assumes that checks are already sorted by specificity
(number of columns that the check applies to). Once a row is found that satisfies the check, we remove the row from
the result vector. Once all row-checks within a check have passed, and there are no more rows in the result set
return true, otherwise, return false
TODO(natacha): this requires knowing the number of rows returned a priori. We should expand the correctness
to support unknown number of rows
This method iterates over all checks and removes the first row that matches the check as well as the check . The result is considered valid when all checks have identified a row which matches the outlined equality Given that we have no guarantee on the order in which rows are returned in the database checks are considered valid if one row matches the check . That row is then removed . This function assumes that checks are already sorted by specificity ( number of columns that the check applies to ) . Once a row is found that satisfies the check we remove the row from the result vector . Once all row - checks within a check have passed and there are no more rows in the result set return true otherwise return false TODO ( natacha ) : this requires knowing the number of rows returned a priori . We should expand the correctness to support unknown number of rows
fn validate_result(check: &Check, rows: &[Row]) -> bool {
    let mut decoded_rows: Vec<Result<HashMap<String, String>, String>> =
        rows.iter().map(decode).collect();
    for row_check in &check.rows {
        // Identify a row that matches the check. Iterate over
        // all decoded rows and return the index of the first matching row
        let matching = decoded_rows.iter().position(|row| {
            match row {
                Ok(row) => {
                    // Check that all columns specified in the check
                    // have the expected value in the decoded row
                    for col in &row_check.columns {
                        let result = row.get(&col.column).unwrap();
                        if *result != col.value {
                            return false;
                        }
                    }
                    // If all match, then return row index
                    true
                }
                Err(e) => {
                    error!("{}", e);
                    false
                }
            }
        });
        // Remove item that we found (if any)
        if let Some(matched) = matching {
            decoded_rows.remove(matched).expect("Row must exist");
        } else {
            // No row matched our check, the validation should fail
            return false;
        }
    }
    // If there are any rows left in checked, the validation should fail
    decoded_rows.len() == 0
}
fn validate_result ( check : & Check , rows : & [ Row ] ) -> bool { let mut decoded_rows : Vec < Result < HashMap < String , String > , String > > = rows . iter ( ) . map ( decode ) . collect ( ) ; for row_check in & check . rows { // Identify a row that matches the check. Iterate over // all decoded rows and return the index of the first matching row let matching = decoded_rows . iter ( ) . position ( | row | { match row { Ok ( row ) => { // Check that all columns specified in the check // have the expected value in the decoded row for col in & row_check . columns { let result = row . get ( & col . column ) . unwrap ( ) ; if * result != col . value { return false ; } } // If all match, then return row index true } Err ( e ) => { error ! ( " " e ) ; false } } } ) ; // Remove item that we found (if any) if let Some ( matched ) = matching { decoded_rows . remove ( matched ) . expect ( " " ) ; } else { // No row matched our check, the validation should fail return false ; } } // If there are any rows left in checked, the validation should fail decoded_rows . len ( ) == 0 }
This method iterates over all checks and removes the first row that matches
the check, as well as the check.
This method iterates over all checks and removes the first row that matches the check as well as the check .
check
&Check
rows
&[Row]
check
&Check
rows
&[Row]