Example usage for org.apache.cassandra.utils UUIDGen decompose

List of usage examples for org.apache.cassandra.utils UUIDGen decompose

Introduction

In this page you can find the example usage for org.apache.cassandra.utils UUIDGen decompose.

Prototype

public static byte[] decompose(UUID uuid) 

Source Link

Document

decomposes a uuid into raw bytes.

Usage

From source file:com.dse.pig.udfs.AbstractCassandraStorage.java

License:Apache License

/** convert object to ByteBuffer */
protected ByteBuffer objToBB(Object o) {
    if (o == null)
        return nullToBB();
    if (o instanceof java.lang.String)
        return ByteBuffer.wrap(new DataByteArray((String) o).get());
    if (o instanceof Integer)
        return Int32Type.instance.decompose((Integer) o);
    if (o instanceof Long)
        return LongType.instance.decompose((Long) o);
    if (o instanceof Float)
        return FloatType.instance.decompose((Float) o);
    if (o instanceof Double)
        return DoubleType.instance.decompose((Double) o);
    if (o instanceof java.util.UUID)
        //           return ByteBuffer.wrap(((UUID) o).toString().getBytes());
        return ByteBuffer.wrap(UUIDGen.decompose((java.util.UUID) o));
    if (o instanceof Tuple) {
        List<Object> objects = ((Tuple) o).getAll();
        //collections
        if (objects.size() > 0 && objects.get(0) instanceof String) {
            String collectionType = (String) objects.get(0);
            if ("set".equalsIgnoreCase(collectionType) || "list".equalsIgnoreCase(collectionType))
                return objToListOrSetBB(objects.subList(1, objects.size()));
            else if ("map".equalsIgnoreCase(collectionType))
                return objToMapBB(objects.subList(1, objects.size()));

        }/*from www.  j  av a2 s.  c  o m*/
        return objToCompositeBB(objects);
    }

    return ByteBuffer.wrap(((DataByteArray) o).get());
}

From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java

License:Apache License

/**
 * Used to convert value (function argument, string) into byte[]
 * @param functionCall - tree representing function call ^(FUNCTION_CALL function_name value)
 * @param columnFamily - column family definition (CfDef)
 * @param columnName   - column name as byte[] (used to update CfDef)
 * @param withUpdate   - also updates column family metadata for given column
 * @return byte[] - string value as byte[]
 *///from  www . j  a v  a2  s .c  o m
private ByteBuffer convertValueByFunction(Tree functionCall, CfDef columnFamily, ByteBuffer columnName,
        boolean withUpdate) {
    String functionName = functionCall.getChild(0).getText();
    Tree argumentTree = functionCall.getChild(1);
    String functionArg = (argumentTree == null) ? "" : CliUtils.unescapeSQLString(argumentTree.getText());
    AbstractType<?> validator = getTypeByFunction(functionName);

    try {

        ByteBuffer value;

        if (functionArg.isEmpty()) {
            if (validator instanceof TimeUUIDType) {
                value = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes());
            } else if (validator instanceof LexicalUUIDType) {
                value = ByteBuffer.wrap(UUIDGen.decompose(UUID.randomUUID()));
            } else if (validator instanceof BytesType) {
                value = ByteBuffer.wrap(new byte[0]);
            } else {
                throw new RuntimeException(
                        String.format("Argument for '%s' could not be empty.", functionName));
            }
        } else {
            value = getBytesAccordingToType(functionArg, validator);
        }

        // performing ColumnDef local validator update
        if (withUpdate) {
            updateColumnMetaData(columnFamily, columnName, validator.toString());
        }

        return value;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.hadoop.hive.cassandra.ql.udf.UDFUuid.java

License:Apache License

public BytesWritable evaluate(Text text) {
    return new BytesWritable(UUIDGen.decompose(UUID.fromString(new String(text.getBytes()))));
}

From source file:org.apache.lucene.cassandra.fs.CassandraFileSystemThriftStore.java

License:Apache License

/**
 * {@inheritDoc}/*w  w w . j  a  va 2 s  . c om*/
 */
public void deleteSubBlocks(INode inode) throws IOException {
    // Get all the SubBlock keys to delete.
    List<UUID> subBlockKeys = getListOfBlockIds(inode.getBlocks());
    try {
        // TODO (patricioe) can we send one big batch mutation here ?
        for (UUID subBlocksKey : subBlockKeys) {
            client.remove(ByteBuffer.wrap(UUIDGen.decompose(subBlocksKey)), sblockPath,
                    System.currentTimeMillis(), consistencyLevelWrite);
        }
    } catch (Exception e) {
        throw new IOException(e);
    }
}