Search in sources :

Example 31 with DataInputBuffer

use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.

the class LocalSessions method deserializeRange.

private static Range<Token> deserializeRange(ByteBuffer bb) {
    try (DataInputBuffer in = new DataInputBuffer(bb, false)) {
        IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
        Token left = Token.serializer.deserialize(in, partitioner, 0);
        Token right = Token.serializer.deserialize(in, partitioner, 0);
        return new Range<>(left, right);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) Token(org.apache.cassandra.dht.Token) IOException(java.io.IOException) Range(org.apache.cassandra.dht.Range) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 32 with DataInputBuffer

use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.

the class ColumnFilterTest method testRoundTrip.

private void testRoundTrip(ColumnFilter columnFilter, int version) {
    try {
        DataOutputBuffer output = new DataOutputBuffer();
        serializer.serialize(columnFilter, output, version);
        Assert.assertEquals(serializer.serializedSize(columnFilter, version), output.position());
        DataInputPlus input = new DataInputBuffer(output.buffer(), false);
        ColumnFilter deserialized = serializer.deserialize(input, version, metadata);
        if (version == MessagingService.VERSION_30 && columnFilter.fetchesAllColumns(false)) {
            Assert.assertEquals(metadata.regularAndStaticColumns(), deserialized.fetchedColumns());
        } else {
            Assert.assertEquals(deserialized, columnFilter);
        }
    } catch (IOException e) {
        throw Throwables.cleaned(e);
    }
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) IOException(java.io.IOException)

Example 33 with DataInputBuffer

use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.

the class StandardAnalyzer method init.

public void init(StandardTokenizerOptions tokenizerOptions, AbstractType<?> validator) {
    this.validator = validator;
    this.options = tokenizerOptions;
    this.filterPipeline = getFilterPipeline();
    Reader reader = new InputStreamReader(new DataInputBuffer(ByteBufferUtil.EMPTY_BYTE_BUFFER, false), StandardCharsets.UTF_8);
    this.scanner = new StandardTokenizerImpl(reader);
    this.inputReader = reader;
}
Also used : DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Example 34 with DataInputBuffer

use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.

the class MutationBench method setup.

@Setup
public void setup() throws IOException {
    Schema.instance.load(KeyspaceMetadata.create(keyspace, KeyspaceParams.simple(1)));
    KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace);
    TableMetadata metadata = CreateTableStatement.parse("CREATE TABLE userpics " + "( userid bigint," + "picid bigint," + "commentid bigint, " + "PRIMARY KEY(userid, picid))", keyspace).build();
    Schema.instance.load(ksm.withSwapped(ksm.tables.with(metadata)));
    mutation = (Mutation) UpdateBuilder.create(metadata, 1L).newRow(1L).add("commentid", 32L).makeMutation();
    buffer = ByteBuffer.allocate(mutation.serializedSize(MessagingService.current_version));
    outputBuffer = new DataOutputBufferFixed(buffer);
    inputBuffer = new DataInputBuffer(buffer, false);
    Mutation.serializer.serialize(mutation, outputBuffer, MessagingService.current_version);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) DataOutputBufferFixed(org.apache.cassandra.io.util.DataOutputBufferFixed)

Example 35 with DataInputBuffer

use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.

the class ReadCommandTest method testSinglePartitionGroupMerge.

