Package org.apache.cassandra.thrift

Examples of org.apache.cassandra.thrift.CfDef


        {
            // load the next pair
            if (!reader.nextKeyValue())
                return null;

            CfDef cfDef = getCfDef(loadSignature);
            ByteBuffer key = reader.getCurrentKey();
            Map<ByteBuffer, Column> cf = reader.getCurrentValue();
            assert key != null && cf != null;

            // output tuple, will hold the key, each indexed column in a tuple, then a bag of the rest
            // NOTE: we're setting the tuple size here only for the key so we can use setTupleValue on it

            Tuple tuple = keyToTuple(key, cfDef, parseType(cfDef.getKey_validation_class()));
            DefaultDataBag bag = new DefaultDataBag();

            // we must add all the indexed columns first to match the schema
            Map<ByteBuffer, Boolean> added = new HashMap<ByteBuffer, Boolean>();
            // take care to iterate these in the same order as the schema does
            for (ColumnDef cdef : cfDef.column_metadata)
            {
                if (cf.containsKey(cdef.name))
                {
                    tuple.append(columnToTuple(cf.get(cdef.name), cfDef, parseType(cfDef.getComparator_type())));
                }
                else
                {   // otherwise, we need to add an empty tuple to take its place
                    tuple.append(TupleFactory.getInstance().newTuple());
                }
                added.put(cdef.name, true);
            }
            // now add all the other columns
            for (Map.Entry<ByteBuffer, Column> entry : cf.entrySet())
            {
                if (!added.containsKey(entry.getKey()))
                    bag.add(columnToTuple(entry.getValue(), cfDef, parseType(cfDef.getComparator_type())));
            }
            tuple.append(bag);
            // finally, special top-level indexes if needed
            if (usePartitionFilter)
            {
                for (ColumnDef cdef : getIndexes())
                {
                    Tuple throwaway = columnToTuple(cf.get(cdef.name), cfDef, parseType(cfDef.getComparator_type()));
                    tuple.append(throwaway.get(1));
                }
            }
            return tuple;
        }
View Full Code Here


    /** define the schema */
    public ResourceSchema getSchema(String location, Job job) throws IOException
    {
        setLocation(location, job);
        CfDef cfDef = getCfDef(loadSignature);

        if (cfDef.column_type.equals("Super"))
            return null;
        /*
        Our returned schema should look like this:
View Full Code Here

    }

    /** get a list of columns with defined index*/
    private List<ColumnDef> getIndexes()
    {
        CfDef cfdef = getCfDef(loadSignature);
        List<ColumnDef> indexes = new ArrayList<ColumnDef>();
        for (ColumnDef cdef : cfdef.column_metadata)
        {
            if (cdef.index_type != null)
                indexes.add(cdef);
View Full Code Here

    }

    @Test
    public void testThriftToAvroConversion() 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);

        // make a correct Avro object
        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);
View Full Code Here

       
        assert DatabaseDescriptor.getTableDefinition(cf.tableName) != null;
        assert DatabaseDescriptor.getTableDefinition(cf.tableName) == ksm;
       
        // updating certain fields should fail.
        CfDef cf_def = new CfDef();
        cf_def.setId(cf.cfId);
        cf_def.setKeyspace(cf.tableName);
        cf_def.setName(cf.cfName);
        cf_def.setColumn_type(cf.cfType.name());
        cf_def.setComment(cf.comment);
        cf_def.setComparator_type(cf.comparator.getClass().getName());
        cf_def.setSubcomparator_type(null);
        cf_def.setGc_grace_seconds(cf.gcGraceSeconds);
        cf_def.setKey_cache_size(cf.keyCacheSize);
        cf_def.setPreload_row_cache(cf.preloadRowCache);
        cf_def.setRead_repair_chance(cf.readRepairChance);
        cf_def.setRow_cache_size(43.3);
        cf_def.setColumn_metadata(new ArrayList<ColumnDef>());
        cf_def.setDefault_validation_class("BytesType");
        cf_def.setMin_compaction_threshold(5);
        cf_def.setMax_compaction_threshold(31);
       
        // test valid operations.
        cf_def.setComment("Modified comment");
        CFMetaData updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;
       
        cf_def.setRow_cache_size(2d);
        updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;
       
        cf_def.setKey_cache_size(3d);
        updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;
       
        cf_def.setRead_repair_chance(0.23);
        updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;
       
        cf_def.setGc_grace_seconds(12);
        updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;
       
        cf_def.setPreload_row_cache(!cf_def.preload_row_cache);
        updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;
       
        cf_def.setDefault_validation_class("UTF8Type");
        updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;

        cf_def.setMin_compaction_threshold(3);
        updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;

        cf_def.setMax_compaction_threshold(33);
        updateCfm = cf.apply(cf_def);
        new UpdateColumnFamily(cf, updateCfm).apply();
        cf = updateCfm;

        // can't test changing the reconciler because there is only one impl.
       
        // check the cumulative affect.
        assert DatabaseDescriptor.getCFMetaData(cf.tableName, cf.cfName).comment.equals(cf_def.comment);
        assert DatabaseDescriptor.getCFMetaData(cf.tableName, cf.cfName).rowCacheSize == cf_def.row_cache_size;
        assert DatabaseDescriptor.getCFMetaData(cf.tableName, cf.cfName).keyCacheSize == cf_def.key_cache_size;
        assert DatabaseDescriptor.getCFMetaData(cf.tableName, cf.cfName).readRepairChance == cf_def.read_repair_chance;
        assert DatabaseDescriptor.getCFMetaData(cf.tableName, cf.cfName).gcGraceSeconds == cf_def.gc_grace_seconds;
        assert DatabaseDescriptor.getCFMetaData(cf.tableName, cf.cfName).preloadRowCache == cf_def.preload_row_cache;
        assert DatabaseDescriptor.getCFMetaData(cf.tableName, cf.cfName).defaultValidator == UTF8Type.instance;
       
        // make sure some invalid operations fail.
        int oldId = cf_def.id;
        try
        {
            cf_def.setId(cf_def.getId() + 1);
            updateCfm = cf.apply(cf_def);
            throw new AssertionError("Should have blown up when you used a different id.");
        }
        catch (ConfigurationException expected)
        {
            cf_def.setId(oldId);   
        }
       
        String oldStr = cf_def.getName();
        try
        {
            cf_def.setName(cf_def.getName() + "_renamed");
            updateCfm = cf.apply(cf_def);
            throw new AssertionError("Should have blown up when you used a different name.");
        }
        catch (ConfigurationException expected)
        {
            cf_def.setName(oldStr);
        }
       
        oldStr = cf_def.getKeyspace();
        try
        {
            cf_def.setKeyspace(oldStr + "_renamed");
            updateCfm = cf.apply(cf_def);
            throw new AssertionError("Should have blown up when you used a different keyspace.");
        }
        catch (ConfigurationException expected)
        {
            cf_def.setKeyspace(oldStr);
        }
       
        try
        {
            cf_def.setColumn_type(ColumnFamilyType.Super.name());
            updateCfm = cf.apply(cf_def);
            throw new AssertionError("Should have blwon up when you used a different cf type.");
        }
        catch (ConfigurationException expected)
        {
            cf_def.setColumn_type(ColumnFamilyType.Standard.name());
        }
       
        oldStr = cf_def.getComparator_type();
        try
        {
            cf_def.setComparator_type(BytesType.class.getSimpleName());
            updateCfm = cf.apply(cf_def);
            throw new AssertionError("Should have blown up when you used a different comparator.");
        }
        catch (ConfigurationException expected)
        {
            cf_def.setComparator_type(UTF8Type.class.getSimpleName());
        }

        try
        {
            cf_def.setMin_compaction_threshold(34);
            updateCfm = cf.apply(cf_def);
            throw new AssertionError("Should have blown up when min > max.");
        }
        catch (ConfigurationException expected)
        {
            cf_def.setMin_compaction_threshold(3);
        }

        try
        {
            cf_def.setMax_compaction_threshold(2);
            updateCfm = cf.apply(cf_def);
            throw new AssertionError("Should have blown up when max > min.");
        }
        catch (ConfigurationException expected)
        {
            cf_def.setMax_compaction_threshold(33);
        }
    }
