C
- type of the column name or column keyD
- type of the column valuepublic class CustomColumn<C extends Serializable & Comparable<C>,D> extends Column<C,D>
A custom column is normally used to create a composite column which is normally used to implement filtering with a secondary index. For example, to filter persons by Status and Sex ("Get all female single persons") a composite column that stores the status and sex can be created and a secondary index can be set. Thus the column family to store persons would have a column for status ( to support filtering by status), a column for sex (to support filtering by sex) and a composite column for status-sex.
A composite column is also used to implement super columns. Astyanax
deprecated ColumnPath
with the following
comment: "Super columns should be replaced with composite columns". All
super columns support was dropped in favor of composite columns. Cassandra
will eventually replace the super column implementation with composite
columns.
Note that composite columns that will act as super columns are nornally not indexed since they will tend to store several values.
Note: In order to use the value of a custom column, when it is read from the column family, it will have to be casted.
Column<C, ?> column = read(...); SomeObj someObj = (SomeObj)column.getValue();For specific applications that use specific custom values an additional visitor pattern may be used to avoid casting. For each subclass of
CustomColumn
a ColumnDecoder
will have to be created too to
create the right subclass instance. However the same
CustomColumn.CustomIndexValueExpressionStrategy
can be used.
Example:
public abstract class MyCustomColumn<C extends Serializable & Comparable<C>, D> extends CustomColumn<C, D> { ... public abstract void accept(MyCustomColumnVisitor<C> visitor); } public class SomeObjColumn<C extends Serializable & Comparable<C> >extends MyCustomColumn<C, SomeObj> { ... @Override public void accept(MyCustomColumnVisitor<C> visitor) { visitor.visit(this); } } public interface MyCustomColumnVisitor<C extends Serializable & Comparable<C>> { public void visit(SomeObjColumn<C> column); }
Modifier and Type | Class and Description |
---|---|
static class |
CustomColumn.CustomColumnDecoder<C extends Serializable & Comparable<C>,D>
Custom column decoder.
|
static class |
CustomColumn.CustomIndexValueExpressionStrategy<K extends Serializable,C extends Serializable & Comparable<C>,D>
Custom index value expression strategy.
|
serializer
Constructor and Description |
---|
CustomColumn(ColumnName<C,D> name)
Creates a boolean column with no value
|
CustomColumn(ColumnName<C,D> name,
D value,
com.netflix.astyanax.Serializer<D> serializer)
Creates a boolean column.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(ColumnVisitor<C> visitor)
Calls a visit method of the visitor, this class object passes itself as
an argument to the visit method this class object.
|
void |
addToMutation(com.netflix.astyanax.ColumnListMutation<C> mutation)
Adds the column to a mutation.
|
com.netflix.astyanax.Execution<Void> |
addToMutation(com.netflix.astyanax.ColumnMutation mutation)
Adds the column to a mutation.
|
int |
compareTo(Column<C,D> o2) |
public CustomColumn(ColumnName<C,D> name)
name
- column's namepublic CustomColumn(ColumnName<C,D> name, D value, com.netflix.astyanax.Serializer<D> serializer)
name
- column's namevalue
- column's valueserializer
- serializerpublic int compareTo(Column<C,D> o2)
compareTo
in class Column<C extends Serializable & Comparable<C>,D>
public void accept(ColumnVisitor<C> visitor)
visitor
- ColumnVisitorpublic com.netflix.astyanax.Execution<Void> addToMutation(com.netflix.astyanax.ColumnMutation mutation)
mutation
- to add the column topublic void addToMutation(com.netflix.astyanax.ColumnListMutation<C> mutation)
mutation
- to add the column toCopyright © 2016. All Rights Reserved.