Github user sounakr commented on a diff in the pull request: https://github.com/apache/carbondata/pull/1079#discussion_r125191772 --- Diff: core/src/main/java/org/apache/carbondata/core/util/DataTypeUtil.java --- @@ -113,6 +115,143 @@ public static Object getMeasureValueBasedOnDataType(String msrValue, DataType da } } + public static Object getMeasureObjectFromDataType(byte[] data, DataType dataType) { + ByteBuffer bb = ByteBuffer.wrap(data); + switch (dataType) { + case SHORT: + case INT: + case LONG: + return bb.getLong(); + case DECIMAL: + return byteToBigDecimal(data); + default: + return bb.getDouble(); + } + } + + /** + * This method will convert a given ByteArray to its specific type + * + * @param msrValue + * @param dataType + * @param carbonMeasure + * @return + */ + // public static byte[] getMeasureByteArrayBasedOnDataType(String msrValue, DataType dataType, + // CarbonMeasure carbonMeasure) { + // switch (dataType) { + // case DECIMAL: + // BigDecimal bigDecimal = + // new BigDecimal(msrValue).setScale(carbonMeasure.getScale(), RoundingMode.HALF_UP); + // return ByteUtil.toBytes(normalizeDecimalValue(bigDecimal, carbonMeasure.getPrecision())); + // case SHORT: + // return ByteUtil.toBytes((Short.parseShort(msrValue))); + // case INT: + // return ByteUtil.toBytes(Integer.parseInt(msrValue)); + // case LONG: + // return ByteUtil.toBytes(Long.valueOf(msrValue)); + // default: + // Double parsedValue = Double.valueOf(msrValue); + // if (Double.isInfinite(parsedValue) || Double.isNaN(parsedValue)) { + // return null; + // } + // return ByteUtil.toBytes(parsedValue); + // } + // } + public static byte[] getMeasureByteArrayBasedOnDataTypes(String msrValue, DataType dataType, + CarbonMeasure carbonMeasure) { + ByteBuffer b; + switch (dataType) { + case BYTE: + case SHORT: + case INT: + case LONG: + b = ByteBuffer.allocate(8); + b.putLong(Long.valueOf(msrValue)); + b.flip(); + return b.array(); + case DOUBLE: + b = ByteBuffer.allocate(8); + b.putDouble(Double.valueOf(msrValue)); + b.flip(); + return b.array(); + case DECIMAL: + BigDecimal bigDecimal = + new BigDecimal(msrValue).setScale(carbonMeasure.getScale(), RoundingMode.HALF_UP); + return DataTypeUtil + .bigDecimalToByte(normalizeDecimalValue(bigDecimal, carbonMeasure.getPrecision())); + default: + throw new IllegalArgumentException("Invalid data type: " + dataType); + } + } + + /** + * This method will convert a given ByteArray to its specific type + * + * @param msrValue + * @param dataType + * @param carbonMeasure + * @return + */ + public static byte[] getMeasureByteArrayBasedOnDataType(ColumnPage measurePage, int index, --- End diff -- Done
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---