List of usage examples for org.apache.cassandra.db.marshal CompositeType getInstance
public static CompositeType getInstance(List<AbstractType<?>> types)
From source file:com.stratio.cassandra.lucene.key.KeyMapper.java
License:Apache License
/** * Constructor specifying the partition and clustering key mappers. * * @param metadata the indexed table metadata *//*w w w .j av a 2s . c o m*/ public KeyMapper(CFMetaData metadata) { this.metadata = metadata; clusteringComparator = metadata.comparator; clusteringType = CompositeType.getInstance(clusteringComparator.subtypes()); type = CompositeType.getInstance(LongType.instance, metadata.getKeyValidator(), clusteringType); }
From source file:com.stratio.deep.cassandra.cql.DeepRecordReader.java
License:Apache License
/** * retrieve the partition keys and cluster keys from system.schema_columnfamilies table *///from w w w . j a v a 2s . c om //TODO check this private void retrieveKeys() { TableMetadata tableMetadata = config.fetchTableMetadata(); List<ColumnMetadata> partitionKeys = tableMetadata.getPartitionKey(); List<ColumnMetadata> clusteringKeys = tableMetadata.getClusteringColumns(); List<AbstractType<?>> types = new ArrayList<>(); for (ColumnMetadata key : partitionKeys) { String columnName = key.getName(); BoundColumn boundColumn = new BoundColumn(columnName); boundColumn.validator = CellValidator.cellValidator(key.getType()).getAbstractType(); partitionBoundColumns.add(boundColumn); types.add(boundColumn.validator); } for (ColumnMetadata key : clusteringKeys) { String columnName = key.getName(); BoundColumn boundColumn = new BoundColumn(columnName); boundColumn.validator = CellValidator.cellValidator(key.getType()).getAbstractType(); clusterColumns.add(boundColumn); } if (types.size() > 1) { keyValidator = CompositeType.getInstance(types); } else if (types.size() == 1) { keyValidator = types.get(0); } else { throw new DeepGenericException( "Cannot determine if keyvalidator is composed or not, " + "partitionKeys: " + partitionKeys); } }
From source file:io.datalayer.cassandra.support.AosEmbeddedSchemaLoader.java
License:Apache License
private static CFMetaData compositeCFMD(String ksName, String cfName, AbstractType<?>... types) { return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, CompositeType.getInstance(Arrays.asList(types)), null); }
From source file:kina.cql.CqlRecordReader.java
License:Apache License
/** * retrieve the partition keys and cluster keys from system.schema_columnfamilies table *//*from w w w. j ava2 s .c o m*/ private void retrieveKeys() { TableMetadata tableMetadata = ((GenericCassandraKinaConfig) config).fetchTableMetadata(); List<ColumnMetadata> partitionKeys = tableMetadata.getPartitionKey(); List<ColumnMetadata> clusteringKeys = tableMetadata.getClusteringColumns(); List<AbstractType<?>> types = new ArrayList<>(); for (ColumnMetadata key : partitionKeys) { String columnName = key.getName(); BoundColumn boundColumn = new BoundColumn(columnName); boundColumn.validator = CassandraCell.getValueType(key.getType()).getAbstractType(); partitionBoundColumns.add(boundColumn); types.add(boundColumn.validator); } for (ColumnMetadata key : clusteringKeys) { String columnName = key.getName(); BoundColumn boundColumn = new BoundColumn(columnName); boundColumn.validator = CassandraCell.getValueType(key.getType()).getAbstractType(); clusterColumns.add(boundColumn); } if (types.size() > 1) { keyValidator = CompositeType.getInstance(types); } else if (types.size() == 1) { keyValidator = types.get(0); } else { throw new GenericException( "Cannot determine if keyvalidator is composed or not, " + "partitionKeys: " + partitionKeys); } }
From source file:me.tango.cassandra.bench.SchemaLoader.java
License:Apache License
public static Collection<KSMetaData> schemaDefinition() throws ConfigurationException { List<KSMetaData> schema = new ArrayList<KSMetaData>(); // A whole bucket of shorthand String ks1 = "Keyspace1"; Class<? extends AbstractReplicationStrategy> simple = SimpleStrategy.class; Map<String, String> opts_rf1 = KSMetaData.optsWithRF(1); AbstractType bytes = BytesType.instance; AbstractType<?> composite = CompositeType.getInstance(Arrays .asList(new AbstractType<?>[] { BytesType.instance, TimeUUIDType.instance, IntegerType.instance })); AbstractType<?> compositeMaxMin = CompositeType .getInstance(Arrays.asList(new AbstractType<?>[] { BytesType.instance, IntegerType.instance })); Map<Byte, AbstractType<?>> aliases = new HashMap<Byte, AbstractType<?>>(); aliases.put((byte) 'b', BytesType.instance); aliases.put((byte) 't', TimeUUIDType.instance); aliases.put((byte) 'B', ReversedType.getInstance(BytesType.instance)); aliases.put((byte) 'T', ReversedType.getInstance(TimeUUIDType.instance)); AbstractType<?> dynamicComposite = DynamicCompositeType.getInstance(aliases); Map<String, String> leveledOptions = new HashMap<String, String>(); leveledOptions.put("sstable_size_in_mb", "64"); Map<String, String> compressionOptions = new HashMap<String, String>(); compressionOptions.put("sstable_compression", ""); // Keyspace 1 schema.add(KSMetaData.testMetadata(ks1, simple, opts_rf1, // Column Families standardCFMD(ks1, "Standard1").compactionStrategyClass(LeveledCompactionStrategy.class) .maxIndexInterval(256).compactionStrategyOptions(leveledOptions) .compressionParameters(CompressionParameters.create(compressionOptions)))); return schema; }
From source file:org.usergrid.vx.experimental.IntraServiceITest.java
License:Apache License
@Test public void compositeTest() throws Exception { IntraReq req = new IntraReq(); req.add(Operations.setKeyspaceOp("compks")); // 0 req.add(Operations.createKsOp("compks", 1)); // 1 req.add(Operations.createCfOp("compcf")); // 2 req.add(Operations.setColumnFamilyOp("compcf")); // 3 req.add(Operations.setAutotimestampOp(true)); // 4 req.add(Operations.assumeOp("compks", "compcf", "value", "CompositeType(UTF8Type,Int32Type)"));// 5 req.add(Operations.assumeOp("compks", "compcf", "column", "Int32Type"));// 6 req.add(Operations.setOp("rowa", 1, new Object[] { "yo", 0, 2, 0 })); // 7 req.add(Operations.getOp("rowa", 1)); // 8 IntraClient2 ic2 = new IntraClient2("localhost", 8080); IntraRes res = ic2.sendBlocking(req); List<Map> x = (List<Map>) res.getOpsRes().get("8"); Assert.assertEquals(1, x.get(0).get("name")); // ByteBuffer bytes = (ByteBuffer) x.get(0).get("value"); String value = (String) x.get(0).get("value"); ByteBuffer bytes = ByteBuffer.wrap(Base64.decode(value)); List<AbstractType<?>> comparators = new ArrayList<>(); comparators.add(UTF8Type.instance); comparators.add(Int32Type.instance); CompositeType comparator = CompositeType.getInstance(comparators); List<AbstractCompositeType.CompositeComponent> components = comparator.deconstruct(bytes); AbstractCompositeType.CompositeComponent c1 = components.get(0); AbstractCompositeType.CompositeComponent c2 = components.get(1); Assert.assertEquals("yo", c1.comparator.compose(c1.value)); Assert.assertEquals(2, c2.comparator.compose(c2.value)); }