Java Code Examples for org.apache.hadoop.hbase.util.Bytes#SIZEOF_DOUBLE

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#SIZEOF_DOUBLE . 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: HBaseBinaryConverter.java    From spork with Apache License 2.0 5 votes vote down vote up
@Override
public Double bytesToDouble(byte[] b) throws IOException {
    if (Bytes.SIZEOF_DOUBLE > b.length){
        return Bytes.toDouble(Bytes.padHead(b, Bytes.SIZEOF_DOUBLE - b.length));
    } else {
        return Bytes.toDouble(Bytes.head(b, Bytes.SIZEOF_DOUBLE));
    }
}
 
Example 2
Source File: PhTypeUtil.java    From canal with Apache License 2.0 5 votes vote down vote up
private static int encodeUnsignedDouble(double v, byte[] b, int o) {
    checkForSufficientLength(b, o, Bytes.SIZEOF_DOUBLE);
    if (v < 0) {
        throw new RuntimeException();
    }
    Bytes.putDouble(b, o, v);
    return Bytes.SIZEOF_DOUBLE;
}
 
Example 3
Source File: PUnsignedDouble.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public int encodeDouble(double v, byte[] b, int o) {
    checkForSufficientLength(b, o, Bytes.SIZEOF_DOUBLE);
    if (v < 0) {
        throw newIllegalDataException();
    }
    Bytes.putDouble(b, o, v);
    return Bytes.SIZEOF_DOUBLE;
}
 
Example 4
Source File: DoubleColumnInterpreter.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public Double getValue(byte[] colFamily, byte[] colQualifier, Cell c)
    throws IOException {
  if (c == null || c.getValueLength() != Bytes.SIZEOF_DOUBLE)
    return null;
  return PrivateCellUtil.getValueAsDouble(c);
}
 
Example 5
Source File: PUnsignedDouble.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public int encodeDouble(double v, byte[] b, int o) {
  checkForSufficientLength(b, o, Bytes.SIZEOF_DOUBLE);
  if (v < 0) {
    throw newIllegalDataException();
  }
  Bytes.putDouble(b, o, v);
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 6
Source File: PhTypeUtil.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private static int encodeUnsignedDouble(double v, byte[] b, int o) {
    checkForSufficientLength(b, o, Bytes.SIZEOF_DOUBLE);
    if (v < 0) {
        throw new RuntimeException();
    }
    Bytes.putDouble(b, o, v);
    return Bytes.SIZEOF_DOUBLE;
}
 
Example 7
Source File: PUnsignedDouble.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] toBytes(Object object) {
  byte[] b = new byte[Bytes.SIZEOF_DOUBLE];
  toBytes(object, b, 0);
  return b;
}
 
Example 8
Source File: PUnsignedDouble.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 9
Source File: PDouble.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] toBytes(Object object) {
  byte[] b = new byte[Bytes.SIZEOF_DOUBLE];
  toBytes(object, b, 0);
  return b;
}
 
