Search in sources :

Example 6 with UserType

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

the class AbstractRow method toString.

public String toString(TableMetadata metadata, boolean includeClusterKeys, boolean fullDetails) {
    StringBuilder sb = new StringBuilder();
    sb.append("Row");
    if (fullDetails) {
        sb.append("[info=").append(primaryKeyLivenessInfo());
        if (!deletion().isLive())
            sb.append(" del=").append(deletion());
        sb.append(" ]");
    }
    sb.append(": ");
    if (includeClusterKeys)
        sb.append(clustering().toString(metadata));
    else
        sb.append(clustering().toCQLString(metadata));
    sb.append(" | ");
    boolean isFirst = true;
    for (ColumnData cd : this) {
        if (isFirst)
            isFirst = false;
        else
            sb.append(", ");
        if (fullDetails) {
            if (cd.column().isSimple()) {
                sb.append(cd);
            } else {
                ComplexColumnData complexData = (ComplexColumnData) cd;
                if (!complexData.complexDeletion().isLive())
                    sb.append("del(").append(cd.column().name).append(")=").append(complexData.complexDeletion());
                for (Cell cell : complexData) sb.append(", ").append(cell);
            }
        } else {
            if (cd.column().isSimple()) {
                Cell cell = (Cell) cd;
                sb.append(cell.column().name).append('=');
                if (cell.isTombstone())
                    sb.append("<tombstone>");
                else
                    sb.append(cell.column().type.getString(cell.value()));
            } else {
                sb.append(cd.column().name).append('=');
                ComplexColumnData complexData = (ComplexColumnData) cd;
                Function<Cell, String> transform = null;
                if (cd.column().type.isCollection()) {
                    CollectionType ct = (CollectionType) cd.column().type;
                    transform = cell -> String.format("%s -> %s", ct.nameComparator().getString(cell.path().get(0)), ct.valueComparator().getString(cell.value()));
                } else if (cd.column().type.isUDT()) {
                    UserType ut = (UserType) cd.column().type;
                    transform = cell -> {
                        Short fId = ut.nameComparator().getSerializer().deserialize(cell.path().get(0));
                        return String.format("%s -> %s", ut.fieldNameAsString(fId), ut.fieldType(fId).getString(cell.value()));
                    };
                } else {
                    transform = cell -> "";
                }
                sb.append(StreamSupport.stream(complexData.spliterator(), false).map(transform).collect(Collectors.joining(", ", "{", "}")));
            }
        }
    }
    return sb.toString();
}
Also used : Iterables(com.google.common.collect.Iterables) FBUtilities(org.apache.cassandra.utils.FBUtilities) MessageDigest(java.security.MessageDigest) org.apache.cassandra.db(org.apache.cassandra.db) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) Objects(java.util.Objects) AbstractCollection(java.util.AbstractCollection) TableMetadata(org.apache.cassandra.schema.TableMetadata) StreamSupport(java.util.stream.StreamSupport) CollectionType(org.apache.cassandra.db.marshal.CollectionType) UserType(org.apache.cassandra.db.marshal.UserType) MarshalException(org.apache.cassandra.serializers.MarshalException) CollectionType(org.apache.cassandra.db.marshal.CollectionType) UserType(org.apache.cassandra.db.marshal.UserType)

Aggregations

UserType (org.apache.cassandra.db.marshal.UserType)6 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)3 ByteBuffer (java.nio.ByteBuffer)2 Iterables (com.google.common.collect.Iterables)1 MessageDigest (java.security.MessageDigest)1 AbstractCollection (java.util.AbstractCollection)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 org.apache.cassandra.db (org.apache.cassandra.db)1 CollectionType (org.apache.cassandra.db.marshal.CollectionType)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1 MarshalException (org.apache.cassandra.serializers.MarshalException)1 FBUtilities (org.apache.cassandra.utils.FBUtilities)1