Search in sources :

Example 1 with ListType

use of org.apache.cassandra.db.marshal.ListType in project cassandra by apache.

the class SSTableHeaderFixTest method freezeUdt.

private AbstractType<?> freezeUdt(AbstractType<?> type) {
    if (type instanceof CollectionType) {
        if (type.getClass() == ListType.class) {
            ListType<?> cHeader = (ListType<?>) type;
            return ListType.getInstance(freezeUdt(cHeader.getElementsType()), cHeader.isMultiCell());
        } else if (type.getClass() == SetType.class) {
            SetType<?> cHeader = (SetType<?>) type;
            return SetType.getInstance(freezeUdt(cHeader.getElementsType()), cHeader.isMultiCell());
        } else if (type.getClass() == MapType.class) {
            MapType<?, ?> cHeader = (MapType<?, ?>) type;
            return MapType.getInstance(freezeUdt(cHeader.getKeysType()), freezeUdt(cHeader.getValuesType()), cHeader.isMultiCell());
        }
    } else if (type instanceof AbstractCompositeType) {
        if (type.getClass() == CompositeType.class) {
            CompositeType cHeader = (CompositeType) type;
            return CompositeType.getInstance(cHeader.types.stream().map(this::freezeUdt).collect(Collectors.toList()));
        }
    } else if (type instanceof TupleType) {
        if (type.getClass() == UserType.class) {
            UserType cHeader = (UserType) type;
            cHeader = cHeader.freeze();
            return new UserType(cHeader.keyspace, cHeader.name, cHeader.fieldNames(), cHeader.allTypes().stream().map(this::freezeUdt).collect(Collectors.toList()), cHeader.isMultiCell());
        }
    }
    return type;
}
Also used : SetType(org.apache.cassandra.db.marshal.SetType) CollectionType(org.apache.cassandra.db.marshal.CollectionType) ListType(org.apache.cassandra.db.marshal.ListType) TupleType(org.apache.cassandra.db.marshal.TupleType) UserType(org.apache.cassandra.db.marshal.UserType) MapType(org.apache.cassandra.db.marshal.MapType) AbstractCompositeType(org.apache.cassandra.db.marshal.AbstractCompositeType) CompositeType(org.apache.cassandra.db.marshal.CompositeType) AbstractCompositeType(org.apache.cassandra.db.marshal.AbstractCompositeType)

Example 2 with ListType

use of org.apache.cassandra.db.marshal.ListType in project cassandra by apache.

the class SSTableHeaderFixTest method assertFrozenUdt.

private void assertFrozenUdt(String name, AbstractType<?> type, boolean frozen, boolean checkInner) {
    if (type instanceof CompositeType) {
        if (checkInner)
            for (AbstractType<?> component : ((CompositeType) type).types) assertFrozenUdt(name, component, frozen, true);
    } else if (type instanceof CollectionType) {
        if (checkInner) {
            if (type instanceof MapType) {
                MapType map = (MapType) type;
                // only descend for non-frozen types (checking frozen in frozen is just stupid)
                if (map.isMultiCell()) {
                    assertFrozenUdt(name + "<map-key>", map.getKeysType(), frozen, true);
                    assertFrozenUdt(name + "<map-value>", map.getValuesType(), frozen, true);
                }
            } else if (type instanceof SetType) {
                SetType set = (SetType) type;
                // only descend for non-frozen types (checking frozen in frozen is just stupid)
                if (set.isMultiCell())
                    assertFrozenUdt(name + "<set>", set.getElementsType(), frozen, true);
            } else if (type instanceof ListType) {
                ListType list = (ListType) type;
                // only descend for non-frozen types (checking frozen in frozen is just stupid)
                if (list.isMultiCell())
                    assertFrozenUdt(name + "<list>", list.getElementsType(), frozen, true);
            }
        }
    } else if (type instanceof TupleType) {
        if (checkInner) {
            TupleType tuple = (TupleType) type;
            // only descend for non-frozen types (checking frozen in frozen is just stupid)
            if (tuple.isMultiCell())
                for (AbstractType<?> component : tuple.allTypes()) assertFrozenUdt(name + "<tuple>", component, frozen, true);
        }
    }
    if (type instanceof UserType) {
        String typeString = type.toString();
        assertEquals(name + ": " + typeString, frozen, !type.isMultiCell());
        if (typeString.startsWith(UserType.class.getName() + '('))
            if (frozen)
                fail(name + ": " + typeString);
        if (typeString.startsWith(FrozenType.class.getName() + '(' + UserType.class.getName() + '('))
            if (!frozen)
                fail(name + ": " + typeString);
    }
}
Also used : SetType(org.apache.cassandra.db.marshal.SetType) CollectionType(org.apache.cassandra.db.marshal.CollectionType) ListType(org.apache.cassandra.db.marshal.ListType) AbstractType(org.apache.cassandra.db.marshal.AbstractType) TupleType(org.apache.cassandra.db.marshal.TupleType) UserType(org.apache.cassandra.db.marshal.UserType) MapType(org.apache.cassandra.db.marshal.MapType) CompositeType(org.apache.cassandra.db.marshal.CompositeType) AbstractCompositeType(org.apache.cassandra.db.marshal.AbstractCompositeType)

Aggregations

AbstractCompositeType (org.apache.cassandra.db.marshal.AbstractCompositeType)2 CollectionType (org.apache.cassandra.db.marshal.CollectionType)2 CompositeType (org.apache.cassandra.db.marshal.CompositeType)2 ListType (org.apache.cassandra.db.marshal.ListType)2 MapType (org.apache.cassandra.db.marshal.MapType)2 SetType (org.apache.cassandra.db.marshal.SetType)2 TupleType (org.apache.cassandra.db.marshal.TupleType)2 UserType (org.apache.cassandra.db.marshal.UserType)2 AbstractType (org.apache.cassandra.db.marshal.AbstractType)1