当前位置: 首页>>代码示例>>Java>>正文


Java ColumnOrSuperColumn类代码示例

本文整理汇总了Java中org.apache.cassandra.thrift.ColumnOrSuperColumn的典型用法代码示例。如果您正苦于以下问题:Java ColumnOrSuperColumn类的具体用法?Java ColumnOrSuperColumn怎么用?Java ColumnOrSuperColumn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ColumnOrSuperColumn类属于org.apache.cassandra.thrift包,在下文中一共展示了ColumnOrSuperColumn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
/**
 * get 讀取1個column
 *
 * @throws Exception
 */
@Test
public void get() throws Exception {
	String KEYSPACE = "mock";
	client.set_keyspace(KEYSPACE);

	// 讀取1個column
	String COLUMN_FAMILY = "student";
	ColumnPath columnPath = new ColumnPath(COLUMN_FAMILY);
	//
	String COLUMN = "grad";
	columnPath.setColumn(ByteBufferHelper.toByteBuffer(COLUMN));

	String ROW_KEY = "Jack";
	// key, column_path, consistency_level
	ColumnOrSuperColumn cos = client.get(
			ByteBufferHelper.toByteBuffer(ROW_KEY), columnPath,
			ConsistencyLevel.ONE);// NotFoundException

	Column column = cos.getColumn();
	System.out.println(ROW_KEY + ", "
			+ ByteHelper.toString(column.getName()) + ": "
			+ ByteHelper.toString(column.getValue()) + ", "
			+ column.getTimestamp());
	// Jack, grad: 5, 1380932164492000
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:31,代码来源:CassandraThriftDMLTest.java

示例2: getColumnValue

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
private String getColumnValue(String ks, String cf, String colName, String key, String validator)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, IOException
{
    Cassandra.Client client = getClient();
    client.set_keyspace(ks);

    ByteBuffer key_user_id = ByteBufferUtil.bytes(key);

    long timestamp = System.currentTimeMillis();
    ColumnPath cp = new ColumnPath(cf);
    ColumnParent par = new ColumnParent(cf);
    cp.column = ByteBufferUtil.bytes(colName);

    // read
    ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE);
    return parseType(validator).getString(got.getColumn().value);
}
 
开发者ID:wso2,项目名称:wso2-cassandra,代码行数:18,代码来源:ThriftColumnFamilyTest.java