@Test
public void testSinglePartitionGroupMerge() throws Exception {
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore(CF3);
    String[][][] groups = new String[][][] { new String[][] { // "1" indicates to create the data, "-1" to delete the row
    new String[] { "1", "key1", "aa", "a" }, new String[] { "1", "key2", "bb", "b" }, new String[] { "1", "key3", "cc", "c" } }, new String[][] { new String[] { "1", "key3", "dd", "d" }, new String[] { "1", "key2", "ee", "e" }, new String[] { "1", "key1", "ff", "f" } }, new String[][] { new String[] { "1", "key6", "aa", "a" }, new String[] { "1", "key5", "bb", "b" }, new String[] { "1", "key4", "cc", "c" } }, new String[][] { new String[] { "-1", "key6", "aa", "a" }, new String[] { "-1", "key2", "bb", "b" } } };
    // Given the data above, when the keys are sorted and the deletions removed, we should
    // get these clustering rows in this order
    String[] expectedRows = new String[] { "aa", "ff", "ee", "cc", "dd", "cc", "bb" };
    List<ByteBuffer> buffers = new ArrayList<>(groups.length);
    int nowInSeconds = FBUtilities.nowInSeconds();
    ColumnFilter columnFilter = ColumnFilter.allRegularColumnsBuilder(cfs.metadata(), false).build();
    RowFilter rowFilter = RowFilter.create();
    Slice slice = Slice.make(BufferClusteringBound.BOTTOM, BufferClusteringBound.TOP);
    ClusteringIndexSliceFilter sliceFilter = new ClusteringIndexSliceFilter(Slices.with(cfs.metadata().comparator, slice), false);
    for (String[][] group : groups) {
        cfs.truncateBlocking();
        List<SinglePartitionReadCommand> commands = new ArrayList<>(group.length);
        for (String[] data : group) {
            if (data[0].equals("1")) {
                new RowUpdateBuilder(cfs.metadata(), 0, ByteBufferUtil.bytes(data[1])).clustering(data[2]).add(data[3], ByteBufferUtil.bytes("blah")).build().apply();
            } else {
                RowUpdateBuilder.deleteRow(cfs.metadata(), FBUtilities.timestampMicros(), ByteBufferUtil.bytes(data[1]), data[2]).apply();
            }
            commands.add(SinglePartitionReadCommand.create(cfs.metadata(), nowInSeconds, columnFilter, rowFilter, DataLimits.NONE, Util.dk(data[1]), sliceFilter));
        }
        cfs.forceBlockingFlush();
        ReadQuery query = SinglePartitionReadCommand.Group.create(commands, DataLimits.NONE);
        try (ReadExecutionController executionController = query.executionController();
            UnfilteredPartitionIterator iter = query.executeLocally(executionController);
            DataOutputBuffer buffer = new DataOutputBuffer()) {
            UnfilteredPartitionIterators.serializerForIntraNode().serialize(iter, columnFilter, buffer, MessagingService.current_version);
            buffers.add(buffer.buffer());
        }
    }
    // deserialize, merge and check the results are all there
    List<UnfilteredPartitionIterator> iterators = new ArrayList<>();
    for (ByteBuffer buffer : buffers) {
        try (DataInputBuffer in = new DataInputBuffer(buffer, true)) {
            iterators.add(UnfilteredPartitionIterators.serializerForIntraNode().deserialize(in, MessagingService.current_version, cfs.metadata(), columnFilter, DeserializationHelper.Flag.LOCAL));
        }
    }
    UnfilteredPartitionIterators.MergeListener listener = new UnfilteredPartitionIterators.MergeListener() {

        public UnfilteredRowIterators.MergeListener getRowMergeListener(DecoratedKey partitionKey, List<UnfilteredRowIterator> versions) {
            return null;
        }

        public void close() {
        }
    };
    try (PartitionIterator partitionIterator = UnfilteredPartitionIterators.filter(UnfilteredPartitionIterators.merge(iterators, listener), nowInSeconds)) {
        int i = 0;
        int numPartitions = 0;
        while (partitionIterator.hasNext()) {
            numPartitions++;
            try (RowIterator rowIterator = partitionIterator.next()) {
                while (rowIterator.hasNext()) {
                    Row row = rowIterator.next();
                    assertEquals("col=" + expectedRows[i++], row.clustering().toString(cfs.metadata()));
                // System.out.print(row.toString(cfs.metadata, true));
                }
            }
        }
        assertEquals(5, numPartitions);
        assertEquals(expectedRows.length, i);
    }
}
Also used : ClusteringIndexSliceFilter(org.apache.cassandra.db.filter.ClusteringIndexSliceFilter) RowFilter(org.apache.cassandra.db.filter.RowFilter) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) UnfilteredRowIterators(org.apache.cassandra.db.rows.UnfilteredRowIterators) ColumnFilter(org.apache.cassandra.db.filter.ColumnFilter) ByteBuffer(java.nio.ByteBuffer) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) RowIterator(org.apache.cassandra.db.rows.RowIterator) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) Row(org.apache.cassandra.db.rows.Row) Test(org.junit.Test)

Aggregations

DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)54 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)33 Test (org.junit.Test)23 IOException (java.io.IOException)14 ByteBuffer (java.nio.ByteBuffer)13 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)13 TableMetadata (org.apache.cassandra.schema.TableMetadata)6 Mutation (org.apache.cassandra.db.Mutation)5 UUID (java.util.UUID)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 DataOutputPlus (org.apache.cassandra.io.util.DataOutputPlus)4 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)4 InputStreamReader (java.io.InputStreamReader)3 Reader (java.io.Reader)3 ArrayList (java.util.ArrayList)3 DataOutputBufferFixed (org.apache.cassandra.io.util.DataOutputBufferFixed)3 ByteBuf (io.netty.buffer.ByteBuf)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ClusteringIndexSliceFilter (org.apache.cassandra.db.filter.ClusteringIndexSliceFilter)2