Example usage for org.apache.cassandra.db.marshal BytesType instance

List of usage examples for org.apache.cassandra.db.marshal BytesType instance

Introduction

In this page you can find the example usage for org.apache.cassandra.db.marshal BytesType instance.

Prototype

BytesType instance

To view the source code for org.apache.cassandra.db.marshal BytesType instance.

Click Source Link

Usage

From source file:clojurewerkz.cassaforte.Codec.java

License:Apache License

private static AbstractType getCodecInternal(DataType type) {
    switch (type.getName()) {
    case ASCII:/*from  w  w w  .  j  a v a 2  s.  c  o  m*/
        return AsciiType.instance;
    case BIGINT:
        return LongType.instance;
    case BLOB:
        return BytesType.instance;
    case BOOLEAN:
        return BooleanType.instance;
    case COUNTER:
        return CounterColumnType.instance;
    case DECIMAL:
        return DecimalType.instance;
    case DOUBLE:
        return DoubleType.instance;
    case FLOAT:
        return FloatType.instance;
    case INET:
        return InetAddressType.instance;
    case INT:
        return Int32Type.instance;
    case TEXT:
        return UTF8Type.instance;
    case TIMESTAMP:
        return DateType.instance;
    case UUID:
        return UUIDType.instance;
    case VARCHAR:
        return UTF8Type.instance;
    case VARINT:
        return IntegerType.instance;
    case TIMEUUID:
        return TimeUUIDType.instance;
    case LIST:
        return ListType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case SET:
        return SetType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case MAP:
        return MapType.getInstance(getCodec(type.getTypeArguments().get(0)),
                getCodec(type.getTypeArguments().get(1)));
    default:
        throw new RuntimeException("Unknown type");
    }
}

From source file:com.chaordicsystems.sstableconverter.SSTableConverter.java

License:Apache License

public static void main(String[] args) throws Exception {
    LoaderOptions options = LoaderOptions.parseArgs(args);
    OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);

    File srcDir = options.sourceDir;
    File dstDir = options.destDir;
    IPartitioner srcPart = options.srcPartitioner;
    IPartitioner dstPart = options.dstPartitioner;
    String keyspace = options.ks;
    String cf = options.cf;//www  . j a  v a 2  s.co  m

    if (keyspace == null) {
        keyspace = srcDir.getParentFile().getName();
    }
    if (cf == null) {
        cf = srcDir.getName();
    }

    CFMetaData metadata = new CFMetaData(keyspace, cf, ColumnFamilyType.Standard, BytesType.instance, null);
    Collection<SSTableReader> originalSstables = readSSTables(srcPart, srcDir, metadata, handler);

    handler.output(
            String.format("Converting sstables of ks[%s], cf[%s], from %s to %s. Src dir: %s. Dest dir: %s.",
                    keyspace, cf, srcPart.getClass().getName(), dstPart.getClass().getName(),
                    srcDir.getAbsolutePath(), dstDir.getAbsolutePath()));

    SSTableSimpleUnsortedWriter destWriter = new SSTableSimpleUnsortedWriter(dstDir, dstPart, keyspace, cf,
            AsciiType.instance, null, 64);

    for (SSTableReader reader : originalSstables) {
        handler.output("Reading: " + reader.getFilename());
        SSTableIdentityIterator row;
        SSTableScanner scanner = reader.getDirectScanner(null);

        // collecting keys to export
        while (scanner.hasNext()) {
            row = (SSTableIdentityIterator) scanner.next();

            destWriter.newRow(row.getKey().key);
            while (row.hasNext()) {
                IColumn col = (IColumn) row.next();
                destWriter.addColumn(col.name(), col.value(), col.timestamp());
            }
        }
        scanner.close();
    }

    // Don't forget to close!
    destWriter.close();

    System.exit(0);
}

From source file:com.datastax.driver.core.Codec.java

License:Apache License