示例3: getMutation

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
private Mutation getMutation(String columnName, Object value, long timestamp) {
    byte[] columnNameBytes;
    try {
        columnNameBytes = columnName.getBytes("UTF-8");
    }
    catch (UnsupportedEncodingException exc) {
        throw new StorageException("Unsupported character encoding for column name", exc);
    }
    byte[] valueBytes = convertValueToBytes(value);
    Column column = new Column();
    column.setName(columnNameBytes);
    column.setValue(valueBytes);
    column.setTimestamp(timestamp);
    ColumnOrSuperColumn columnOrSuperColumn = new ColumnOrSuperColumn();
    columnOrSuperColumn.setColumn(column);
    Mutation mutation = new Mutation();
    mutation.setColumn_or_supercolumn(columnOrSuperColumn);
    return mutation;
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:20,代码来源:Connection.java

示例4: getColumns

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
@Override
public List<DColumn> getColumns(String storeName, String rowKey, String startColumn, String endColumn, int count) {
    DBConn dbConn = getDBConnection();
    try {
        List<ColumnOrSuperColumn> columns = dbConn.getSlice(
                CassandraDefs.columnParent(storeName),
                CassandraDefs.slicePredicateStartEndCol(Utils.toBytes(startColumn), Utils.toBytes(endColumn), count),
                Utils.toByteBuffer(rowKey));
        List<DColumn> result = new ArrayList<>(columns.size());
        for(ColumnOrSuperColumn column: columns) {
            result.add(new DColumn(column.getColumn().getName(), column.getColumn().getValue()));
        }
        return result;
    } finally {
        returnDBConnection(dbConn);
    }
}
 
开发者ID:QSFT,项目名称:Doradus,代码行数:18,代码来源:ThriftService.java

示例5: createMutation

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
private static Mutation createMutation(byte[] colName, byte[] colValue, long timestamp) {
    if (colValue == null) {
        colValue = EMPTY_BYTES;
    }
    Column col = new Column();
    col.setName(colName);
    col.setValue(colValue);
    col.setTimestamp(timestamp);
    
    ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
    cosc.setColumn(col);
    
    Mutation mutation = new Mutation();
    mutation.setColumn_or_supercolumn(cosc);
    return mutation;
}
 
开发者ID:QSFT,项目名称:Doradus,代码行数:17,代码来源:CassandraTransaction.java

示例6: computeNext

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
@Override
protected Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>> computeNext() {
  maybeInit();
  if (rows == null) {
    return endOfData();
  }

  KeySlice ks = rows.get(0);
  SortedMap<ByteBuffer, IColumn> map = new TreeMap<ByteBuffer, IColumn>(comparator);
  for (ColumnOrSuperColumn cosc : ks.columns) {
    IColumn column = unthriftify(cosc);
    map.put(column.name(), column);
  }
  // return new Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>>(ks.key, map);
  return Pair.create(ks.key, map);
}
 
开发者ID:dvasilen,项目名称:Hive-Cassandra,代码行数:17,代码来源:ColumnFamilyWideRowRecordReader.java

示例7: QueryOneMinute

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
public List<String> QueryOneMinute(String min) {
	List<String> userList = new ArrayList<String>();
	try {
		List<ColumnOrSuperColumn> results = client.get_slice(Utils
				.toByteBuffer(min), columnParent, predicate,
				ConsistencyLevel.ONE);
		for (ColumnOrSuperColumn cc : results) {
			SuperColumn superColumn = cc.getSuper_column();
			List<Column> list = superColumn.getColumns();
			for (Column c : list) {
				String columnName = new String(c.getName(), "UTF-8");
				if (columnName.equals("username")) {
					String value = new String(c.getValue(), "UTF-8");
					if (!userList.contains(value)) {
						userList.add(value);
					}
				}
			}
		}
	} catch (Exception e) {
		System.out.println(e);
	}
	return userList;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:25,代码来源:CasTimeReader.java

示例8: QueryOneMinute

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
public List<String> QueryOneMinute(String min){
	List<String> bookList = new ArrayList<String>();
	try {
		List<ColumnOrSuperColumn> results = client.get_slice(Utils
				.toByteBuffer(min), columnParent, predicate,
				ConsistencyLevel.ONE);
		for (ColumnOrSuperColumn cc : results) {
			SuperColumn superColumn = cc.getSuper_column();
			List<Column> list = superColumn.getColumns();
			for (Column c : list) {
				String columnName = new String(c.getName(), "UTF-8");
				if (columnName.equals("bookno")) {
					String value = new String(c.getValue(), "UTF-8");
					if (!bookList.contains(value)) {
						bookList.add(value);
					}
				}
			}
		}
	} catch (Exception e) {
		System.out.println(e);
	}
	return bookList;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:25,代码来源:CasTimeBook.java

示例9: run

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
    List<CounterColumn> columns = new ArrayList<>();
    for (ByteBuffer name : select().select(settings.columns.names))
        columns.add(new CounterColumn(name, counteradd.next()));

    List<Mutation> mutations = new ArrayList<>(columns.size());
    for (CounterColumn c : columns)
    {
        ColumnOrSuperColumn cosc = new ColumnOrSuperColumn().setCounter_column(c);
        mutations.add(new Mutation().setColumn_or_supercolumn(cosc));
    }
    Map<String, List<Mutation>> row = Collections.singletonMap(type.table, mutations);

    final ByteBuffer key = getKey();
    final Map<ByteBuffer, Map<String, List<Mutation>>> record = Collections.singletonMap(key, row);

    timeWithRetry(new RunOp()
    {
        @Override
        public boolean run() throws Exception
        {
            client.batch_mutate(record, settings.command.consistencyLevel);
            return true;
        }

        @Override
        public int partitionCount()
        {
            return 1;
        }

        @Override
        public int rowCount()
        {
            return 1;
        }
    });
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:40,代码来源:ThriftCounterAdder.java

示例10: run

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
    final ColumnSelection select = select();
    final ByteBuffer key = getKey();
    final List<ByteBuffer> expect = getColumnValues(select);
    timeWithRetry(new RunOp()
    {
        @Override
        public boolean run() throws Exception
        {
            List<ColumnOrSuperColumn> row = client.get_slice(key, new ColumnParent(type.table), select.predicate(), settings.command.consistencyLevel);
            if (expect == null)
                return !row.isEmpty();
            if (row == null)
                return false;
            if (row.size() != expect.size())
                return false;
            for (int i = 0 ; i < row.size() ; i++)
                if (!row.get(i).getColumn().bufferForValue().equals(expect.get(i)))
                    return false;
            return true;
        }

        @Override
        public int partitionCount()
        {
            return 1;
        }

        @Override
        public int rowCount()
        {
            return 1;
        }
    });
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:37,代码来源:ThriftReader.java

示例11: run

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
public void run(final ThriftClient client) throws IOException
{
    final ByteBuffer key = getKey();
    final List<Column> columns = getColumns();

    List<Mutation> mutations = new ArrayList<>(columns.size());
    for (Column c : columns)
    {
        ColumnOrSuperColumn column = new ColumnOrSuperColumn().setColumn(c);
        mutations.add(new Mutation().setColumn_or_supercolumn(column));
    }
    Map<String, List<Mutation>> row = Collections.singletonMap(type.table, mutations);

    final Map<ByteBuffer, Map<String, List<Mutation>>> record = Collections.singletonMap(key, row);

    timeWithRetry(new RunOp()
    {
        @Override
        public boolean run() throws Exception
        {
            client.batch_mutate(record, settings.command.consistencyLevel);
            return true;
        }

        @Override
        public int partitionCount()
        {
            return 1;
        }

        @Override
        public int rowCount()
        {
            return 1;
        }
    });
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:38,代码来源:ThriftInserter.java

示例12: getColumnValue

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
private String getColumnValue(String ks, String cf, String colName, String key, String validator)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, IOException
{
    Cassandra.Client client = getClient();
    client.set_keyspace(ks);

    ByteBuffer key_user_id = ByteBufferUtil.bytes(key);
    ColumnPath cp = new ColumnPath(cf);
    cp.column = ByteBufferUtil.bytes(colName);

    // read
    ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE);
    return parseType(validator).getString(got.getColumn().value);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:15,代码来源:ThriftColumnFamilyTest.java

示例13: get2

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
/**
 * get 讀取所有column
 *
 * @throws Exception
 */
@Test
public void get2() throws Exception {
	String KEYSPACE = "mock";
	client.set_keyspace(KEYSPACE);

	// 讀取所有column
	String COLUMN_FAMILY = "student";
	ColumnParent columnParent = new ColumnParent(COLUMN_FAMILY);

	// 術語
	SlicePredicate predicate = new SlicePredicate();

	// 範圍
	SliceRange sliceRange = new SliceRange();
	// sliceRange.setStart(ByteBufferHelper.toByteBuffer(new byte[0]));//開始
	sliceRange.setStart(new byte[0]);// 開始
	sliceRange.setFinish(new byte[0]);// 結束
	sliceRange.setCount(100);// 筆數
	//
	predicate.setSlice_range(sliceRange);

	String ROW_KEY = "Jack";
	// 結果
	// key, column_parent, predicate, consistency_level
	List<ColumnOrSuperColumn> results = client.get_slice(
			ByteBufferHelper.toByteBuffer(ROW_KEY), columnParent,
			predicate, ConsistencyLevel.ONE);

	for (ColumnOrSuperColumn cos : results) {
		Column column = cos.getColumn();
		System.out.println(ROW_KEY + ", "
				+ ByteHelper.toString(column.getName()) + ": "
				+ ByteHelper.toString(column.getValue()) + ", "
				+ column.getTimestamp());
		// Jack, art, 87, 1380788003220
		// Jack, grad, 5, 1380788003203
		// Jack, math, 97, 1380788003214
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:45,代码来源:CassandraThriftDMLTest.java

示例14: update

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
/**
 * update
 *
 * @throws Exception
 */
@Test
public void update() throws Exception {
	String KEYSPACE = "mock";
	client.set_keyspace(KEYSPACE);

	List<Mutation> mutations = new LinkedList<Mutation>();
	// <columnFamily,mutations>
	Map<String, List<Mutation>> columnfamilyMutaions = new HashMap<String, List<Mutation>>();// keyMutations
	// <rowKey,keyMutations>
	Map<ByteBuffer, Map<String, List<Mutation>>> rowKeyMutations = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();

	long timestamp = System.nanoTime();
	//
	Column column = new Column();
	column.setName(ByteBufferHelper.toByteBuffer("grad"));
	column.setValue(ByteBufferHelper.toByteBuffer("9"));
	column.setTimestamp(timestamp);
	//
	ColumnOrSuperColumn cos = new ColumnOrSuperColumn();
	cos.setColumn(column);
	//
	Mutation mutation = new Mutation();
	mutation.setColumn_or_supercolumn(cos);
	mutations.add(mutation);

	String COLUMN_FAMILY = "student";
	columnfamilyMutaions.put(COLUMN_FAMILY, mutations);

	String ROW_KEY = "Jack";
	rowKeyMutations.put(ByteBufferHelper.toByteBuffer(ROW_KEY),
			columnfamilyMutaions);

	// mutation_map, consistency_level
	client.batch_mutate(rowKeyMutations, ConsistencyLevel.ONE);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:41,代码来源:CassandraThriftDMLTest.java

示例15: insertPOISpringTraining

import org.apache.cassandra.thrift.ColumnOrSuperColumn; //导入依赖的package包/类
private void insertPOISpringTraining() throws Exception {
	Map<ByteBuffer, Map<String, List<Mutation>>> outerMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
	List<Mutation> columnsToAdd = new ArrayList<Mutation>();

	long timestamp = System.nanoTime();
	String keyName = "Spring Training";
	Column descCol = new Column(bytes("desc"));
	Column phoneCol = new Column(bytes("phone"));

	List<Column> cols = new ArrayList<Column>();
	cols.add(descCol);
	cols.add(phoneCol);

	Map<String, List<Mutation>> innerMap = new HashMap<String, List<Mutation>>();

	Mutation columns = new Mutation();
	ColumnOrSuperColumn descCosc = new ColumnOrSuperColumn();
	SuperColumn sc = new SuperColumn();
	sc.name = bytes(CAMBRIA_NAME);
	sc.columns = cols;

	descCosc.super_column = sc;
	columns.setColumn_or_supercolumn(descCosc);

	columnsToAdd.add(columns);

	String superCFName = "PointOfInterest";
	ColumnPath cp = new ColumnPath();
	cp.column_family = superCFName;
	cp.setSuper_column(CAMBRIA_NAME.getBytes());
	cp.setSuper_columnIsSet(true);

	innerMap.put(superCFName, columnsToAdd);
	outerMap.put(bytes(keyName), innerMap);

	client.batch_mutate(outerMap, CL);

	LOG.debug("Done inserting Spring Training.");
}
 
开发者ID:lhfei,项目名称:hadoop-in-action,代码行数:40,代码来源:Prepopulate.java


注:本文中的org.apache.cassandra.thrift.ColumnOrSuperColumn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。