Java Code Examples for org.apache.hadoop.hbase.util.Bytes#toBigDecimal()
The following examples show how to use
org.apache.hadoop.hbase.util.Bytes#toBigDecimal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HBaseRowInputFormat.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private Object deserialize(byte[] value, int typeIdx) { switch (typeIdx) { case 0: // byte[] return value; case 1: return new String(value, stringCharset); case 2: // byte return value[0]; case 3: return Bytes.toShort(value); case 4: return Bytes.toInt(value); case 5: return Bytes.toLong(value); case 6: return Bytes.toFloat(value); case 7: return Bytes.toDouble(value); case 8: return Bytes.toBoolean(value); case 9: // sql.Timestamp encoded as long return new Timestamp(Bytes.toLong(value)); case 10: // sql.Date encoded as long return new Date(Bytes.toLong(value)); case 11: // sql.Time encoded as long return new Time(Bytes.toLong(value)); case 12: return Bytes.toBigDecimal(value); case 13: return new BigInteger(value); default: throw new IllegalArgumentException("Unknown type index " + typeIdx); } }
Example 2
Source File: HBaseRecordCursor.java From presto-hbase-connector with Apache License 2.0 | 5 votes |
/** * We store the column value in HBase like Bytes.toBytes(value) rather than Bytes.toBytes(value.toString) * * @param type type * @param value value * @return object */ Object matchValue(Type type, byte[] value) { if (type == null) { return Bytes.toString(value); } Class typeClass = type.getClass(); // return null if value is null // || (For varchar type if length is 0, return value is Bytes.toString(value), this will return "") // beside varchar type if length is 0, the value will be null if (value == null) { return null; } if (value.length == 0 && !typeClass.equals(VARCHAR_CLASS)) { return null; } if (typeClass.equals(VARCHAR_CLASS)) { return Bytes.toString(value); } else if (typeClass.equals(INTEGER_CLASS)) { return Bytes.toInt(value); } else if (typeClass.equals(BIGINT_CLASS)) { return Bytes.toLong(value); } else if (typeClass.equals(DOUBLE_CLASS)) { return Bytes.toDouble(value); } else if (typeClass.equals(TIMESTAMP_CLASS)) { return Bytes.toLong(value); } else if (typeClass.equals(BOOLEAN_CLASS)) { // 0: false, 1: true return Bytes.toInt(value); } else if (type.getClass().getSuperclass().equals(DecimalType.class)) { return Bytes.toBigDecimal(value); } else { return Bytes.toString(value); } }
Example 3
Source File: HBaseTypeUtils.java From flink with Apache License 2.0 | 5 votes |
/** * Deserialize byte array to Java Object with the given type. */ public static Object deserializeToObject(byte[] value, int typeIdx, Charset stringCharset) { switch (typeIdx) { case 0: // byte[] return value; case 1: // String return new String(value, stringCharset); case 2: // byte return value[0]; case 3: return Bytes.toShort(value); case 4: return Bytes.toInt(value); case 5: return Bytes.toLong(value); case 6: return Bytes.toFloat(value); case 7: return Bytes.toDouble(value); case 8: return Bytes.toBoolean(value); case 9: // sql.Timestamp encoded as long return new Timestamp(Bytes.toLong(value)); case 10: // sql.Date encoded as long return new Date(Bytes.toLong(value)); case 11: // sql.Time encoded as long return new Time(Bytes.toLong(value)); case 12: return Bytes.toBigDecimal(value); case 13: return new BigInteger(value); default: throw new IllegalArgumentException("unsupported type index:" + typeIdx); } }
Example 4
Source File: HBaseSerde.java From flink with Apache License 2.0 | 5 votes |
private static FieldDecoder createDecimalDecoder(DecimalType decimalType) { final int precision = decimalType.getPrecision(); final int scale = decimalType.getScale(); return value -> { BigDecimal decimal = Bytes.toBigDecimal(value); return DecimalData.fromBigDecimal(decimal, precision, scale); }; }
Example 5
Source File: HBaseTypeUtils.java From flink with Apache License 2.0 | 5 votes |
/** * Deserialize byte array to Java Object with the given type. */ public static Object deserializeToObject(byte[] value, int typeIdx, Charset stringCharset) { switch (typeIdx) { case 0: // byte[] return value; case 1: // String return Arrays.equals(EMPTY_BYTES, value) ? null : new String(value, stringCharset); case 2: // byte return value[0]; case 3: return Bytes.toShort(value); case 4: return Bytes.toInt(value); case 5: return Bytes.toLong(value); case 6: return Bytes.toFloat(value); case 7: return Bytes.toDouble(value); case 8: return Bytes.toBoolean(value); case 9: // sql.Timestamp encoded as long return new Timestamp(Bytes.toLong(value)); case 10: // sql.Date encoded as long return new Date(Bytes.toLong(value)); case 11: // sql.Time encoded as long return new Time(Bytes.toLong(value)); case 12: return Bytes.toBigDecimal(value); case 13: return new BigInteger(value); default: throw new IllegalArgumentException("unsupported type index:" + typeIdx); } }
Example 6
Source File: BigDecimalComparator.java From hbase with Apache License 2.0 | 5 votes |
/** * @param pbBytes A pb serialized {@link BigDecimalComparator} instance * @return An instance of {@link BigDecimalComparator} made from <code>bytes</code> * @throws DeserializationException A deserialization exception * @see #toByteArray */ public static BigDecimalComparator parseFrom(final byte[] pbBytes) throws DeserializationException { ComparatorProtos.BigDecimalComparator proto; try { proto = ComparatorProtos.BigDecimalComparator.parseFrom(pbBytes); } catch (InvalidProtocolBufferException e) { throw new DeserializationException(e); } return new BigDecimalComparator(Bytes.toBigDecimal(proto.getComparable().getValue() .toByteArray())); }
Example 7
Source File: PrivateCellUtil.java From hbase with Apache License 2.0 | 5 votes |
/** * Converts the value bytes of the given cell into a BigDecimal * @param cell * @return value as BigDecimal */ public static BigDecimal getValueAsBigDecimal(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toBigDecimal(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition(), cell.getValueLength()); } return Bytes.toBigDecimal(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); }
Example 8
Source File: BigDecimalColumnInterpreter.java From hbase with Apache License 2.0 | 4 votes |
@Override public BigDecimal getPromotedValueFromProto(BigDecimalMsg r) { return Bytes.toBigDecimal(r.getBigdecimalMsg().toByteArray()); }
Example 9
Source File: BigDecimalColumnInterpreter.java From hbase with Apache License 2.0 | 4 votes |
@Override public BigDecimal getCellValueFromProto(BigDecimalMsg q) { return Bytes.toBigDecimal(q.getBigdecimalMsg().toByteArray()); }
Example 10
Source File: BigDecimalComparator.java From hbase with Apache License 2.0 | 4 votes |
@Override public int compareTo(byte[] value, int offset, int length) { BigDecimal that = Bytes.toBigDecimal(value, offset, length); return this.bigDecimal.compareTo(that); }
Example 11
Source File: ByteArrayValueMappers.java From hbase-indexer with Apache License 2.0 | 4 votes |
@Override protected Object mapInternal(byte[] input) { return Bytes.toBigDecimal(input); }