Do not persist ReversedType in system_schema.columns

patch by Aleksey Yeschenko; reviewed by Sam Tunnicliffe for
CASSANDRA-6717
This commit is contained in:
Aleksey Yeschenko 2015-09-14 22:03:35 +01:00
parent dd9a0abf2e
commit 2db8370fdf
4 changed files with 24 additions and 1 deletions

View File

@ -37,6 +37,11 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable<
public static final int NO_POSITION = -1;
public enum ClusteringOrder
{
ASC, DESC, NONE
}
/*
* The type of CQL3 column this definition represents.
* There is 4 main type of CQL3 columns: those parts of the partition key,
@ -222,6 +227,14 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable<
return kind == Kind.REGULAR;
}
public ClusteringOrder clusteringOrder()
{
if (!isClusteringColumn())
return ClusteringOrder.NONE;
return type.isReversed() ? ClusteringOrder.DESC : ClusteringOrder.ASC;
}
/**
* For convenience sake, if position == NO_POSITION, this method will return 0. The callers should first check
* isOnAllComponents() to distinguish between proper 0 position and NO_POSITION.

View File

@ -34,6 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.*;
import org.apache.cassandra.config.ColumnDefinition.ClusteringOrder;
import org.apache.cassandra.cql3.ColumnIdentifier;
import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.cql3.UntypedResultSet;
@ -117,6 +118,7 @@ public final class SchemaKeyspace
+ "keyspace_name text,"
+ "table_name text,"
+ "column_name text,"
+ "clustering_order text,"
+ "column_name_bytes blob,"
+ "kind text,"
+ "position int,"
@ -1163,10 +1165,15 @@ public final class SchemaKeyspace
{
RowUpdateBuilder adder = new RowUpdateBuilder(Columns, timestamp, mutation).clustering(table.cfName, column.name.toString());
AbstractType<?> type = column.type;
if (type instanceof ReversedType)
type = ((ReversedType) type).baseType;
adder.add("column_name_bytes", column.name.bytes)
.add("kind", column.kind.toString().toLowerCase())
.add("position", column.isOnAllComponents() ? ColumnDefinition.NO_POSITION : column.position())
.add("type", column.type.toString())
.add("clustering_order", column.clusteringOrder().toString().toLowerCase())
.add("type", type.toString())
.build();
}
@ -1193,8 +1200,11 @@ public final class SchemaKeyspace
ColumnDefinition.Kind kind = ColumnDefinition.Kind.valueOf(row.getString("kind").toUpperCase());
int position = row.getInt("position");
ClusteringOrder order = ClusteringOrder.valueOf(row.getString("clustering_order").toUpperCase());
AbstractType<?> type = parseType(row.getString("type"));
if (order == ClusteringOrder.DESC)
type = ReversedType.getInstance(type);
return new ColumnDefinition(keyspace, table, name, type, position, kind);
}