Example 10
Source File: RawDouble.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public int encodedLength(Double val) {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 11
Source File: RawDouble.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public int skip(PositionedByteRange src) {
  src.setPosition(src.getPosition() + Bytes.SIZEOF_DOUBLE);
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 12
Source File: PhTypeUtil.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public static byte[] toBytes(Object v, PhType phType) {
    if (v == null) return null;
    byte[] b = null;
    if (phType == PhType.DEFAULT) {
        PhType phType1 = PhType.getType(v.getClass());
        if (phType1 != null && phType1 != PhType.DEFAULT) {
            toBytes(v, phType1);
        }
    } else if (phType == PhType.INTEGER) {
        b = new byte[Bytes.SIZEOF_INT];
        encodeInt(((Number) v).intValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_INT) {
        b = new byte[Bytes.SIZEOF_INT];
        encodeUnsignedInt(((Number) v).intValue(), b, 0);
    } else if (phType == PhType.BIGINT) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeLong(((Number) v).longValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_LONG) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeUnsignedLong(((Number) v).longValue(), b, 0);
    } else if (phType == PhType.SMALLINT) {
        b = new byte[Bytes.SIZEOF_SHORT];
        encodeShort(((Number) v).shortValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_SMALLINT) {
        b = new byte[Bytes.SIZEOF_SHORT];
        encodeUnsignedShort(((Number) v).shortValue(), b, 0);
    } else if (phType == PhType.TINYINT) {
        b = new byte[Bytes.SIZEOF_BYTE];
        encodeByte(((Number) v).byteValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_TINYINT) {
        b = new byte[Bytes.SIZEOF_BYTE];
        encodeUnsignedByte(((Number) v).byteValue(), b, 0);
    } else if (phType == PhType.FLOAT) {
        b = new byte[Bytes.SIZEOF_FLOAT];
        encodeFloat(((Number) v).floatValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_FLOAT) {
        b = new byte[Bytes.SIZEOF_FLOAT];
        encodeUnsignedFloat(((Number) v).floatValue(), b, 0);
    } else if (phType == PhType.DOUBLE) {
        b = new byte[Bytes.SIZEOF_DOUBLE];
        encodeDouble(((Number) v).doubleValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_DOUBLE) {
        b = new byte[Bytes.SIZEOF_DOUBLE];
        encodeUnsignedDouble(((Number) v).doubleValue(), b, 0);
    } else if (phType == PhType.BOOLEAN) {
        if ((Boolean) v) {
            b = new byte[] { 1 };
        } else {
            b = new byte[] { 0 };
        }
    } else if (phType == PhType.TIME || phType == PhType.DATE) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeDate(v, b, 0);
    } else if (phType == PhType.TIMESTAMP) {
        b = new byte[Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
        encodeTimestamp(v, b, 0);
    } else if (phType == PhType.UNSIGNED_TIME || phType == PhType.UNSIGNED_DATE) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeUnsignedDate(v, b, 0);
    } else if (phType == PhType.UNSIGNED_TIMESTAMP) {
        b = new byte[Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
        encodeUnsignedTimestamp(v, b, 0);
    } else if (phType == PhType.VARBINARY) {
        b = (byte[]) v;
    } else if (phType == PhType.VARCHAR) {
        b = Bytes.toBytes(v.toString());
    } else if (phType == PhType.DECIMAL) {
        if (v instanceof BigDecimal) {
            b = encodeDecimal(v);
        } else if (v instanceof Number) {
            b = encodeDecimal(new BigDecimal(v.toString()));
        }
    }
    return b;
}
 
Example 13
Source File: PDouble.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 14
Source File: PDouble.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] toBytes(Object object) {
  byte[] b = new byte[Bytes.SIZEOF_DOUBLE];
  toBytes(object, b, 0);
  return b;
}
 
Example 15
Source File: PUnsignedDouble.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
    return Bytes.SIZEOF_DOUBLE;
}
 
Example 16
Source File: PUnsignedDouble.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] toBytes(Object object) {
    byte[] b = new byte[Bytes.SIZEOF_DOUBLE];
    toBytes(object, b, 0);
    return b;
}
 
Example 17
Source File: PDouble.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 18
Source File: DeserializedBooleanComparator.java    From pentaho-hadoop-shims with Apache License 2.0 4 votes vote down vote up
public static Boolean decodeBoolFromNumber( byte[] rawEncoded ) {
  if ( rawEncoded.length == Bytes.SIZEOF_BYTE ) {
    byte val = rawEncoded[ 0 ];
    if ( val == 0 || val == 1 ) {
      return new Boolean( val == 1 );
    }
  }

  if ( rawEncoded.length == Bytes.SIZEOF_SHORT ) {
    short tempShort = Bytes.toShort( rawEncoded );

    if ( tempShort == 0 || tempShort == 1 ) {
      return new Boolean( tempShort == 1 );
    }
  }

  if ( rawEncoded.length == Bytes.SIZEOF_INT || rawEncoded.length == Bytes.SIZEOF_FLOAT ) {
    int tempInt = Bytes.toInt( rawEncoded );
    if ( tempInt == 1 || tempInt == 0 ) {
      return new Boolean( tempInt == 1 );
    }

    float tempFloat = Bytes.toFloat( rawEncoded );
    if ( tempFloat == 0.0f || tempFloat == 1.0f ) {
      return new Boolean( tempFloat == 1.0f );
    }
  }

  if ( rawEncoded.length == Bytes.SIZEOF_LONG || rawEncoded.length == Bytes.SIZEOF_DOUBLE ) {
    long tempLong = Bytes.toLong( rawEncoded );
    if ( tempLong == 0L || tempLong == 1L ) {
      return new Boolean( tempLong == 1L );
    }

    double tempDouble = Bytes.toDouble( rawEncoded );
    if ( tempDouble == 0.0 || tempDouble == 1.0 ) {
      return new Boolean( tempDouble == 1.0 );
    }
  }

  // not identifiable from a number
  return null;
}
 
Example 19
Source File: CommonHBaseBytesUtil.java    From pentaho-hadoop-shims with Apache License 2.0 4 votes vote down vote up
public int getSizeOfDouble() {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 20
Source File: PhTypeUtil.java    From canal with Apache License 2.0 4 votes vote down vote up
public static byte[] toBytes(Object v, PhType phType) {
    if (v == null) return null;
    byte[] b = null;
    if (phType == PhType.DEFAULT) {
        PhType phType1 = PhType.getType(v.getClass());
        if (phType1 != null && phType1 != PhType.DEFAULT) {
            toBytes(v, phType1);
        }
    } else if (phType == PhType.INTEGER) {
        b = new byte[Bytes.SIZEOF_INT];
        encodeInt(((Number) v).intValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_INT) {
        b = new byte[Bytes.SIZEOF_INT];
        encodeUnsignedInt(((Number) v).intValue(), b, 0);
    } else if (phType == PhType.BIGINT) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeLong(((Number) v).longValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_LONG) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeUnsignedLong(((Number) v).longValue(), b, 0);
    } else if (phType == PhType.SMALLINT) {
        b = new byte[Bytes.SIZEOF_SHORT];
        encodeShort(((Number) v).shortValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_SMALLINT) {
        b = new byte[Bytes.SIZEOF_SHORT];
        encodeUnsignedShort(((Number) v).shortValue(), b, 0);
    } else if (phType == PhType.TINYINT) {
        b = new byte[Bytes.SIZEOF_BYTE];
        encodeByte(((Number) v).byteValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_TINYINT) {
        b = new byte[Bytes.SIZEOF_BYTE];
        encodeUnsignedByte(((Number) v).byteValue(), b, 0);
    } else if (phType == PhType.FLOAT) {
        b = new byte[Bytes.SIZEOF_FLOAT];
        encodeFloat(((Number) v).floatValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_FLOAT) {
        b = new byte[Bytes.SIZEOF_FLOAT];
        encodeUnsignedFloat(((Number) v).floatValue(), b, 0);
    } else if (phType == PhType.DOUBLE) {
        b = new byte[Bytes.SIZEOF_DOUBLE];
        encodeDouble(((Number) v).doubleValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_DOUBLE) {
        b = new byte[Bytes.SIZEOF_DOUBLE];
        encodeUnsignedDouble(((Number) v).doubleValue(), b, 0);
    } else if (phType == PhType.BOOLEAN) {
        if ((Boolean) v) {
            b = new byte[] { 1 };
        } else {
            b = new byte[] { 0 };
        }
    } else if (phType == PhType.TIME || phType == PhType.DATE) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeDate(v, b, 0);
    } else if (phType == PhType.TIMESTAMP) {
        b = new byte[Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
        encodeTimestamp(v, b, 0);
    } else if (phType == PhType.UNSIGNED_TIME || phType == PhType.UNSIGNED_DATE) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeUnsignedDate(v, b, 0);
    } else if (phType == PhType.UNSIGNED_TIMESTAMP) {
        b = new byte[Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
        encodeUnsignedTimestamp(v, b, 0);
    } else if (phType == PhType.VARBINARY) {
        b = (byte[]) v;
    } else if (phType == PhType.VARCHAR) {
        b = Bytes.toBytes(v.toString());
    } else if (phType == PhType.DECIMAL) {
        if (v instanceof BigDecimal) {
            b = encodeDecimal(v);
        } else if (v instanceof Number) {
            b = encodeDecimal(new BigDecimal(v.toString()));
        }
    }
    return b;
}