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 . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: canal-1.1.3   File: PhTypeUtil.java    License: 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 2
Source Project: phoenix   File: PUnsignedDouble.java    License: 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 3
Source Project: hbase   File: DoubleColumnInterpreter.java    License: 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 4
Source Project: spork   File: HBaseBinaryConverter.java    License: 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 5
Source Project: phoenix   File: PUnsignedDouble.java    License: 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 Project: canal   File: PhTypeUtil.java    License: 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 Project: canal-1.1.3   File: PhTypeUtil.java    License: 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 8
Source Project: phoenix   File: PDouble.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 9
Source Project: phoenix   File: PDouble.java    License: 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 Project: phoenix   File: PUnsignedDouble.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 11
Source Project: phoenix   File: PUnsignedDouble.java    License: 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 12
Source Project: hbase   File: RawDouble.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int encodedLength(Double val) {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 13
Source Project: hbase   File: RawDouble.java    License: 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 14
Source Project: phoenix   File: PDouble.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 15
Source Project: phoenix   File: PDouble.java    License: 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 16
Source Project: phoenix   File: PUnsignedDouble.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
    return Bytes.SIZEOF_DOUBLE;
}
 
Example 17
Source Project: phoenix   File: PUnsignedDouble.java    License: 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 18
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
public int getSizeOfDouble() {
  return Bytes.SIZEOF_DOUBLE;
}
 
Example 20
Source Project: canal   File: PhTypeUtil.java    License: 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;
}