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

Feature/operator bit not #1321

Merged
merged 8 commits into from Jul 25, 2023
Merged

Conversation

gurugio
Copy link
Contributor

@gurugio gurugio commented Jul 22, 2023

In the last PR, I pushed a implementation for bot of BIT_NOT function and ~ operator.
As review comment, I removed implementation of BIT_NOT function and pushed only ~ operator in this PR.
Please review.

I will add more test cases if the coverage test result is not good enough.

@coveralls
Copy link

coveralls commented Jul 22, 2023

Pull Request Test Coverage Report for Build 5658019652

  • 130 of 144 (90.28%) changed or added relevant lines in 7 files are covered.
  • 17 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.05%) to 98.533%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test-suite/src/unary_operator.rs 85 99 85.86%
Files with Coverage Reduction New Missed Lines %
core/src/translate/operator.rs 1 96.88%
test-suite/src/tester/mod.rs 16 85.19%
Totals Coverage Status
Change from base Build 5657043771: -0.05%
Covered Lines: 46275
Relevant Lines: 46964

💛 - Coveralls

@gurugio
Copy link
Contributor Author

gurugio commented Jul 22, 2023

I am going to add some more tests to increase coverage.

Comment on lines 259 to 313
Evaluated::StrSlice { source, range } => {
Err(EvaluateError::UnsupportedUnaryBitNot(source[range.clone()].to_owned()).into())
}
Copy link
Member

Choose a reason for hiding this comment

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

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 me try.
Thank you for the review.

Copy link
Contributor Author

@gurugio gurugio Jul 23, 2023

Choose a reason for hiding this comment

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

I pushed a new patch to test EvaluateError::UnsupportedUnaryBitNot error.

@ever0de ever0de added the enhancement New feature or request label Jul 22, 2023
@ever0de ever0de linked an issue Jul 22, 2023 that may be closed by this pull request
This patch adds some test cases for the bitwise-not operator ~.
Gioh Kim added 3 commits July 23, 2023 22:47
This patch implements ~ operator
- Add translation from SqlUnaryOperator::PGBitwiseNot to
  ast::UnaryOerator::BitNot
- add ast::UnaryOperator::BitNot to ToSql implementation for
  UnaryOperator
- Add evaluation of UnaryOperator::BitNot into Value enum
- Add implementation of ~ operator in Value enum
This patch adds more tests to increase test coverage.
One more test to increase test coverage
@gurugio
Copy link
Contributor Author

gurugio commented Jul 24, 2023

I will add a test case to cover Null data.

The test missed ~ operator.
@@ -18,6 +19,7 @@ impl ToSql for UnaryOperator {
UnaryOperator::Minus => "-".to_owned(),
UnaryOperator::Not => "NOT ".to_owned(),
UnaryOperator::Factorial => "!".to_owned(),
&UnaryOperator::BitNot => "~".to_owned(),
Copy link
Member

Choose a reason for hiding this comment

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

  1. & is unnecessary. we can remove this.
  2. could we use Bitwise prefix rather than Bit because we already use bitwise for other operators. e.g. BinaryOperator::BitwiseAnd and BinaryOperator::BitwiseShiftLeft

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Ok. It's my mistake.
  2. Ok. I will change it to BitwiseNot.

There are already other bitwise operators,
for instance bitwise_and and bitwise_shift_left.
@gurugio
Copy link
Contributor Author

gurugio commented Jul 25, 2023

Hi,
I added test cases covering all new codes.
And change names as panarch's review.

Now I think it's ready to be merged.

@panarch panarch self-requested a review July 25, 2023 10:34
@@ -66,6 +66,7 @@ pub fn unary_op<'a>(op: &UnaryOperator, v: Evaluated<'a>) -> Result<Evaluated<'a
UnaryOperator::Minus => v.unary_minus(),
UnaryOperator::Not => v.try_into().map(|v: bool| Evaluated::from(Value::Bool(!v))),
UnaryOperator::Factorial => v.unary_factorial(),
&UnaryOperator::BitwiseNot => v.unary_bitwise_not(),
Copy link
Member

Choose a reason for hiding this comment

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

we can remove this &, too.

@@ -13,6 +13,7 @@ pub fn translate_unary_operator(sql_unary_operator: &SqlUnaryOperator) -> Result
SqlUnaryOperator::Minus => Ok(UnaryOperator::Minus),
SqlUnaryOperator::Not => Ok(UnaryOperator::Not),
SqlUnaryOperator::PGPostfixFactorial => Ok(UnaryOperator::Factorial),
&SqlUnaryOperator::PGBitwiseNot => Ok(UnaryOperator::BitwiseNot),
Copy link
Member

Choose a reason for hiding this comment

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

here, too.

@gurugio
Copy link
Contributor Author

gurugio commented Jul 25, 2023

Hi,
I just pushed PR again

  • remove unnecessary &
  • use test! macro for test suite

@panarch panarch self-requested a review July 25, 2023 14:46
Copy link
Member

@panarch panarch left a comment

Choose a reason for hiding this comment

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

Looks all nice! Thanks a lot for the contribution 👍 👍

@panarch panarch merged commit a4b1d59 into gluesql:main Jul 25, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement BIT_NOT function
4 participants