View Full Code Here

            // load the next pair
            if (!reader.nextKeyValue())
                return null;

            CfInfo cfInfo = getCfInfo(loadSignature);
            CfDef cfDef = cfInfo.cfDef;
            Row row = reader.getCurrentValue();
            Tuple tuple = TupleFactory.getInstance().newTuple(cfDef.column_metadata.size());
            Iterator<ColumnDef> itera = cfDef.column_metadata.iterator();
            int i = 0;
            while (itera.hasNext())
View Full Code Here

        index = indexName;
    }

    public void announceMigration() throws InvalidRequestException, ConfigurationException
    {
        CfDef cfDef = null;

        KSMetaData ksm = Schema.instance.getTableDefinition(keyspace());

        for (CFMetaData cfm : ksm.cfMetaData().values())
        {
View Full Code Here

    {
        CFMetaData oldCfm = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
        boolean columnExists = false;
        // mutating oldCfm directly would be bad, but mutating a Thrift copy is fine.  This also
        // sets us up to use validateCfDef to check for index name collisions.
        CfDef cf_def = oldCfm.toThrift();
        for (ColumnDef cd : cf_def.column_metadata)
        {
            if (cd.name.equals(columnName.key))
            {
                if (cd.index_type != null)
View Full Code Here

    }

    public void announceMigration() throws InvalidRequestException, ConfigurationException
    {
        CFMetaData meta = validateColumnFamily(keyspace(), columnFamily());
        CfDef thriftDef = meta.toThrift();

        CFDefinition cfDef = meta.getCfDef();
        CFDefinition.Name name = this.oType == Type.OPTS ? null : cfDef.get(columnName);
        switch (oType)
        {
View Full Code Here

    public CfDef getCfDef(String keyspace) throws ConfigurationException, InvalidRequestException
    {
        CFMetaData meta = Schema.instance.getCFMetaData(keyspace, columnFamily);

        CfDef cfDef = meta.toThrift();

        ByteBuffer columnName = this.oType == OperationType.OPTS ? null
                                                                 : meta.comparator.fromString(this.columnName);

        switch (oType)
        {
            case ADD:
                if (cfDef.key_alias != null && cfDef.key_alias.equals(columnName))
                    throw new InvalidRequestException("Invalid column name: "
                                                      + this.columnName
                                                      + ", because it equals to key_alias.");

                cfDef.column_metadata.add(new ColumnDefinition(columnName,
                                                               TypeParser.parse(validator),
                                                               null,
                                                               null,
                                                               null).toThrift());
                break;

            case ALTER:
                if (cfDef.key_alias != null && cfDef.key_alias.equals(columnName))
                {
                    cfDef.setKey_validation_class(TypeParser.parse(validator).toString());
                }
                else
                {
                    ColumnDef toUpdate = null;
View Full Code Here

TOP

Related Classes of org.apache.cassandra.thrift.CfDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.