private static AbstractType<?> getCodecInternal(DataType type) {
    switch (type.getName()) {
    case ASCII://from   ww  w . j  a  va2 s. c  om
        return AsciiType.instance;
    case BIGINT:
        return LongType.instance;
    case BLOB:
        return BytesType.instance;
    case BOOLEAN:
        return BooleanType.instance;
    case COUNTER:
        return CounterColumnType.instance;
    case DECIMAL:
        return DecimalType.instance;
    case DOUBLE:
        return DoubleType.instance;
    case FLOAT:
        return FloatType.instance;
    case INET:
        return InetAddressType.instance;
    case INT:
        return Int32Type.instance;
    case TEXT:
        return UTF8Type.instance;
    case TIMESTAMP:
        return DateType.instance;
    case UUID:
        return UUIDType.instance;
    case VARCHAR:
        return UTF8Type.instance;
    case VARINT:
        return IntegerType.instance;
    case TIMEUUID:
        return TimeUUIDType.instance;
    case LIST:
        return ListType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case SET:
        return SetType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case MAP:
        return MapType.getInstance(getCodec(type.getTypeArguments().get(0)),
                getCodec(type.getTypeArguments().get(1)));
    // We don't interpret custom values in any way
    case CUSTOM:
        return BytesType.instance;
    default:
        throw new RuntimeException("Unknown type");
    }
}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

License:Apache License

/**
 * @param value//from www. java2 s  . c o m
 * @param f
 * @return
 */
public static ByteBuffer toBytes(Object value, Class<?> clazz) {
    if (clazz.isAssignableFrom(String.class)) {
        return UTF8Type.instance.decompose((String) value);
    } else if (clazz.equals(int.class) || clazz.isAssignableFrom(Integer.class)) {
        return Int32Type.instance.decompose(Integer.parseInt(value.toString()));
    } else if (clazz.equals(long.class) || clazz.isAssignableFrom(Long.class)) {
        return LongType.instance.decompose(Long.parseLong(value.toString()));
    } else if (clazz.equals(boolean.class) || clazz.isAssignableFrom(Boolean.class)) {
        return BooleanType.instance.decompose(Boolean.valueOf(value.toString()));
    } else if (clazz.equals(double.class) || clazz.isAssignableFrom(Double.class)) {
        return DoubleType.instance.decompose(Double.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(java.util.UUID.class)) {
        return UUIDType.instance.decompose(UUID.fromString(value.toString()));
    } else if (clazz.equals(float.class) || clazz.isAssignableFrom(Float.class)) {
        return FloatType.instance.decompose(Float.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(Date.class)) {
        DateAccessor dateAccessor = new DateAccessor();
        return DateType.instance.decompose((Date) value);
    } else {
        if (value.getClass().isAssignableFrom(String.class)) {
            value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString());
        }
        return BytesType.instance
                .decompose(ByteBuffer.wrap(PropertyAccessorFactory.getPropertyAccessor(clazz).toBytes(value)));
    }
}

From source file:com.knewton.mapreduce.example.StudentEventMapperTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    underTest = new StudentEventMapper();
    conf = new Configuration(false);
    Counter mockCounter = mock(Counter.class);
    when(mockedContext.getConfiguration()).thenReturn(conf);
    when(mockedContext.getCounter(anyString(), anyString())).thenReturn(mockCounter);
    this.simpleDenseCellType = new SimpleDenseCellNameType(BytesType.instance);
}

From source file:com.knewton.mapreduce.SSTableCellMapperTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    this.underTest = new DoNothingColumnMapper();
    this.keyVal = "testKey";
    this.columnNameVal = "testColumnName";
    this.columnValue = "testColumnValue";
    this.simpleDenseCellType = new SimpleDenseCellNameType(BytesType.instance);
}

