Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update_record_with_output function and tests #130

Merged
merged 3 commits into from
Dec 13, 2022

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Dec 11, 2022

Draft as it builds on #129

Rationale

I want to be able to update Records given the output of a particular run (see apache/datafusion#4570)

Changes

  1. Add update_record_with_output function
  2. Tests

I think this is my last planned PR to sqllogictest for a bit (I want to go try and integrated this into DataFusion upstream first)

Signed-off-by: Andrew Lamb <andrew@nerdnetworks.org>
@alamb alamb marked this pull request as ready for review December 11, 2022 11:51
})
}

// No update possible, return the original record
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look at update_record? https://github.com/risinglightdb/sqllogictest-rs/blob/46752d1b536f186e3f976bdfce4968ce761ab230/sqllogictest-bin/src/lib.rs

I think they are highly alike, but it contains more updatable edge cases. How do you think the differences?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I forgot out update_record

I think it is cleaner to update the Record and then use the Display logic to print it back out, rather than write to a new file directly. However, there is nothing wrong with generating the text directly (but there may be more chance of inconsistencies)

I am out of time for coding today, sadly, but I will think on this question and see if I can come to a conclusion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xxchan if I want to refactor update_record and avoid breaking your tests, what is the best way to do so? I have been running cargo test but I guess that is not the only thing 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alamb I did the refactor. You can take a look whether it looks good to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look - and it looks good to me @xxchan -- thank you 🙏

The only thing I would normally do is to write some more tests to cover these cases (and also illustrate how the updates work)-- perhaps I can do that as a follow on PR?

Copy link
Contributor Author

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wonderful @xxchan -- thank you for pushing this over the line

/// By default ([`default_validator`]), we will use compare normalized results.
pub type Validator = fn(actual: &[Vec<String>], expected: &[String]) -> bool;

pub fn default_validator(actual: &[Vec<String>], expected: &[String]) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let record_output = runner.apply_record(record.clone()).await;
match update_record_with_output(&record, &record_output, "\t", default_validator) {
Some(new_record) => {
writeln!(outfile, "{new_record}")?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

expected_results,
},
RecordOutput::Query {
// FIXME: maybe we should use output's types instead of orignal query's types
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I agree it should use the output query types

})
}

// No update possible, return the original record
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look - and it looks good to me @xxchan -- thank you 🙏

The only thing I would normally do is to write some more tests to cover these cases (and also illustrate how the updates work)-- perhaps I can do that as a follow on PR?

@alamb
Copy link
Contributor Author

alamb commented Dec 13, 2022

@xxchan would you like me to add tests to this PR or do you plan to merge this one and have me add more tests as a follow on PR?

@xxchan
Copy link
Member

xxchan commented Dec 13, 2022

Let's merge it first and improve it later, since it generally looks good and works well in my manual testing.

@xxchan xxchan merged commit 7030a63 into risinglightdb:main Dec 13, 2022
@alamb alamb deleted the alamb/record_update branch December 13, 2022 23:00
@alamb
Copy link
Contributor Author

alamb commented Dec 13, 2022

Let's merge it first and improve it later, since it generally looks good and works well in my manual testing.

Here is a follow on PR #131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants