Example usage for org.apache.cassandra.db.marshal AbstractType decompose

List of usage examples for org.apache.cassandra.db.marshal AbstractType decompose

Introduction

In this page you can find the example usage for org.apache.cassandra.db.marshal AbstractType decompose.

Prototype

public ByteBuffer decompose(T value) 

Source Link

Usage

From source file:com.dse.pig.udfs.CqlStorage.java

License:Apache License

private Object cassandraToPigData(Object obj, AbstractType validator) {
    if (validator instanceof DecimalType || validator instanceof InetAddressType)
        return validator.getString(validator.decompose(obj));
    return obj;/*from   ww w  .  ja v a2  s.c  o m*/
}

From source file:com.stratio.cassandra.lucene.column.ColumnBuilder.java

License:Apache License

/**
 * Returns a new {@link Column} using the specified composed value and its type.
 *
 * @param composedValue the decomposed value
 * @param type the value type// w ww. ja  va 2s  . c om
 * @param <T> the marshaller's base type
 * @return the built column
 */
public <T> Column<T> buildWithComposed(T composedValue, AbstractType<T> type) {
    ByteBuffer decomposedValue = type.decompose(composedValue);
    return new Column<>(cellName, udtNames, mapNames, decomposedValue, composedValue, type);
}

From source file:com.stratio.cassandra.lucene.column.ColumnTest.java

License:Apache License

@Test
public void testCreateFromDecomposedWithoutSuffix() {
    AbstractType<Long> type = LongType.instance;
    Long composedValue = 5L;//from   ww w  .j  a v  a2s.  co m
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.builder("my_column").buildWithDecomposed(decomposedValue, type);
    assertEquals("Column full name is wrong", "my_column", column.getFullName());
    assertEquals("Column cell name is wrong", "my_column", column.getCellName());
    assertEquals("Column mapper name is wrong", "my_column", column.getMapperName());
    assertEquals("Column field name is wrong", "field", column.getFieldName("field"));
    assertEquals("Column type is wrong", type, column.getType());
    assertEquals("Column buildWithComposed is wrong", composedValue, column.getComposedValue());
    assertEquals("Column buildWithDecomposed is wrong", decomposedValue, column.getDecomposedValue());
}

From source file:com.stratio.cassandra.lucene.column.ColumnTest.java

License:Apache License

@Test
public void testCreateFromDecomposedWithMapSuffix() {
    AbstractType<Long> type = LongType.instance;
    Long composedValue = 5L;/* w w  w.  j  av  a2 s .  co m*/
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.builder("my").withMapName("column").buildWithDecomposed(decomposedValue, type);
    assertEquals("Column full name is wrong", "my$column", column.getFullName());
    assertEquals("Column cell name is wrong", "my", column.getCellName());
    assertEquals("Column mapper name is wrong", "my", column.getMapperName());
    assertEquals("Column field name is wrong", "field$column", column.getFieldName("field"));
    assertEquals("Column type is wrong", type, column.getType());
    assertEquals("Column buildWithComposed is wrong", composedValue, column.getComposedValue());
    assertEquals("Column buildWithDecomposed is wrong", decomposedValue, column.getDecomposedValue());
}

From source file:com.stratio.cassandra.lucene.column.ColumnTest.java

License:Apache License

@Test
public void testCreateFromDecomposedWithUDTSuffix() {
    AbstractType<Long> type = LongType.instance;
    Long composedValue = 5L;//from   w w  w  .  j  ava  2 s.c om
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.builder("my").withUDTName("column").buildWithDecomposed(decomposedValue, type);
    assertEquals("Column full name is wrong", "my.column", column.getFullName());
    assertEquals("Column cell name is wrong", "my", column.getCellName());
    assertEquals("Column mapper name is wrong", "my.column", column.getMapperName());
    assertEquals("Column field name is wrong", "field", column.getFieldName("field"));
    assertEquals("Column type is wrong", type, column.getType());
    assertEquals("Column buildWithComposed is wrong", composedValue, column.getComposedValue());
    assertEquals("Column buildWithDecomposed is wrong", decomposedValue, column.getDecomposedValue());
}

From source file:com.stratio.cassandra.lucene.column.ColumnTest.java

License:Apache License

