Java 类org.apache.cassandra.thrift.CfDef 实例源码

项目:cassandra-kmean    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:ACaZoo    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * creating a keyspace
 *
 * @throws Exception
 */
@Test
public void createKeyspace() throws Exception {
    // keyspace define
    KsDef kd = new KsDef();
    kd.setName("mock");
    // kd.setStrategy_class("org.apache.cassandra.locator.SimpleStrategy");
    kd.setStrategy_class(SimpleStrategy.class.getName());
    //
    Map<String, String> map = new HashMap<String, String>();
    map.put("replication_factor", String.valueOf(1));
    kd.setStrategy_options(map);
    kd.setCf_defs(new ArrayList<CfDef>());
    //
    client.system_add_keyspace(kd);// InvalidRequestException(why:Keyspace
                                    // names must be case-insensitively
                                    // unique ("mock" conflicts with
                                    // "mock"))
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * adding a column family to an existing keyspace
 *
 * @throws Exception
 */
@Test
public void addColumnFamily() throws Exception {
    String KEYSPACE = "mock";
    client.set_keyspace(KEYSPACE);
    //
    String COLUMN_FAMILY = "student";
    CfDef cd = new CfDef();
    cd.setKeyspace(KEYSPACE);
    cd.setName(COLUMN_FAMILY);
    // cd.setKey_alias(key_alias);
    //
    cd.setComparator_type("UTF8Type");
    cd.setKey_validation_class("UTF8Type");
    cd.setDefault_validation_class("UTF8Type");
    client.system_add_column_family(cd);// InvalidRequestException(why:student
                                        // already exists in keyspace mock)
    //
    System.out.println("add column family [" + COLUMN_FAMILY + "]");
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * column family exist
 *
 * @throws Exception
 */
@Test
public void columnFamilyExists() throws Exception {
    String KEYSPACE = "mock";
    client.set_keyspace(KEYSPACE);
    //
    String COLUMN_FAMILY = "student";
    boolean result = false;
    KsDef kd = client.describe_keyspace(KEYSPACE);
    for (CfDef entry : kd.getCf_defs()) {
        if (entry.getName().equals(COLUMN_FAMILY)) {
            result = true;
            break;
        }
    }
    //
    System.out.println(result);// true
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * getting a column family
 *
 * @throws Exception
 */
@Test
public void getColumnFamily() throws Exception {
    // String KEYSPACE = "mock";
    // client.set_keyspace(KEYSPACE);
    // //
    // String COLUMN_FAMILY = "student";
    // KsDef kd = client.describe_keyspace(KEYSPACE);
    // CfDef result = null;
    // for (CfDef entry : kd.getCf_defs()) {
    // if (entry.getName().equals(COLUMN_FAMILY)) {
    // result = entry;
    // break;
    // }
    // }
    // System.out.println(result);

    String KEYSPACE = "mock";
    String COLUMN_FAMILY = "student";
    CfDef result = getColumnFamily(client, KEYSPACE, COLUMN_FAMILY);
    System.out.println(result);
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * getting a column family
 *
 * @param client
 * @param keyspace
 * @param columnFamily
 * @return
 */
protected static CfDef getColumnFamily(Cassandra.Client client,
        String keyspace, String columnFamily) {
    CfDef result = null;
    //
    try {
        KsDef kd = client.describe_keyspace(keyspace);
        for (CfDef entry : kd.getCf_defs()) {
            if (entry.getName().equals(columnFamily)) {
                result = entry;
                break;
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return result;
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * modifying a column family to an existing keyspace
 *
 * @throws Exception
 */
@Test
public void modifyColumnFamily() throws Exception {
    String KEYSPACE = "mock";
    client.set_keyspace(KEYSPACE);
    //
    String COLUMN_FAMILY = "student";
    KsDef kd = client.describe_keyspace(KEYSPACE);
    CfDef cd = null;
    for (CfDef entry : kd.getCf_defs()) {
        if (entry.getName().equals(COLUMN_FAMILY)) {
            cd = entry;
            break;
        }
    }
    System.out.println(cd.getName());
    client.system_update_column_family(cd);// InvalidRequestException(why:student
    // already exists in keyspace mock)

    System.out.println("modify column family [" + COLUMN_FAMILY + "]");
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * getting a column
 *
 * @param client
 * @param keyspace
 * @param columnFamily
 * @return
 */
protected static ColumnDef getColumn(Cassandra.Client client,
        String keyspace, String columnFamily, String column) {
    ColumnDef result = null;
    //
    try {
        CfDef cd = getColumnFamily(client, keyspace, columnFamily);
        for (ColumnDef entry : cd.getColumn_metadata()) {
            if (new String(entry.getName()).equals(column)) {
                result = entry;
                break;
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return result;
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * modifying a column family to an existing keyspace
 *
 * @throws Exception
 */
@Test
public void modifyColumn() throws Exception {
    String KEYSPACE = "mock";
    client.set_keyspace(KEYSPACE);
    //
    String COLUMN_FAMILY = "student";
    CfDef cd = getColumnFamily(client, KEYSPACE, COLUMN_FAMILY);
    System.out.println(cd.getName());
    //
    String COLUMN = "grad";
    ColumnDef columnDef = getColumn(client, KEYSPACE, COLUMN_FAMILY, COLUMN);
    System.out.println(new String(columnDef.getName()));

    // TODO

    System.out.println("modify column [" + COLUMN + "]");
}
项目:scylla-tools-java    文件:ThriftCompatibilityTest.java   
@Test // test for CASSANDRA-8178
public void testNonTextComparator() throws Throwable
{
    ColumnDef column = new ColumnDef();
    column.setName(bytes(42))
          .setValidation_class(UTF8Type.instance.toString());

    CfDef cf = new CfDef("thriftcompat", "JdbcInteger");
    cf.setColumn_type("Standard")
      .setComparator_type(Int32Type.instance.toString())
      .setDefault_validation_class(UTF8Type.instance.toString())
      .setKey_validation_class(BytesType.instance.toString())
      .setColumn_metadata(Collections.singletonList(column));

    SchemaLoader.createKeyspace("thriftcompat", KeyspaceParams.simple(1), ThriftConversion.fromThrift(cf));

    // the comparator is IntegerType, and there is a column named 42 with a UTF8Type validation type
    execute("INSERT INTO \"thriftcompat\".\"JdbcInteger\" (key, \"42\") VALUES (0x00000001, 'abc')");
    execute("UPDATE \"thriftcompat\".\"JdbcInteger\" SET \"42\" = 'abc' WHERE key = 0x00000001");
    execute("DELETE \"42\" FROM \"thriftcompat\".\"JdbcInteger\" WHERE key = 0x00000000");
    UntypedResultSet results = execute("SELECT key, \"42\" FROM \"thriftcompat\".\"JdbcInteger\"");
    assertEquals(1, results.size());
    UntypedResultSet.Row row = results.iterator().next();
    assertEquals(ByteBufferUtil.bytes(1), row.getBytes("key"));
    assertEquals("abc", row.getString("42"));
}
项目:GraphTrek    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:learning-hadoop    文件:CassandraColumnMetaData.java   
/**
 * Static utility routine that returns a list of column families that exist in
 * the keyspace encapsulated in the supplied connection
 * 
 * @param conn the connection to use
 * @return a list of column families (tables)
 * @throws Exception if a problem occurs
 */
public static List<String> getColumnFamilyNames(CassandraConnection conn)
    throws Exception {

  KsDef keySpace = conn.describeKeyspace();
  List<CfDef> colFams = null;
  if (keySpace != null) {
    colFams = keySpace.getCf_defs();
  } else {
    throw new Exception(BaseMessages.getString(PKG,
        "CassandraColumnMetaData.Error.UnableToGetMetaDataForKeyspace",
        conn.m_keyspaceName));
  }

  List<String> colFamNames = new ArrayList<String>();
  for (CfDef fam : colFams) {
    colFamNames.add(fam.getName());
  }

  return colFamNames;
}
项目:Cassandra-Wasef    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:stratio-cassandra    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:cassandra-cqlMod    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:wso2-cassandra    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:cassandra-trunk    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:cassandra-1.2.16    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, Iterable<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:Doradus    文件:CassandraSchemaMgr.java   
/**
 * Return true if the given store name currently exists in the given keyspace. This
 * method can be used with a connection connected to any keyspace.
 * 
 * @param dbConn    Database connection to use.
 * @param cfName    Candidate ColumnFamily name.
 * @return          True if the CF exists in the database.
 */
public boolean columnFamilyExists(DBConn dbConn, String keyspace, String cfName) {
    KsDef ksDef = null;
    try {
        ksDef = dbConn.getClientSession().describe_keyspace(keyspace);
    } catch (Exception ex) {
        throw new RuntimeException("Failed to get keyspace definition for '" + keyspace + "'", ex);
    }

    List<CfDef> cfDefList = ksDef.getCf_defs();
    for (CfDef cfDef : cfDefList) {
        if (cfDef.getName().equals(cfName)) {
            return true;
        }
    }
    return false;
}
项目:Cassandra-KVPM    文件:KSMetaData.java   
public org.apache.cassandra.db.migration.avro.KsDef deflate()
{
    org.apache.cassandra.db.migration.avro.KsDef ks = new org.apache.cassandra.db.migration.avro.KsDef();
    ks.name = new Utf8(name);
    ks.strategy_class = new Utf8(strategyClass.getName());
    if (strategyOptions != null)
    {
        ks.strategy_options = new HashMap<CharSequence, CharSequence>();
        for (Map.Entry<String, String> e : strategyOptions.entrySet())
        {
            ks.strategy_options.put(new Utf8(e.getKey()), new Utf8(e.getValue()));
        }
    }
    ks.cf_defs = SerDeUtils.createArray(cfMetaData.size(), org.apache.cassandra.db.migration.avro.CfDef.SCHEMA$);
    for (CFMetaData cfm : cfMetaData.values())
        ks.cf_defs.add(cfm.deflate());

    ks.durable_writes = durable_writes;

    return ks;
}
项目:Cassandra-KVPM    文件:CliCompiler.java   
public static String getColumnFamily(String cfName, List<CfDef> cfDefs)
{
    int matches = 0;
    String lastMatchedName = "";

    for (CfDef cfDef : cfDefs)
    {
        if (cfDef.name.equals(cfName))
        {
            return cfName;
        }
        else if (cfDef.name.toUpperCase().equals(cfName.toUpperCase()))
        {
            lastMatchedName = cfDef.name;
            matches++;
        }
    }

    if (matches > 1 || matches == 0)
        throw new RuntimeException(cfName + " not found in current keyspace.");

    return lastMatchedName;
}
项目:Rapture    文件:CassandraBase.java   
public void ensureStandardCF(String cfName) throws InvalidRequestException, TException, UnavailableException, TimedOutException,
        SchemaDisagreementException {
    KsDef keyspace = getKeyspace(keySpace);
    log.info(String.format("Ensuring standard cf:%s", cfName));
    for (CfDef cfdef : keyspace.getCf_defs()) {
        if (cfdef.getName().equals(cfName)) {
            return;
        }
    }

    String cql = "CREATE TABLE %s (KEY text PRIMARY KEY) WITH comparator=text";
    executeCQL(String.format(cql, cfName));

}
项目:cassandra-kmean    文件:KSMetaData.java   
public KsDef toThrift()
{
    List<CfDef> cfDefs = new ArrayList<>(cfMetaData.size());
    for (CFMetaData cfm : cfMetaData().values())
    {
        // Don't expose CF that cannot be correctly handle by thrift; see CASSANDRA-4377 for further details
        if (cfm.isThriftCompatible())
            cfDefs.add(cfm.toThrift());
    }
    KsDef ksdef = new KsDef(name, strategyClass.getName(), cfDefs);
    ksdef.setStrategy_options(strategyOptions);
    ksdef.setDurable_writes(durableWrites);

    return ksdef;
}
项目:cassandra-kmean    文件:CFMetaData.java   
/** applies implicit defaults to cf definition. useful in updates */
private static void applyImplicitDefaults(org.apache.cassandra.thrift.CfDef cf_def)
{
    if (!cf_def.isSetComment())
        cf_def.setComment("");
    if (!cf_def.isSetMin_compaction_threshold())
        cf_def.setMin_compaction_threshold(CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD);
    if (!cf_def.isSetMax_compaction_threshold())
        cf_def.setMax_compaction_threshold(CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD);
    if (cf_def.compaction_strategy == null)
        cf_def.compaction_strategy = DEFAULT_COMPACTION_STRATEGY_CLASS.getSimpleName();
    if (cf_def.compaction_strategy_options == null)
        cf_def.compaction_strategy_options = Collections.emptyMap();
    if (!cf_def.isSetCompression_options())
    {
        cf_def.setCompression_options(new HashMap<String, String>()
        {{
            if (DEFAULT_COMPRESSOR != null)
                put(CompressionParameters.SSTABLE_COMPRESSION, DEFAULT_COMPRESSOR);
        }});
    }
    if (!cf_def.isSetDefault_time_to_live())
        cf_def.setDefault_time_to_live(CFMetaData.DEFAULT_DEFAULT_TIME_TO_LIVE);
    if (!cf_def.isSetDclocal_read_repair_chance())
        cf_def.setDclocal_read_repair_chance(CFMetaData.DEFAULT_DCLOCAL_READ_REPAIR_CHANCE);

    // if index_interval was set, use that for the min_index_interval default
    if (!cf_def.isSetMin_index_interval())
    {
        if (cf_def.isSetIndex_interval())
            cf_def.setMin_index_interval(cf_def.getIndex_interval());
        else
            cf_def.setMin_index_interval(CFMetaData.DEFAULT_MIN_INDEX_INTERVAL);
    }
    if (!cf_def.isSetMax_index_interval())
    {
        // ensure the max is at least as large as the min
        cf_def.setMax_index_interval(Math.max(cf_def.min_index_interval, CFMetaData.DEFAULT_MAX_INDEX_INTERVAL));
    }
}
项目:cassandra-kmean    文件:CliUtils.java   
/**
 * Returns set of column family names in specified keySpace.
 * @param keySpace - keyspace definition to get column family names from.
 * @return Set - column family names
 */
public static Set<String> getCfNamesByKeySpace(KsDef keySpace)
{
    Set<String> names = new LinkedHashSet<String>();

    for (CfDef cfDef : keySpace.getCf_defs())
    {
        names.add(cfDef.getName());
    }

    return names;
}
项目:cassandra-kmean    文件:CFMetaDataTest.java   
@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));
}
项目:ACaZoo    文件:KSMetaData.java   
public KsDef toThrift()
{
    List<CfDef> cfDefs = new ArrayList<CfDef>(cfMetaData.size());
    for (CFMetaData cfm : cfMetaData().values())
    {
        // Don't expose CF that cannot be correctly handle by thrift; see CASSANDRA-4377 for further details
        if (cfm.isThriftCompatible())
            cfDefs.add(cfm.toThrift());
    }
    KsDef ksdef = new KsDef(name, strategyClass.getName(), cfDefs);
    ksdef.setStrategy_options(strategyOptions);
    ksdef.setDurable_writes(durableWrites);

    return ksdef;
}
项目:ACaZoo    文件:CliUtils.java   
/**
 * Returns set of column family names in specified keySpace.
 * @param keySpace - keyspace definition to get column family names from.
 * @return Set - column family names
 */
public static Set<String> getCfNamesByKeySpace(KsDef keySpace)
{
    Set<String> names = new LinkedHashSet<String>();

    for (CfDef cfDef : keySpace.getCf_defs())
    {
        names.add(cfDef.getName());
    }

    return names;
}
项目:ACaZoo    文件:CFMetaDataTest.java   
@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(thriftCfDef.column_metadata, converted.column_metadata);
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * list all keyspaces
 *
 * @throws Exception
 */
@Test
// 50 times: 982 mills.
public void listKeyspaces() throws Exception {
    int count = 50;
    //
    long beg = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        TTransport ttransport = createTFramedTransport();
        TProtocol tprotocol = createTBinaryProtocol(ttransport);
        Cassandra.Client client = createClient(tprotocol);
        System.out.println(client);
        //
        List<KsDef> kds = client.describe_keyspaces();
        for (KsDef kd : kds) {
            StringBuilder buffer = new StringBuilder();
            buffer.append("[");
            buffer.append(kd.getName());
            buffer.append("] ");
            List<CfDef> cds = kd.getCf_defs();
            int size = cds.size();
            for (int j = 0; j < size; j++) {
                buffer.append(cds.get(j).getName());
                if (j < size - 1) {
                    buffer.append(", ");
                }
            }
            //
            System.out.println(buffer);
        }
        ttransport.close();

    }
    long end = System.currentTimeMillis();
    System.out.println(count + " times: " + (end - beg) + " mills. ");
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * list all column familys
 *
 * @throws Exception
 */
@Test
public void listColumnFamilys() throws Exception {
    long beg = System.currentTimeMillis();
    //
    String KEYSPACE = "UIH";
    client.set_keyspace(KEYSPACE);
    //
    KsDef kd = client.describe_keyspace(KEYSPACE);
    List<CfDef> result = kd.getCf_defs();
    for (CfDef cd : result) {
        StringBuilder buffer = new StringBuilder();
        buffer.append("[");
        buffer.append(cd.getName());
        buffer.append("] ");
        //
        List<ColumnDef> cols = cd.getColumn_metadata();
        int size = cols.size();
        int i = 0;
        for (ColumnDef column : cols) {
            buffer.append(ByteHelper.toString(column.getName()));
            if (i < size - 1) {
                buffer.append(", ");
            }
            i++;
        }
        //
        System.out.println(buffer);
    }
    long end = System.currentTimeMillis();
    //
    System.out.println((end - beg) + " at mills.");
}
项目:openyu-commons    文件:CassandraThriftDDLTest.java   
/**
 * list all columns
 *
 * @throws Exception
 */
@Test
public void listColumns() throws Exception {

    String KEYSPACE = "mock";
    String COLUMN_FAMILY = "student";
    CfDef cd = getColumnFamily(client, KEYSPACE, COLUMN_FAMILY);
    System.out.println(cd.getColumn_metadata());
}
项目:openyu-commons    文件:CtDataSourceImplTest.java   
@Test
// 50 times: 527 mills.
public void listKeyspaces() throws Exception {
    int count = 50;
    //
    long beg = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        TTransport ttransport = ctDataSource.getTTransport();
        TProtocol tprotocol = new TBinaryProtocol(ttransport);
        Cassandra.Client client = new Cassandra.Client(tprotocol);
        //
        List<KsDef> kds = client.describe_keyspaces();
        for (KsDef kd : kds) {
            StringBuilder buffer = new StringBuilder();
            buffer.append("[");
            buffer.append(kd.getName());
            buffer.append("] ");
            kd.getCf_defs();
            List<CfDef> cds = kd.getCf_defs();
            for (int j = 0; j < cds.size(); j++) {
                buffer.append(cds.get(j).getName());
                if (j < cds.size() - 1) {
                    buffer.append(", ");
                }
            }
            //
            System.out.println(buffer);
        }
        ttransport.close();
    }
    long end = System.currentTimeMillis();
    System.out.println(count + " times: " + (end - beg) + " mills. ");
}
项目:openyu-commons    文件:CtSessionFactoryImplTest.java   
@Test
// 50 times: 597 mills.
public void listKeyspaces() throws Exception {
    int count = 50;
    //
    long beg = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        CtSession ctSession = ctSessionFactory.openSession();
        System.out.println(ctSession);
        //
        List<KsDef> kds = ctSession.describe_keyspaces();
        for (KsDef kd : kds) {
            StringBuilder buffer = new StringBuilder();
            buffer.append("[");
            buffer.append(kd.getName());
            buffer.append("] ");
            List<CfDef> cds = kd.getCf_defs();
            int size = cds.size();
            for (int j = 0; j < size; j++) {
                buffer.append(cds.get(j).getName());
                if (j < size - 1) {
                    buffer.append(", ");
                }
            }
            //
            System.out.println(buffer);
        }
        ctSessionFactory.closeSession();
    }
    long end = System.currentTimeMillis();
    System.out.println(count + " times: " + (end - beg) + " mills. ");
}
项目:scylla-tools-java    文件:ThriftCompatibilityTest.java   
@Test // test for CASSANDRA-9867
public void testDropCompactStaticColumn()
{
    ColumnDef column1 = new ColumnDef();
    column1.setName(bytes(42))
          .setValidation_class(UTF8Type.instance.toString());

    ColumnDef column2 = new ColumnDef();
    column2.setName(bytes(25))
           .setValidation_class(UTF8Type.instance.toString());

    CfDef cf = new CfDef("thriftks", "staticcompact");
    cf.setColumn_type("Standard")
      .setComparator_type(Int32Type.instance.toString())
      .setDefault_validation_class(UTF8Type.instance.toString())
      .setKey_validation_class(BytesType.instance.toString())
      .setColumn_metadata(Arrays.asList(column1, column2));

    SchemaLoader.createKeyspace("thriftks", KeyspaceParams.simple(1), ThriftConversion.fromThrift(cf));
    CFMetaData cfm = Schema.instance.getCFMetaData("thriftks", "staticcompact");

    // assert the both columns are in the metadata
    assertTrue(cfm.getColumnMetadata().containsKey(bytes(42)));
    assertTrue(cfm.getColumnMetadata().containsKey(bytes(25)));

    // remove column2
    cf.setColumn_metadata(Collections.singletonList(column1));
    MigrationManager.announceColumnFamilyUpdate(ThriftConversion.fromThriftForUpdate(cf, cfm), true);

    // assert that it's gone from metadata
    assertTrue(cfm.getColumnMetadata().containsKey(bytes(42)));
    assertFalse(cfm.getColumnMetadata().containsKey(bytes(25)));
}
项目:scylla-tools-java    文件:CFMetaDataTest.java   
@Test
public void testThriftConversion() throws Exception
{
    CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName())
                             .setComment("Test comment")
                             .setColumn_metadata(columnDefs)
                             .setKeyspace(KEYSPACE1)
                             .setName(CF_STANDARD1);

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

    CfDef thriftCfDef = new CfDef();
    thriftCfDef.keyspace = KEYSPACE1;
    thriftCfDef.name = CF_STANDARD1;
    thriftCfDef.default_validation_class = cfDef.default_validation_class;
    thriftCfDef.comment = cfDef.comment;
    thriftCfDef.column_metadata = new ArrayList<>();
    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 = columnDef.getIndex_type();
        if (columnDef.isSetIndex_options())
            c.setIndex_options(columnDef.getIndex_options());
        thriftCfDef.column_metadata.add(c);
    }

    CfDef converted = ThriftConversion.toThrift(cfMetaData);

    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));
}
项目:scylla-tools-java    文件:SchemaKeyspaceTest.java   
@Test
public void testThriftConversion() throws Exception
{
    CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName())
                             .setComment("Test comment")
                             .setColumn_metadata(columnDefs)
                             .setKeyspace(KEYSPACE1)
                             .setName(CF_STANDARD1);

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

    CfDef thriftCfDef = new CfDef();
    thriftCfDef.keyspace = KEYSPACE1;
    thriftCfDef.name = CF_STANDARD1;
    thriftCfDef.default_validation_class = cfDef.default_validation_class;
    thriftCfDef.comment = cfDef.comment;
    thriftCfDef.column_metadata = new ArrayList<>();
    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 = ThriftConversion.toThrift(cfMetaData);

    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));
}
项目:GraphTrek    文件:CqlNativeStorage.java   
/** get next row */
public Tuple getNext() throws IOException
{
    try
    {
        // 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())
        {
            ColumnDef cdef = itera.next();
            ByteBuffer columnValue = row.getBytesUnsafe(ByteBufferUtil.string(cdef.name.duplicate()));
            if (columnValue != null)
            {
                Cell cell = new BufferCell(CellNames.simpleDense(cdef.name), columnValue);
                AbstractType<?> validator = getValidatorMap(cfDef).get(cdef.name);
                setTupleValue(tuple, i, cqlColumnToObj(cell, cfDef), validator);
            }
            else
                tuple.set(i, null);
            i++;
        }
        return tuple;
    }
    catch (InterruptedException e)
    {
        throw new IOException(e.getMessage());
    }
}
项目:GraphTrek    文件:KSMetaData.java   
public KsDef toThrift()
{
    List<CfDef> cfDefs = new ArrayList<>(cfMetaData.size());
    for (CFMetaData cfm : cfMetaData().values())
    {
        // Don't expose CF that cannot be correctly handle by thrift; see CASSANDRA-4377 for further details
        if (cfm.isThriftCompatible())
            cfDefs.add(cfm.toThrift());
    }
    KsDef ksdef = new KsDef(name, strategyClass.getName(), cfDefs);
    ksdef.setStrategy_options(strategyOptions);
    ksdef.setDurable_writes(durableWrites);

    return ksdef;
}