use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.
the class RowTest method assertRangeTombstoneMarkers.
private void assertRangeTombstoneMarkers(ClusteringBound<?> start, ClusteringBound<?> end, DeletionTime deletionTime, Object[] expected) {
AbstractType clusteringType = (AbstractType) metadata.comparator.subtype(0);
assertEquals(1, start.size());
assertEquals(start.kind(), ClusteringPrefix.Kind.INCL_START_BOUND);
assertEquals(expected[0], clusteringType.getString(start.bufferAt(0)));
assertEquals(1, end.size());
assertEquals(end.kind(), ClusteringPrefix.Kind.INCL_END_BOUND);
assertEquals(expected[1], clusteringType.getString(end.bufferAt(0)));
assertEquals(expected[2], deletionTime.markedForDeleteAt());
assertEquals(expected[3], deletionTime.localDeletionTime());
}
use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.
the class SSTableHeaderFixTest method buildFakeSSTable.
private File buildFakeSSTable(File dir, int generation, TableMetadata.Builder cols, Function<ColumnMetadata, ColumnMetadata> freezer) {
TableMetadata headerMetadata = cols.build();
TableMetadata.Builder schemaCols = TableMetadata.builder("ks", "cf");
for (ColumnMetadata cm : cols.columns()) schemaCols.addColumn(freezer.apply(cm));
tableMetadata = schemaCols.build();
try {
Descriptor desc = new Descriptor(version, dir, "ks", "cf", generation, SSTableFormat.Type.BIG);
// Just create the component files - we don't really need those.
for (Component component : requiredComponents) assertTrue(new File(desc.filenameFor(component)).createFileIfNotExists());
AbstractType<?> partitionKey = headerMetadata.partitionKeyType;
List<AbstractType<?>> clusteringKey = headerMetadata.clusteringColumns().stream().map(cd -> cd.type).collect(Collectors.toList());
Map<ByteBuffer, AbstractType<?>> staticColumns = headerMetadata.columns().stream().filter(cd -> cd.kind == ColumnMetadata.Kind.STATIC).collect(Collectors.toMap(cd -> cd.name.bytes, cd -> cd.type, (a, b) -> a));
Map<ByteBuffer, AbstractType<?>> regularColumns = headerMetadata.columns().stream().filter(cd -> cd.kind == ColumnMetadata.Kind.REGULAR).collect(Collectors.toMap(cd -> cd.name.bytes, cd -> cd.type, (a, b) -> a));
File statsFile = new File(desc.filenameFor(Component.STATS));
SerializationHeader.Component header = SerializationHeader.Component.buildComponentForTools(partitionKey, clusteringKey, staticColumns, regularColumns, EncodingStats.NO_STATS);
try (SequentialWriter out = new SequentialWriter(statsFile)) {
desc.getMetadataSerializer().serialize(Collections.singletonMap(MetadataType.HEADER, header), out, version);
out.finish();
}
return new File(desc.filenameFor(Component.DATA));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.cassandra.db.marshal.AbstractType 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);
}
}
use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.
the class CassandraGenerators method toStringRecursive.
/**
* Uses reflection to generate a toString. This method is aware of common Cassandra classes and can be used for
* generators or tests to provide more details for debugging.
*/
public static String toStringRecursive(Object o) {
return ReflectionToStringBuilder.toString(o, new MultilineRecursiveToStringStyle() {
private String spacer = "";
{
// common lang uses start/end chars that are not the common ones used, so switch to the common ones
setArrayStart("[");
setArrayEnd("]");
setContentStart("{");
setContentEnd("}");
setUseIdentityHashCode(false);
setUseShortClassName(true);
}
protected boolean accept(Class<?> clazz) {
return // toString enums
!clazz.isEnum() && // if no fields, just toString
Stream.of(clazz.getDeclaredFields()).anyMatch(f -> !Modifier.isStatic(f.getModifiers()));
}
public void appendDetail(StringBuffer buffer, String fieldName, Object value) {
if (value instanceof ByteBuffer) {
value = ByteBufferUtil.bytesToHex((ByteBuffer) value);
} else if (value instanceof AbstractType) {
value = SchemaCQLHelper.toCqlType((AbstractType) value);
} else if (value instanceof Token || value instanceof InetAddressAndPort || value instanceof FieldIdentifier) {
value = value.toString();
} else if (value instanceof TableMetadata) {
// to make sure the correct indents are taken, convert to CQL, then replace newlines with the indents
// then prefix with the indents.
String cql = SchemaCQLHelper.getTableMetadataAsCQL((TableMetadata) value);
cql = NEWLINE_PATTERN.matcher(cql).replaceAll(Matcher.quoteReplacement("\n " + spacer));
cql = "\n " + spacer + cql;
value = cql;
}
super.appendDetail(buffer, fieldName, value);
}
// MultilineRecursiveToStringStyle doesn't look at what was set and instead hard codes the values when it "resets" the level
protected void setArrayStart(String arrayStart) {
super.setArrayStart(arrayStart.replace("{", "["));
}
protected void setArrayEnd(String arrayEnd) {
super.setArrayEnd(arrayEnd.replace("}", "]"));
}
protected void setContentStart(String contentStart) {
// use this to infer the spacer since it isn't exposed.
String[] split = contentStart.split("\n", 2);
spacer = split.length == 2 ? split[1] : "";
super.setContentStart(contentStart.replace("[", "{"));
}
protected void setContentEnd(String contentEnd) {
super.setContentEnd(contentEnd.replace("]", "}"));
}
}, true);
}
use of org.apache.cassandra.db.marshal.AbstractType in project cassandra by apache.
the class PartitionIterator method getKeyAsString.
public String getKeyAsString() {
StringBuilder sb = new StringBuilder();
int i = 0;
for (Object key : partitionKey) {
if (i > 0)
sb.append("|");
AbstractType type = generator.partitionKey.get(i++).type;
sb.append(type.getString(type.decompose(key)));
}
return sb.toString();
}
Aggregations