本文整理汇总了Java中org.apache.cassandra.thrift.ColumnDef类的典型用法代码示例。如果您正苦于以下问题:Java ColumnDef类的具体用法?Java ColumnDef怎么用?Java ColumnDef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ColumnDef类属于org.apache.cassandra.thrift包,在下文中一共展示了ColumnDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromThrift
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
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);
}
示例2: getColumn
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
/**
* 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;
}
示例3: modifyColumn
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
/**
* 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 + "]");
}
示例4: testNonTextComparator
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
@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"));
}
示例5: fromThrift
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
public static ColumnDefinition fromThrift(CFMetaData cfm, ColumnDef thriftColumnDef) throws SyntaxException, ConfigurationException
{
// For super columns, the componentIndex is 1 because the ColumnDefinition applies to the column component.
Integer componentIndex = cfm.isSuper() ? 1 : null;
AbstractType<?> comparator = cfm.getComponentComparator(componentIndex, Kind.REGULAR);
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));
}
ColumnDefinition cd = new ColumnDefinition(cfm,
ByteBufferUtil.clone(thriftColumnDef.name),
TypeParser.parse(thriftColumnDef.validation_class),
componentIndex,
Kind.REGULAR);
cd.setIndex(thriftColumnDef.index_name,
thriftColumnDef.index_type == null ? null : IndexType.valueOf(thriftColumnDef.index_type.name()),
thriftColumnDef.index_options);
return cd;
}
示例6: getIndexMetadata
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
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 );
}
示例7: toThrift
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
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;
}
示例8: testThriftConversion
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
@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));
}
示例9: toThrift
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
public static List<ColumnDef> toThrift(Map<ByteBuffer, ColumnDefinition> columns)
{
List<ColumnDef> thriftDefs = new ArrayList<>(columns.size());
for (ColumnDefinition def : columns.values())
if (def.type == ColumnDefinition.Type.REGULAR)
thriftDefs.add(def.toThrift());
return thriftDefs;
}
示例10: fromThrift
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
public static ColumnDefinition fromThrift(ColumnDef thriftColumnDef, boolean isSuper) throws SyntaxException, ConfigurationException
{
// For super columns, the componentIndex is 1 because the ColumnDefinition applies to the column component.
return new ColumnDefinition(ByteBufferUtil.clone(thriftColumnDef.name),
TypeParser.parse(thriftColumnDef.validation_class),
thriftColumnDef.index_type == null ? null : IndexType.valueOf(thriftColumnDef.index_type.name()),
thriftColumnDef.index_options,
thriftColumnDef.index_name,
isSuper ? 1 : null,
Type.REGULAR);
}
示例11: testThriftConversion
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
@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);
}
示例12: listColumnFamilys
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
/**
* 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.");
}
示例13: testDropCompactStaticColumn
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
@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)));
}
示例14: testThriftConversion
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
@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));
}
示例15: testThriftConversion
import org.apache.cassandra.thrift.ColumnDef; //导入依赖的package包/类
@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));
}