Java Code Examples for org.apache.cassandra.utils.ByteBufferUtil#toLong()

The following examples show how to use org.apache.cassandra.utils.ByteBufferUtil#toLong() . 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: TimestampToLongCodec.java    From cassandra-jdbc-wrapper with Apache License 2.0 5 votes vote down vote up
@Override
public Long deserialize(ByteBuffer paramByteBuffer, ProtocolVersion paramProtocolVersion) throws InvalidTypeException {
	if (paramByteBuffer == null) {
		return null;

	}
	// always duplicate the ByteBuffer instance before consuming it!
	return ByteBufferUtil.toLong(paramByteBuffer.duplicate());
}
 
Example 2
Source File: BigDecimalToBigintCodec.java    From cassandra-jdbc-wrapper with Apache License 2.0 5 votes vote down vote up
@Override
public BigDecimal deserialize(ByteBuffer paramByteBuffer, ProtocolVersion paramProtocolVersion) throws InvalidTypeException {
	if (paramByteBuffer == null) {
		return null;

	}
	// always duplicate the ByteBuffer instance before consuming it!
	Long value = ByteBufferUtil.toLong(paramByteBuffer.duplicate());
	return new BigDecimal(value);
}
 
Example 3
Source File: LongToIntCodec.java    From cassandra-jdbc-wrapper with Apache License 2.0 5 votes vote down vote up
@Override
public Integer deserialize(ByteBuffer paramByteBuffer, ProtocolVersion paramProtocolVersion) throws InvalidTypeException {
	if (paramByteBuffer == null) {
		return null;

	}
	// always duplicate the ByteBuffer instance before consuming it!
	Long value = ByteBufferUtil.toLong(paramByteBuffer.duplicate());
	return value.intValue();
}
 
Example 4
Source File: IntToLongCodec.java    From cassandra-jdbc-wrapper with Apache License 2.0 5 votes vote down vote up
@Override
public Long deserialize(ByteBuffer paramByteBuffer, ProtocolVersion paramProtocolVersion) throws InvalidTypeException {
	if (paramByteBuffer == null) {
		return null;

	}
	// always duplicate the ByteBuffer instance before consuming it!
	return ByteBufferUtil.toLong(paramByteBuffer.duplicate());
}
 
Example 5
Source File: WordCountCounters.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void map(ByteBuffer key, SortedMap<ByteBuffer, Cell> columns, Context context) throws IOException, InterruptedException
{
    long sum = 0;
    for (Cell cell : columns.values())
    {
        logger.debug("read " + key + ":" + cell.name() + " from " + context.getInputSplit());
        sum += ByteBufferUtil.toLong(cell.value());
    }
    context.write(new Text(ByteBufferUtil.string(key)), new LongWritable(sum));
}
 
Example 6
Source File: WordCountSetup.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static void setupKeyspace(Cassandra.Iface client)  
        throws InvalidRequestException, 
        UnavailableException, 
        TimedOutException, 
        SchemaDisagreementException, 
        TException
{
    KsDef ks;
    try
    {
        ks = client.describe_keyspace(WordCount.KEYSPACE);
    }
    catch(NotFoundException e)
    {
        logger.info("set up keyspace " + WordCount.KEYSPACE);
        String query = "CREATE KEYSPACE " + WordCount.KEYSPACE +
                          " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"; 

        client.execute_cql3_query(ByteBufferUtil.bytes(query), Compression.NONE, ConsistencyLevel.ONE);

        String verifyQuery = "select count(*) from system.peers";
        CqlResult result = client.execute_cql3_query(ByteBufferUtil.bytes(verifyQuery), Compression.NONE, ConsistencyLevel.ONE);

        long magnitude = ByteBufferUtil.toLong(result.rows.get(0).columns.get(0).value);
        try
        {
            Thread.sleep(1000 * magnitude);
        }
        catch (InterruptedException ie)
        {
            throw new RuntimeException(ie);
        }
    }
}
 
Example 7
Source File: Constants.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException
{
    ByteBuffer bytes = t.bindAndGet(params.options);
    if (bytes == null)
        throw new InvalidRequestException("Invalid null value for counter increment");
    long increment = ByteBufferUtil.toLong(bytes);
    CellName cname = cf.getComparator().create(prefix, column);
    cf.addColumn(params.makeCounter(cname, increment));
}
 
Example 8
Source File: Constants.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException
{
    ByteBuffer bytes = t.bindAndGet(params.options);
    if (bytes == null)
        throw new InvalidRequestException("Invalid null value for counter increment");

    long increment = ByteBufferUtil.toLong(bytes);
    if (increment == Long.MIN_VALUE)
        throw new InvalidRequestException("The negation of " + increment + " overflows supported counter precision (signed 8 bytes integer)");

    CellName cname = cf.getComparator().create(prefix, column);
    cf.addColumn(params.makeCounter(cname, -increment));
}
 
Example 9
Source File: Murmur3Partitioner.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public Token fromByteArray(ByteBuffer bytes)
{
    return new LongToken(ByteBufferUtil.toLong(bytes));
}
 
Example 10
Source File: LongSerializer.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public Long deserialize(ByteBuffer bytes)
{
    return bytes.remaining() == 0 ? null : ByteBufferUtil.toLong(bytes);
}
 
Example 11
Source File: TimestampSerializer.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public Date deserialize(ByteBuffer bytes)
{
    return bytes.remaining() == 0 ? null : new Date(ByteBufferUtil.toLong(bytes));
}