From source file:com.knewton.mapreduce.SSTableColumnRecordReaderTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    conf = new Configuration();
    attemptId = new TaskAttemptID();
    Path inputPath = new Path(TABLE_PATH_STR);
    inputSplit = new FileSplit(inputPath, 0, 1, null);
    Descriptor desc = new Descriptor(new File(TABLE_PATH_STR), "keyspace", "columnFamily", 1, Type.FINAL);

    doReturn(desc).when(ssTableColumnRecordReader).getDescriptor();

    doNothing().when(ssTableColumnRecordReader).copyTablesToLocal(any(FileSystem.class), any(FileSystem.class),
            any(Path.class), any(TaskAttemptContext.class));

    doReturn(ssTableReader).when(ssTableColumnRecordReader).openSSTableReader(any(IPartitioner.class),
            any(CFMetaData.class));

    when(ssTableReader.estimatedKeys()).thenReturn(2L);
    when(ssTableReader.getScanner()).thenReturn(tableScanner);

    when(tableScanner.hasNext()).thenReturn(true, true, false);

    key = new BufferDecoratedKey(new StringToken("a"), ByteBuffer.wrap("b".getBytes()));
    CellNameType simpleDenseCellType = new SimpleDenseCellNameType(BytesType.instance);
    CellName cellName = simpleDenseCellType.cellFromByteBuffer(ByteBuffer.wrap("n".getBytes()));
    ByteBuffer counterBB = CounterContext.instance().createGlobal(CounterId.fromInt(0),
            System.currentTimeMillis(), 123L);
    value = BufferCounterCell.create(cellName, counterBB, System.currentTimeMillis(), 0L, Flag.PRESERVE_SIZE);

    SSTableIdentityIterator row1 = getNewRow();
    SSTableIdentityIterator row2 = getNewRow();

    when(tableScanner.next()).thenReturn(row1, row2);
}

From source file:com.netflix.aegisthus.io.commitlog.CommitLogScanner.java

License:Apache License

@SuppressWarnings("unused")
public String next(int filter) {
    int serializedSize;
    if (cache.size() > 0) {
        // if we are here we are reading rows that we already reported the
        // size of.
        datasize = 0;//from w w  w  .ja  v a  2 s . c  o m
        return cache.remove(0);
    }
    try {
        outer: while (true) {
            serializedSize = input.readInt();
            if (serializedSize == 0) {
                return null;
            }
            long claimedSizeChecksum = input.readLong();
            byte[] buffer = new byte[(int) (serializedSize * 1.2)];
            input.readFully(buffer, 0, serializedSize);
            long claimedChecksum = input.readLong();

            // two checksums plus the int for the size
            datasize = serializedSize + 8 + 8 + 4;

            FastByteArrayInputStream bufIn = new FastByteArrayInputStream(buffer, 0, serializedSize);
            DataInput ris = new DataInputStream(bufIn);
            String table = ris.readUTF();
            ByteBuffer key = ByteBufferUtil.readWithShortLength(ris);
            Map<Integer, ColumnFamily> modifications = new HashMap<Integer, ColumnFamily>();
            int size = ris.readInt();
            for (int i = 0; i < size; ++i) {
                Integer cfid = Integer.valueOf(ris.readInt());
                if (filter >= 0 && cfid != filter) {
                    continue outer;
                }
                if (!ris.readBoolean()) {
                    continue;
                }
                cfid = Integer.valueOf(ris.readInt());
                int localDeletionTime = ris.readInt();
                long markedForDeleteAt = ris.readLong();
                sb = new StringBuilder();
                sb.append("{");
                insertKey(sb, BytesType.instance.getString(key));
                sb.append("{");
                insertKey(sb, "deletedAt");
                sb.append(markedForDeleteAt);
                sb.append(", ");
                insertKey(sb, "columns");
                sb.append("[");
                int columns = ris.readInt();
                serializeColumns(sb, columns, ris);
                sb.append("]");
                sb.append("}}");
                cache.add(sb.toString());
            }
            if (cache.size() > 0) {
                return cache.remove(0);
            } else {
                return null;
            }
        }
    } catch (Exception e) {
        throw new IOError(e);
    }
}

From source file:com.netflix.aegisthus.io.sstable.IndexScanner.java

License:Apache License

@Override
public Pair<String, Long> next() {
    try {//from w w  w  .  j ava2  s  .  c  o m
        String key = BytesType.instance.getString(ByteBufferUtil.readWithShortLength(input));
        Long offset = input.readLong();
        if (version.hasPromotedIndexes) {
            skipPromotedIndexes();
        }
        return Pair.create(key, offset);
    } catch (IOException e) {
        throw new IOError(e);
    }

}

From source file:com.netflix.aegisthus.io.sstable.SSTableColumnScanner.java

License:Apache License

private String keyToString(byte[] rowKey) {
    if (rowKey == null) {
        return "null";
    }/*from ww w  . j ava  2  s  . co  m*/

    String str = BytesType.instance.getString(ByteBuffer.wrap(rowKey));
    return StringUtils.left(str, 32);
}