public class SimpleLoadExample
{
    /** Default output directory */
    public static final String DEFAULT_OUTPUT_DIR = "/home/tamil/bdata";

    public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    /** Keyspace name */
    public static final String KEYSPACE = "test";
    /** Table name */
    public static final String TABLE = "counter";

    public static final String SCHEMA = "CREATE TABLE test.counter (" +
            "id varchar PRIMARY KEY," +
            "count counter" +
            ")";

    public static void main(String[] args) throws InvalidRequestException, IOException {
        Config.setClientMode(true);
        File outputDir = new File(DEFAULT_OUTPUT_DIR + File.separator + KEYSPACE + File.separator + TABLE);
        if (!outputDir.exists() && !outputDir.mkdirs())
        {
            throw new RuntimeException("Cannot create output directory: " + outputDir);
        }
        SSTableSimpleUnsortedWriter writer = new SSTableSimpleUnsortedWriter(outputDir, new Murmur3Partitioner(), KEYSPACE, TABLE, CounterColumnType.instance, null, 1000);
        writer.newRow(bytes("2"));
        writer.addCounterColumn(bytes("count"), 10L);
        try
        {
            writer.close();
        }
        catch (IOException ignore) {
            System.out.println(ignore);
        }
    }
}


我尝试了上面的简单示例来生成sstables。但

ERROR 21:05:14,287 Missing component: /home/tamil/bdata/test/counter/test-counter-jb-1-Summary.db
    [
    {"key": "32","columns": [Exception in thread "main" java.lang.IllegalArgumentException
        at java.nio.Buffer.limit(Buffer.java:267)
        at org.apache.cassandra.utils.ByteBufferUtil.readBytes(ByteBufferUtil.java:587)
        at org.apache.cassandra.utils.ByteBufferUtil.readBytesWithShortLength(ByteBufferUtil.java:596)
        at org.apache.cassandra.db.marshal.AbstractCompositeType.getString(AbstractCompositeType.java:203)
        at org.apache.cassandra.tools.SSTableExport.serializeColumn(SSTableExport.java:183)
        at org.apache.cassandra.tools.SSTableExport.serializeAtom(SSTableExport.java:152)
        at org.apache.cassandra.tools.SSTableExport.serializeAtoms(SSTableExport.java:140)
        at org.apache.cassandra.tools.SSTableExport.serializeRow(SSTableExport.java:238)
        at org.apache.cassandra.tools.SSTableExport.serializeRow(SSTableExport.java:223)
        at org.apache.cassandra.tools.SSTableExport.export(SSTableExport.java:374)
        at org.apache.cassandra.tools.SSTableExport.export(SSTableExport.java:399)
        at org.apache.cassandra.tools.SSTableExport.export(SSTableExport.java:411)
        at org.apache.cassandra.tools.SSTableExport.main(SSTableExport.java:494)


有人可以指出我哪里出问题了吗?

This是我在网络上可以找到的。但是我认为我的比较器[尝试了UTF8Type和CounterColumn都很好]。还有什么可能导致此缓冲区问题?

最佳答案

最后,以下代码可以正常工作。将其发布以供人们关注

SSTableSimpleUnsortedWriter writer = new SSTableSimpleUnsortedWriter(outputDir, new Murmur3Partitioner(), KEYSPACE, TABLE, CompositeType.getInstance(UTF8Type.instance), null, 1000);
writer.newRow(bytes("2"));
ByteBuffer name = CompositeType.getInstance(UTF8Type.instance).builder().add(bytes("count")).build();
writer.addCounterColumn(name, 10L);


如果可以的话甚至更好

// SCHEMA is CQL Create table Query String  and KEYSPACE is string keyspace name
CFMetaData cfm = CFMetaData.compile(SCHEMA, KEYSPACE);
SSTableSimpleUnsortedWriter writer = new SSTableSimpleUnsortedWriter(outputDir, cfm, new Murmur3Partitioner(), defaultSize);

关于java - Cassandra 散装装载机,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30955612/

10-10 03:05