org.apache.cassandra.thrift.ColumnDef Java Examples

The following examples show how to use org.apache.cassandra.thrift.ColumnDef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ColumnDefinition.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static ColumnDefinition fromThrift(String ksName, String cfName, AbstractType<?> thriftComparator, AbstractType<?> thriftSubcomparator, ColumnDef thriftColumnDef) throws SyntaxException, ConfigurationException
{
    // For super columns, the componentIndex is 1 because the ColumnDefinition applies to the column component.
    Integer componentIndex = thriftSubcomparator != null ? 1 : null;
    AbstractType<?> comparator = thriftSubcomparator == null ? thriftComparator : thriftSubcomparator;
    try
    {
        comparator.validate(thriftColumnDef.name);
    }
    catch (MarshalException e)
    {
        throw new ConfigurationException(String.format("Column name %s is not valid for comparator %s", ByteBufferUtil.bytesToHex(thriftColumnDef.name), comparator));
    }

    return new ColumnDefinition(ksName,
                                cfName,
                                new ColumnIdentifier(ByteBufferUtil.clone(thriftColumnDef.name), comparator),
                                TypeParser.parse(thriftColumnDef.validation_class),
                                thriftColumnDef.index_type == null ? null : IndexType.valueOf(thriftColumnDef.index_type.name()),
                                thriftColumnDef.index_options,
                                thriftColumnDef.index_name,
                                componentIndex,
                                Kind.REGULAR);
}
 
Example #2
Source File: CassandraPersistenceUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public static List<ColumnDefinition> getIndexMetadata( String indexes ) {
    if ( indexes == null ) {
        return null;
    }
    String[] index_entries = split( indexes, ',' );
    List<ColumnDef> columns = new ArrayList<ColumnDef>();
    for ( String index_entry : index_entries ) {
        String column_name = stringOrSubstringBeforeFirst( index_entry, ':' ).trim();
        String comparer = substringAfterLast( index_entry, ":" ).trim();
        if ( StringUtils.isBlank( comparer ) ) {
            comparer = "UUIDType";
        }
        if ( StringUtils.isNotBlank( column_name ) ) {
            ColumnDef cd = new ColumnDef( bytebuffer( column_name ), comparer );
            cd.setIndex_name( column_name );
            cd.setIndex_type( IndexType.KEYS );
            columns.add( cd );
        }
    }
    return ThriftColumnDef.fromThriftList( columns );
}
 
Example #3
Source File: ColumnDefinition.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static List<ColumnDef> toThrift(Map<ByteBuffer, ColumnDefinition> columns)
{
    List<ColumnDef> thriftDefs = new ArrayList<>(columns.size());
    for (ColumnDefinition def : columns.values())
        if (def.kind == ColumnDefinition.Kind.REGULAR)
            thriftDefs.add(def.toThrift());
    return thriftDefs;
}
 
Example #4
Source File: ColumnDefinition.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public ColumnDef toThrift()
{
    ColumnDef cd = new ColumnDef();

    cd.setName(ByteBufferUtil.clone(name.bytes));
    cd.setValidation_class(type.toString());
    cd.setIndex_type(indexType == null ? null : org.apache.cassandra.thrift.IndexType.valueOf(indexType.name()));
    cd.setIndex_name(indexName == null ? null : indexName);
    cd.setIndex_options(indexOptions == null ? null : Maps.newHashMap(indexOptions));

    return cd;
}
 
Example #5
Source File: ColumnDefinition.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static List<ColumnDefinition> fromThrift(String ksName, String cfName, AbstractType<?> thriftComparator, AbstractType<?> thriftSubcomparator, List<ColumnDef> thriftDefs) throws SyntaxException, ConfigurationException
{
    if (thriftDefs == null)
        return new ArrayList<>();

    List<ColumnDefinition> defs = new ArrayList<>(thriftDefs.size());
    for (ColumnDef thriftColumnDef : thriftDefs)
        defs.add(fromThrift(ksName, cfName, thriftComparator, thriftSubcomparator, thriftColumnDef));

    return defs;
}
 
Example #6
Source File: CFMetaDataTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testThriftConversion() throws Exception
{
    CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName())
                             .setComment("Test comment")
                             .setColumn_metadata(columnDefs)
                             .setKeyspace(KEYSPACE)
                             .setName(COLUMN_FAMILY);

    // convert Thrift to CFMetaData
    CFMetaData cfMetaData = CFMetaData.fromThrift(cfDef);

    CfDef thriftCfDef = new CfDef();
    thriftCfDef.keyspace = KEYSPACE;
    thriftCfDef.name = COLUMN_FAMILY;
    thriftCfDef.default_validation_class = cfDef.default_validation_class;
    thriftCfDef.comment = cfDef.comment;
    thriftCfDef.column_metadata = new ArrayList<ColumnDef>();
    for (ColumnDef columnDef : columnDefs)
    {
        ColumnDef c = new ColumnDef();
        c.name = ByteBufferUtil.clone(columnDef.name);
        c.validation_class = columnDef.getValidation_class();
        c.index_name = columnDef.getIndex_name();
        c.index_type = IndexType.KEYS;
        thriftCfDef.column_metadata.add(c);
    }

    CfDef converted = cfMetaData.toThrift();

    assertEquals(thriftCfDef.keyspace, converted.keyspace);
    assertEquals(thriftCfDef.name, converted.name);
    assertEquals(thriftCfDef.default_validation_class, converted.default_validation_class);
    assertEquals(thriftCfDef.comment, converted.comment);
    assertEquals(new HashSet<>(thriftCfDef.column_metadata), new HashSet<>(converted.column_metadata));
}