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

Implement BIT_SHIFT_LEFT operation #1286

Merged
merged 25 commits into from Jul 22, 2023

Conversation

codernineteen
Copy link
Contributor

From the issue #1271,
Added below key features to several modules in core directory.

  1. a way to translate the result of sqlparser
  2. a execute path for shift_left operation
  3. a definition of the operator '<<' as 'ShiftLeft'
  4. new variant in LiteralError
  5. test cases for above implementations

Body : Defined a new type to support bit shift operation and added a logic to pass from sqlparesr to gluesql ast builder
Body : Basically the structure of function is similar to other binary operations. But i added new vriant of LiteralError to make error-handling more sense
Body : This needs to make the statement executable.
@ever0de ever0de linked an issue Jul 14, 2023 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Jul 14, 2023

Pull Request Test Coverage Report for Build 5629113870

  • 294 of 296 (99.32%) changed or added relevant lines in 8 files are covered.
  • 17 unchanged lines in 5 files lost coverage.
  • Overall coverage decreased (-0.07%) to 98.638%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test-suite/src/bitwise_shift.rs 40 42 95.24%
Files with Coverage Reduction New Missed Lines %
core/src/ast/function.rs 1 99.89%
core/src/executor/evaluate/function.rs 1 97.72%
core/src/plan/expr/function.rs 1 99.58%
core/src/executor/evaluate/error.rs 7 0%
core/src/translate/mod.rs 7 96.39%
Totals Coverage Status
Change from base Build 5550958766: -0.07%
Covered Lines: 43951
Relevant Lines: 44558

💛 - Coveralls

test-suite/src/lib.rs Outdated Show resolved Hide resolved
test-suite/src/lib.rs Outdated Show resolved Hide resolved
@panarch panarch requested review from ever0de and devgony July 14, 2023 14:22
@panarch panarch added the enhancement New feature or request label Jul 14, 2023
core/src/ast/operator.rs Outdated Show resolved Hide resolved
core/src/data/value/mod.rs Outdated Show resolved Hide resolved
core/src/executor/evaluate/evaluated.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@codernineteen codernineteen left a comment

Choose a reason for hiding this comment

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

https://docs.rs/num-traits/latest/num_traits/ops/checked/trait.CheckedShl.html

According to above docs, it is true that 'checked_shl' was implemented for most of primitive integer types. However it seems that 'rhs' parameter for checked_shl is 'u32' type.
When i ran the test cases i wrote in suite, i always got the I64 Value type as a result. That's why i added this conversion funtionality into this module.
If there is anything i misunderstood , pls feedback )

test-suite/src/lib.rs Outdated Show resolved Hide resolved
@panarch
Copy link
Member

panarch commented Jul 17, 2023

https://docs.rs/num-traits/latest/num_traits/ops/checked/trait.CheckedShl.html

We don't need to use num-traits because the primitive types already support checked_shl by default.
ref. https://doc.rust-lang.org/std/primitive.i32.html#method.checked_shl

it would be better to see the doc of rust primitive integer types.
each of them returns the same type of itself.

1. shift_left -> bitwise_shift_left
2. ShiftLeft -> BitwiseShiftLeft
I separated rhs match expression from original match pattern so that it can remove duplicated parts in the previous implementation
i also covered some missed lines
core/src/data/value/mod.rs Outdated Show resolved Hide resolved
Also reflected the changes into related files
1. Removed 'validate_bitwise_shift_rhs' because it was only being used by this function
2. Deleted duplicated error handling because we can treat it in ok_or_else parenthesis when the 'checked_shl' fail
core/src/data/literal.rs Outdated Show resolved Hide resolved
core/src/data/literal.rs Outdated Show resolved Hide resolved
core/src/ast_builder/expr/binary_op.rs Outdated Show resolved Hide resolved
core/src/data/value/mod.rs Outdated Show resolved Hide resolved
core/src/data/value/mod.rs Outdated Show resolved Hide resolved
core/src/data/value/mod.rs Show resolved Hide resolved
core/src/data/literal.rs Outdated Show resolved Hide resolved
Following review request, i added if statement to keep consistency if rhs is Null value by return Ok(Null)
1. Separated test cases into additional unit test case block.
2. Added new error variant into 'LiteralError' enum
3. Edit the implementation detail of bitwise_shift_left to handle explicit error handling
New error variant list :
- BitwiseNonIntegerOperand for a operand that is Number literal, but not an integer type
- BitwiseNonNumberLiteral for non number literal type
- BitwiseOperationOverflow for overflow exception case
- ImpossibleConversion when it is impossible to cast a value to another type
@panarch panarch self-requested a review July 22, 2023 08:02
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 great! Thanks a lot for the contribution 👍 👍

@panarch panarch merged commit 7cd1c5d into gluesql:main Jul 22, 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_SHIFT function
3 participants