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

Separate and move testCast function #7912

Closed
wants to merge 1 commit into from

Conversation

rui-mo
Copy link
Collaborator

@rui-mo rui-mo commented Dec 7, 2023

Moves testCast function from CastExprTest.cpp to CastBaseTest.h for other
test files to use. Separates testCast function into testCast (for valid
output test), testTryCast (for try_cast test), and testInvalidCast (for
exception test).

#7377 (comment)
#7377 (comment)

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 7, 2023
Copy link

netlify bot commented Dec 7, 2023

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 4b23556
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/65728075ede4eb0008c399da

const std::string& typeString,
std::vector<std::optional<TFrom>> input,
std::vector<std::optional<TTo>> expectedResult,
bool tryCast = false,
Copy link
Collaborator Author

@rui-mo rui-mo Dec 7, 2023

Choose a reason for hiding this comment

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

tryCast is needed when test case wants to verify if error cases lead to null outputs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove tryCast parameter here and add another method: testTryCast. This will make tests a bit easier to read.

@rui-mo
Copy link
Collaborator Author

rui-mo commented Dec 7, 2023

@mbasmanova Could you help review? Thanks.

@mbasmanova mbasmanova requested a review from kagamiori December 7, 2023 12:04
Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@rui-mo Thank you for the refactoring. Looks nice % some nits.

template <typename TFrom, typename TTo>
void testCast(
const std::string& typeString,
std::vector<std::optional<TFrom>> input,
Copy link
Contributor

Choose a reason for hiding this comment

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

const& for input and expectedResult

const std::string& typeString,
std::vector<std::optional<TFrom>> input,
std::vector<std::optional<TTo>> expectedResult,
bool tryCast = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove tryCast parameter here and add another method: testTryCast. This will make tests a bit easier to read.

template <typename TFrom, typename TTo>
void testInvalidCast(
const std::string& typeString,
std::vector<std::optional<TFrom>> input,
Copy link
Contributor

Choose a reason for hiding this comment

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

const &

std::vector<std::optional<TFrom>> input,
const std::string& expectedErrorMessage,
const TypePtr& fromType = CppToType<TFrom>::create(),
const TypePtr& toType = CppToType<TTo>::create()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

toType parameter is not used

fmt::format("cast(c0 as {})", typeString),
createRowVector<TFrom>(input, fromType)),
expectedErrorMessage);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove


private:
template <typename T>
RowVectorPtr createRowVector(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use make makeRowVector({makeFlatVector(input, fromType)})?

@rui-mo
Copy link
Collaborator Author

rui-mo commented Dec 8, 2023

@mbasmanova Thanks for your review. Above comments were fixed.

@rui-mo rui-mo requested a review from mbasmanova December 8, 2023 02:19
Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

Thanks.

const TypePtr& fromType = CppToType<TFrom>::create(),
const TypePtr& toType = CppToType<TTo>::create()) {
auto result = evaluate(
"cast(c0 as " + typeString + ")",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: fmt::format

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, fixed.

const TypePtr& fromType = CppToType<TFrom>::create(),
const TypePtr& toType = CppToType<TTo>::create()) {
auto result = evaluate(
"try_cast(c0 as " + typeString + ")",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: fmt::format

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mbasmanova merged this pull request in bf6c3c1.

Copy link

Conbench analyzed the 1 benchmark run on commit bf6c3c13.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants