List of usage examples for org.apache.cassandra.db.marshal AbstractType getComponents
public List<AbstractType<?>> getComponents()
From source file:com.stratio.cassandra.index.PartitionKeyMapper.java
License:Apache License
public Columns columns(Row row) { DecoratedKey partitionKey = row.key; Columns columns = new Columns(); AbstractType<?> rawKeyType = metadata.getKeyValidator(); List<ColumnDefinition> columnDefinitions = metadata.partitionKeyColumns(); for (ColumnDefinition columnDefinition : columnDefinitions) { String name = columnDefinition.name.toString(); ByteBuffer[] components = ByteBufferUtils.split(partitionKey.getKey(), rawKeyType); int position = columnDefinition.position(); ByteBuffer value = components[position]; AbstractType<?> valueType = rawKeyType.getComponents().get(position); columns.add(new Column(name, value, valueType)); }//from w w w . ja va 2 s . c o m return columns; }
From source file:com.stratio.cassandra.index.util.ByteBufferUtils.java
License:Apache License
/** * Returns the {@link AbstractType}s contained in {@code type}. * * @param type the {@link AbstractType} to be split. * @return the {@link AbstractType}s contained in {@code type}. *//*from ww w . j a v a 2s . c o m*/ public static List<AbstractType<?>> split(AbstractType<?> type) { if (type instanceof CompositeType) { return type.getComponents(); } else { List<AbstractType<?>> result = new ArrayList<>(1); result.add(type); return result; } }
From source file:com.stratio.cassandra.lucene.service.PartitionKeyMapper.java
License:Apache License
/** * Returns the columns contained in the partition key of the specified {@link Row}. Note that not all the contained * columns are returned, but only those of the partition key. * * @param row A {@link Row}.//from www.j a v a 2s. c o m * @return The columns contained in the partition key of the specified {@link Row}. */ public Columns columns(Row row) { DecoratedKey partitionKey = row.key; Columns columns = new Columns(); AbstractType<?> rawKeyType = metadata.getKeyValidator(); List<ColumnDefinition> columnDefinitions = metadata.partitionKeyColumns(); for (ColumnDefinition columnDefinition : columnDefinitions) { String name = columnDefinition.name.toString(); ByteBuffer[] components = ByteBufferUtils.split(partitionKey.getKey(), rawKeyType); int position = columnDefinition.position(); ByteBuffer value = components[position]; AbstractType<?> valueType = rawKeyType.getComponents().get(position); columns.add(Column.fromDecomposed(name, value, valueType, false)); } return columns; }
From source file:com.tuplejump.stargate.lucene.query.function.AggregateFunction.java
License:Apache License
public void load(Tuple tuple, Row row, ColumnFamilyStore table) { CompositeType baseComparator = (CompositeType) table.getComparator(); ColumnFamily cf = row.cf;//w w w. j a v a 2 s . c om CFDefinition cfDef = table.metadata.getCfDef(); ByteBuffer rowKey = row.key.key; AbstractType<?> keyValidator = table.metadata.getKeyValidator(); Collection<Column> cols = cf.getSortedColumns(); boolean keyColumnsAdded = false; for (Column column : cols) { if (!keyColumnsAdded) { ByteBuffer[] keyComponents = cfDef.hasCompositeKey ? ((CompositeType) table.metadata.getKeyValidator()).split(rowKey) : new ByteBuffer[] { rowKey }; List<AbstractType<?>> keyValidators = keyValidator.getComponents(); for (Map.Entry<Integer, Pair<String, ByteBuffer>> entry : options.partitionKeysIndexed.entrySet()) { ByteBuffer value = keyComponents[entry.getKey()]; AbstractType<?> validator = keyValidators.get(entry.getKey()); String actualColumnName = entry.getValue().left; for (String field : positions.keySet()) { if (actualColumnName.equalsIgnoreCase(field)) { tuple.tuple[this.positions.get(field)] = validator.compose(value); } } } keyColumnsAdded = true; } String actualColumnName = CassandraUtils.getColumnNameStr(baseComparator, column.name()); ByteBuffer colValue = column.value(); AbstractType<?> valueValidator = table.metadata.getValueValidatorFromColumnName(column.name()); if (valueValidator.isCollection()) { CollectionType validator = (CollectionType) valueValidator; AbstractType keyType = validator.nameComparator(); AbstractType valueType = validator.valueComparator(); ByteBuffer[] components = baseComparator.split(column.name()); ByteBuffer keyBuf = components[components.length - 1]; if (valueValidator instanceof MapType) { actualColumnName = actualColumnName + "." + keyType.compose(keyBuf); valueValidator = valueType; } else if (valueValidator instanceof SetType) { colValue = keyBuf; valueValidator = keyType; } else { valueValidator = valueType; } } for (String field : positions.keySet()) { if (actualColumnName.equalsIgnoreCase(field)) { tuple.tuple[this.positions.get(field)] = valueValidator.compose(colValue); } } } }