List of usage examples for org.apache.cassandra.cql3 ColumnIdentifier ColumnIdentifier
public ColumnIdentifier(ByteBuffer bytes, String text)
From source file:com.stratio.cassandra.lucene.service.ClusteringKeyMapperTest.java
License:Apache License
@Test public void testAddFields() throws InvalidRequestException, ConfigurationException { List<ColumnDef> columnDefinitions = new ArrayList<>(); columnDefinitions.add(new ColumnDef(ByteBufferUtil.bytes("field1"), UTF8Type.class.getCanonicalName()) .setIndex_name("field1").setIndex_type(IndexType.KEYS)); columnDefinitions.add(new ColumnDef(ByteBufferUtil.bytes("field2"), IntegerType.class.getCanonicalName()) .setIndex_name("field2").setIndex_type(IndexType.KEYS)); CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName()) .setColumn_metadata(columnDefinitions).setKeyspace("Keyspace1").setName("Standard1"); CFMetaData metadata = ThriftConversion.fromThrift(cfDef); Schema schema = SchemaBuilders.schema().mapper("field1", stringMapper()).mapper("field2", textMapper()) .build();//from w w w. j a v a 2 s .c o m ClusteringKeyMapper clusteringKeyMapper = ClusteringKeyMapper.instance(metadata, schema); CellName cellName = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); Document doc = new Document(); clusteringKeyMapper.addFields(doc, cellName); Field field = (Field) doc.getField(ClusteringKeyMapper.FIELD_NAME); assertNotNull("clusteringKeyMapper addFields to Document must add al least one Field to Doc", field); assertEquals("clusteringKeyMapper.byteRef included in Document must be equal", clusteringKeyMapper.bytesRef(cellName), field.binaryValue()); }
From source file:com.stratio.cassandra.lucene.service.ClusteringKeyMapperTest.java
License:Apache License
@Test public void testClusteringKeyFromDocument() throws InvalidRequestException, ConfigurationException { List<ColumnDef> columnDefinitions = new ArrayList<>(); columnDefinitions.add(new ColumnDef(ByteBufferUtil.bytes("field1"), UTF8Type.class.getCanonicalName()) .setIndex_name("field1").setIndex_type(IndexType.KEYS)); columnDefinitions.add(new ColumnDef(ByteBufferUtil.bytes("field2"), IntegerType.class.getCanonicalName()) .setIndex_name("field2").setIndex_type(IndexType.KEYS)); CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName()) .setColumn_metadata(columnDefinitions).setKeyspace("Keyspace1").setName("Standard1"); CFMetaData metadata = ThriftConversion.fromThrift(cfDef); Schema schema = SchemaBuilders.schema().mapper("field1", stringMapper()).mapper("field2", textMapper()) .build();/*w w w . j a v a 2 s . co m*/ ClusteringKeyMapper clusteringKeyMapper = ClusteringKeyMapper.instance(metadata, schema); CellName cellName = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); Document doc = new Document(); clusteringKeyMapper.addFields(doc, cellName); CellName cellName2 = clusteringKeyMapper.clusteringKey(doc); assertEquals("CellName added to Document must be equal like returned by clusteringKeymapper.clusteringkey" + "(doc)", cellName, cellName2); }
From source file:com.stratio.cassandra.lucene.service.ClusteringKeyMapperTest.java
License:Apache License
@Test public void testClusteringKeyFromByteRef() throws InvalidRequestException, ConfigurationException { List<ColumnDef> columnDefinitions = new ArrayList<>(); columnDefinitions.add(new ColumnDef(ByteBufferUtil.bytes("field1"), UTF8Type.class.getCanonicalName()) .setIndex_name("field1").setIndex_type(IndexType.KEYS)); columnDefinitions.add(new ColumnDef(ByteBufferUtil.bytes("field2"), IntegerType.class.getCanonicalName()) .setIndex_name("field2").setIndex_type(IndexType.KEYS)); CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName()) .setColumn_metadata(columnDefinitions).setKeyspace("Keyspace1").setName("Standard1"); CFMetaData metadata = ThriftConversion.fromThrift(cfDef); Schema schema = SchemaBuilders.schema().mapper("field1", stringMapper()).mapper("field2", textMapper()) .build();// w ww . j ava2 s. c o m ClusteringKeyMapper clusteringKeyMapper = ClusteringKeyMapper.instance(metadata, schema); CellName cellName = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); BytesRef bytesRef = clusteringKeyMapper.bytesRef(cellName); CellName cellName2 = clusteringKeyMapper.clusteringKey(bytesRef); assertEquals("clusteringKeyMapper.clusteringKey(bytesRef(cellName)) must be equal to cellName", cellName, cellName2); }
From source file:com.stratio.cassandra.lucene.service.RowKeysTest.java
License:Apache License
@Test public void testConstructorRowKeys() { RowKeys rowKeys = new RowKeys(); DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey = new RowKey(decoratedKey, clusteringKey); rowKeys.add(rowKey);/*from w w w . j a v a2s . c om*/ assertEquals("rowsKeys.add 1, size must return 1", 1, rowKeys.size()); DecoratedKey decoratedKey2 = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey2 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey2 = new RowKey(decoratedKey2, clusteringKey2); rowKeys.add(rowKey2); assertEquals("rowsKeys.add 2, size() must return 2", 2, rowKeys.size()); }
From source file:com.stratio.cassandra.lucene.service.RowKeysTest.java
License:Apache License
@Test public void testListConstructor() { DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey = new RowKey(decoratedKey, clusteringKey); DecoratedKey decoratedKey2 = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey2 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey2 = new RowKey(decoratedKey2, clusteringKey2); List<RowKey> list = new ArrayList<>(); list.add(rowKey);/* w w w . jav a 2 s .c o m*/ list.add(rowKey2); RowKeys rowKeys = new RowKeys(list); assertEquals("rowsKeys.add 2, size() must return 2", 2, rowKeys.size()); }
From source file:com.stratio.cassandra.lucene.service.RowKeysTest.java
License:Apache License
@Test public void testIterator() { DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey = new RowKey(decoratedKey, clusteringKey); DecoratedKey decoratedKey2 = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey2 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey2 = new RowKey(decoratedKey2, clusteringKey2); DecoratedKey decoratedKey3 = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey3 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey3 = new RowKey(decoratedKey3, clusteringKey3); DecoratedKey decoratedKey4 = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey4 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey4 = new RowKey(decoratedKey4, clusteringKey4); RowKeys rowKeys = new RowKeys(); rowKeys.add(rowKey);// www . j a va 2 s.co m rowKeys.add(rowKey2); rowKeys.add(rowKey3); rowKeys.add(rowKey4); int num = 4; for (RowKey rowKeyAux : rowKeys) { assertFalse("iterator returns a item that is npot added", rowKeyAux != rowKey && rowKeyAux != rowKey2 && rowKeyAux != rowKey3 && rowKeyAux != rowKey4); num--; } assertEquals("iterator return more items than expected ", num, 0); }
From source file:com.stratio.cassandra.lucene.service.RowKeysTest.java
License:Apache License
@Test public void testToString() { DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey = new RowKey(decoratedKey, clusteringKey); DecoratedKey decoratedKey2 = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey2 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey2 = new RowKey(decoratedKey2, clusteringKey2); List<RowKey> list = new ArrayList<>(); list.add(rowKey);/* ww w. j ava2s . co m*/ list.add(rowKey2); RowKeys rowKeys = new RowKeys(list); assertEquals("iterator return more items than expected ", "RowKeys{rowKeys=[" + rowKey.toString() + ", " + rowKey2.toString() + "]}", rowKeys.toString()); }
From source file:com.stratio.cassandra.lucene.service.RowKeyTest.java
License:Apache License
@Test public void tesRowKey() { DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey = new RowKey(decoratedKey, clusteringKey); assertEquals("RowKey.getPartitionKey must return the same passsed as parameter", rowKey.getPartitionKey(), decoratedKey);//from w ww . jav a 2 s. c o m assertEquals("RowKey.getClusteringKey must return the same passsed as parameter", rowKey.getClusteringKey(), clusteringKey); }
From source file:com.stratio.cassandra.lucene.service.RowKeyTest.java
License:Apache License
@Test public void testToString() { DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); RowKey rowKey = new RowKey(decoratedKey, clusteringKey); assertEquals("RowKey.toString must return", "RowKey{partitionKey=DecoratedKey(10, ), " + "clusteringKey=" + clusteringKey.toString() + "}", rowKey.toString());//from w w w. j av a 2 s . com }
From source file:com.stratio.cassandra.lucene.service.SearchResultTest.java
License:Apache License
@Test public void testConstructor() { DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10), ByteBufferUtil.EMPTY_BYTE_BUFFER); CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false)); ScoreDoc scoreDoc = new ScoreDoc(1, 2.0f); SearchResult searchResult = new SearchResult(decoratedKey, clusteringKey, scoreDoc); Assert.assertNotNull("SearchResult constructor must not return a null object", searchResult); }