@Test
public void testCreateFromDecomposedWithComplexSuffix() {
    AbstractType<Long> type = LongType.instance;
    Long composedValue = 5L;/*from ww w .j  a  va  2s. c o  m*/
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.builder("my").withUDTName("1").withUDTName("2").withUDTName("3")
            .withMapName("4").withMapName("5").withMapName("6").buildWithDecomposed(decomposedValue, type);
    assertEquals("Column full name is wrong", "my.1.2.3$4$5$6", column.getFullName());
    assertEquals("Column cell name is wrong", "my", column.getCellName());
    assertEquals("Column mapper name is wrong", "my.1.2.3", column.getMapperName());
    assertEquals("Column field name is wrong", "field$4$5$6", column.getFieldName("field"));
    assertEquals("Column type is wrong", type, column.getType());
    assertEquals("Column buildWithComposed is wrong", composedValue, column.getComposedValue());
    assertEquals("Column buildWithDecomposed is wrong", decomposedValue, column.getDecomposedValue());
}

From source file:com.stratio.cassandra.lucene.column.ColumnTest.java

License:Apache License

@Test
public void testCreateFromComposedWithoutSuffix() {
    AbstractType<Long> type = LongType.instance;
    Long composedValue = 5L;//  w  w  w  .  ja  v  a 2  s  .c o  m
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.builder("my_column").buildWithDecomposed(decomposedValue, type);
    assertEquals("Column full name is wrong", "my_column", column.getFullName());
    assertEquals("Column cell name is wrong", "my_column", column.getCellName());
    assertEquals("Column mapper name is wrong", "my_column", column.getMapperName());
    assertEquals("Column field name is wrong", "field", column.getFieldName("field"));
    assertEquals("Column buildWithComposed is wrong", composedValue, column.getComposedValue());
    assertEquals("Column buildWithDecomposed is wrong", decomposedValue, column.getDecomposedValue());
}

From source file:com.stratio.cassandra.lucene.column.ColumnTest.java

License:Apache License

@Test
public void testCreateFromComposedWithUDTSuffix() {
    AbstractType<Long> type = LongType.instance;
    Long composedValue = 5L;/*from w w w .j  a v a2  s. c o  m*/
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.builder("my").withUDTName("column").buildWithDecomposed(decomposedValue, type);
    assertEquals("Column full name is wrong", "my.column", column.getFullName());
    assertEquals("Column cell name is wrong", "my", column.getCellName());
    assertEquals("Column mapper name is wrong", "my.column", column.getMapperName());
    assertEquals("Column field name is wrong", "field", column.getFieldName("field"));
    assertEquals("Column buildWithComposed is wrong", composedValue, column.getComposedValue());
    assertEquals("Column buildWithDecomposed is wrong", decomposedValue, column.getDecomposedValue());
}

From source file:com.stratio.cassandra.lucene.schema.column.Column.java

License:Apache License

/**
 * Returns the {@link Column} defined by the specified name, value and type.
 *
 * @param name          The column name.
 * @param composedValue The column composed value.
 * @param type          The column type/marshaller.
 * @param isCollection  If the {@link Column} belongs to a collection.
 * @param <T>           The base type.
 * @return A {@link Column}.//from   w w  w.jav a2s. com
 */
public static <T> Column<T> fromComposed(String name, T composedValue, AbstractType<T> type,
        boolean isCollection) {
    ByteBuffer decomposedValue = type.decompose(composedValue);
    return new Column<>(name, null, decomposedValue, composedValue, type, isCollection);
}

From source file:com.stratio.cassandra.lucene.schema.column.Column.java

License:Apache License

/**
 * Returns the {@link Column} defined by the specified name, value and type.
 *
 * @param name          The column name.
 * @param sufix         The column name sufix.
 * @param composedValue The column composed value.
 * @param type          The column type/marshaller.
 * @param isCollection  If the {@link Column} belongs to a collection.
 * @param <T>           The base type.
 * @return A {@link Column}./*from   w w w.j a  v  a 2s .c  om*/
 */
public static <T> Column<T> fromComposed(String name, String sufix, T composedValue, AbstractType<T> type,
        boolean isCollection) {
    ByteBuffer decomposedValue = type.decompose(composedValue);
    return new Column<>(name, sufix, decomposedValue, composedValue, type, isCollection);
}