Example usage for org.apache.cassandra.db.marshal MapType getKeysType

List of usage examples for org.apache.cassandra.db.marshal MapType getKeysType

Introduction

In this page you can find the example usage for org.apache.cassandra.db.marshal MapType getKeysType.

Prototype

public AbstractType<K> getKeysType() 

Source Link

Usage

From source file:org.elasticsearch.cassandra.cluster.InternalCassandraClusterService.java

License:Apache License

public void buildTypeMapping(Map<String, Object> mapping, final AbstractType<?> type) throws IOException {
    CQL3Type cql3type = type.asCQL3Type();
    if (type.isCollection()) {
        if (type instanceof ListType) {
            mapping.put(TypeParsers.CQL_COLLECTION, "list");
            buildObjectMapping(mapping, ((ListType<?>) type).getElementsType());
        } else if (type instanceof SetType) {
            mapping.put(TypeParsers.CQL_COLLECTION, "set");
            buildObjectMapping(mapping, ((SetType<?>) type).getElementsType());
        } else if (type instanceof MapType) {
            MapType mtype = (MapType) type;
            if (mtype.getKeysType().asCQL3Type() == CQL3Type.Native.TEXT) {
                mapping.put(TypeParsers.CQL_COLLECTION, "singleton");
                mapping.put(TypeParsers.CQL_STRUCT, "map");
                mapping.put(TypeParsers.CQL_PARTIAL_UPDATE, Boolean.TRUE);
                mapping.put("type", ObjectMapper.NESTED_CONTENT_TYPE);
            } else {
                throw new IOException("Expecting a map<text,?>");
            }//from   w  w w  . j  a  v  a  2s  . c o  m
        }
    } else {
        mapping.put(TypeParsers.CQL_COLLECTION, "singleton");
        buildObjectMapping(mapping, type);
    }
}

From source file:org.elasticsearch.index.mapper.MapperService.java

License:Apache License

private void buildCollectionMapping(Map<String, Object> mapping, final AbstractType<?> type)
        throws IOException {
    if (type.isCollection()) {
        if (type instanceof ListType) {
            mapping.put(TypeParsers.CQL_COLLECTION, "list");
            buildNativeOrUdtMapping(mapping, ((ListType<?>) type).getElementsType());
        } else if (type instanceof SetType) {
            mapping.put(TypeParsers.CQL_COLLECTION, "set");
            buildNativeOrUdtMapping(mapping, ((SetType<?>) type).getElementsType());
        } else if (type instanceof MapType) {
            MapType<?, ?> mtype = (MapType<?, ?>) type;
            if (mtype.getKeysType().asCQL3Type() == CQL3Type.Native.TEXT) {
                mapping.put(TypeParsers.CQL_COLLECTION, "singleton");
                mapping.put(TypeParsers.CQL_STRUCT, "map");
                mapping.put(TypeParsers.CQL_MANDATORY, Boolean.TRUE);
                mapping.put("type", ObjectMapper.NESTED_CONTENT_TYPE);
            } else {
                throw new IOException("Expecting a map<text,?>");
            }/* w w w .  j  a va  2  s.  com*/
        }
    } else {
        mapping.put(TypeParsers.CQL_COLLECTION, "singleton");
        buildNativeOrUdtMapping(mapping, type);
    }
}