List of usage examples for org.apache.cassandra.db.marshal TupleType size
public int size()
From source file:com.stratio.cassandra.lucene.column.ColumnsMapper.java
License:Apache License
private void addColumns(Columns columns, ColumnBuilder builder, AbstractType type, ByteBuffer value) { if (type.isCollection()) { value = ByteBufferUtil.clone(value); CollectionType<?> collectionType = (CollectionType<?>) type; switch (collectionType.kind) { case SET: { AbstractType<?> nameType = collectionType.nameComparator(); int colSize = CollectionSerializer.readCollectionSize(value, Server.CURRENT_VERSION); for (int j = 0; j < colSize; j++) { ByteBuffer itemValue = CollectionSerializer.readValue(value, Server.CURRENT_VERSION); addColumns(columns, builder, nameType, itemValue); }/* w w w .ja v a 2s.com*/ break; } case LIST: { AbstractType<?> valueType = collectionType.valueComparator(); int colSize = CollectionSerializer.readCollectionSize(value, Server.CURRENT_VERSION); for (int j = 0; j < colSize; j++) { ByteBuffer itemValue = CollectionSerializer.readValue(value, Server.CURRENT_VERSION); addColumns(columns, builder, valueType, itemValue); } break; } case MAP: { AbstractType<?> keyType = collectionType.nameComparator(); AbstractType<?> valueType = collectionType.valueComparator(); int colSize = MapSerializer.readCollectionSize(value, Server.CURRENT_VERSION); for (int j = 0; j < colSize; j++) { ByteBuffer mapKey = MapSerializer.readValue(value, Server.CURRENT_VERSION); ByteBuffer mapValue = MapSerializer.readValue(value, Server.CURRENT_VERSION); String itemName = keyType.compose(mapKey).toString(); collectionType.nameComparator(); addColumns(columns, builder.withMapName(itemName), valueType, mapValue); } break; } default: { throw new IndexException("Unknown collection type %s", collectionType.kind); } } } else if (type instanceof UserType) { UserType userType = (UserType) type; ByteBuffer[] values = userType.split(value); for (int i = 0; i < userType.fieldNames().size(); i++) { String itemName = userType.fieldNameAsString(i); AbstractType<?> itemType = userType.fieldType(i); // This only occurs in UDT not fully composed if (values[i] != null) { addColumns(columns, builder.withUDTName(itemName), itemType, values[i]); } } } else if (type instanceof TupleType) { TupleType tupleType = (TupleType) type; ByteBuffer[] values = tupleType.split(value); for (Integer i = 0; i < tupleType.size(); i++) { String itemName = i.toString(); AbstractType<?> itemType = tupleType.type(i); addColumns(columns, builder.withUDTName(itemName), itemType, values[i]); } } else { if (value != null) { columns.add(builder.buildWithDecomposed(value, type)); } } }
From source file:org.elasticsearch.cassandra.cluster.InternalCassandraClusterService.java
License:Apache License
public void buildObjectMapping(Map<String, Object> mapping, final AbstractType<?> type) throws IOException { CQL3Type cql3type = type.asCQL3Type(); if (cql3type instanceof CQL3Type.Native) { mapping.put("type", cqlMapping.get(cql3type.toString())); } else if (cql3type instanceof CQL3Type.UserDefined) { mapping.put("type", ObjectMapper.NESTED_CONTENT_TYPE); mapping.put(TypeParsers.CQL_STRUCT, "udt"); Map<String, Object> properties = Maps.newHashMap(); TupleType tuple = (TupleType) type; for (int i = 0; i < tuple.size(); i++) { buildTypeMapping(properties, tuple.type(i)); }/*from w ww . j a v a2s.c o m*/ mapping.put("properties", properties); } }
From source file:org.elasticsearch.index.mapper.MapperService.java
License:Apache License
private void buildNativeOrUdtMapping(Map<String, Object> mapping, final AbstractType<?> type) throws IOException { CQL3Type cql3type = type.asCQL3Type(); if (cql3type instanceof CQL3Type.Native) { String esType = InternalCassandraClusterService.cqlMapping.get(cql3type.toString()); if (esType != null) { mapping.put("type", esType); if (esType.equals("string")) { mapping.put("index", "not_analyzed"); }/*from www. jav a 2 s . co m*/ } else { logger.error("CQL type " + cql3type.toString() + " not supported"); } } else if (cql3type instanceof CQL3Type.UserDefined) { mapping.put("type", ObjectMapper.NESTED_CONTENT_TYPE); mapping.put(TypeParsers.CQL_STRUCT, "udt"); Map<String, Object> properties = Maps.newHashMap(); TupleType tuple = (TupleType) type; for (int i = 0; i < tuple.size(); i++) { buildCollectionMapping(properties, tuple.type(i)); } mapping.put("properties", properties); } }