AMashenkov commented on a change in pull request #243:
URL: https://github.com/apache/ignite-3/pull/243#discussion_r679940432
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/row/Row.java
##########
@@ -233,8 +235,55 @@ public Double doubleValueBoxed(int col) throws
InvalidTypeException {
* @throws InvalidTypeException If actual column type does not match the
requested column type.
*/
public BigDecimal decimalValue(int col) throws InvalidTypeException {
- // TODO: IGNITE-13668 decimal support
- return null;
+ long offLen = findColumn(col, NativeTypeSpec.DECIMAL);
+
+ if (offLen < 0)
+ return offLen == -1 ? null :
(BigDecimal)rowSchema().column(col).defaultValue();
+
+ int off = offset(offLen);
+ int len = length(offLen);
+
+ DecimalNativeType type = (DecimalNativeType)schema.column(col).type();
+
+ int shift;
+ int scale;
+
+ if (type.scale() == 0) {
+ shift = 0;
+ scale = 0;
+ } else if (type.scale() < Byte.MAX_VALUE) {
+ shift = 1;
+ scale = readByte(off);
+ } else if (type.scale() < Short.MAX_VALUE) {
+ shift = 2;
+ scale = readShort(off);
+ } else {
+ shift = 4;
+ scale = readInteger(off);
+ }
Review comment:
You can convert byte/shot value to unsigned int and got twice more range.
Also it is possible to extract a method for writing varInt values, where
sign-bit indicates where the value fits the byte or not.
```
scale = readByte(off);
if (scale < 0)
scale = ((-scale) << 8) | readByte(off+1);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]