• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java KeySlice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: advanceToNonEmptyRow

import org.apache.cassandra.thrift.KeySlice; //导入依赖的package包/类
private void advanceToNonEmptyRow() {
  KeySlice row = m_cassandraRows.get(m_rowIndex);
  m_currentCols = row.getColumns();

  int skipSize = 0;
  while (m_currentCols.size() == skipSize
      && m_rowIndex < m_cassandraRows.size() - 1) {
    m_rowIndex++;
    row = m_cassandraRows.get(m_rowIndex);
    m_currentCols = row.getColumns();
  }

  if (m_currentCols.size() == skipSize) {
    // we've been through the batch and there are no columns in any of these
    // rows -
    // so nothing to output! Indicate this by setting currentCols to null
    m_currentCols = null;
  }
}
 
开发者ID:javachen,项目名称:learning-hadoop,代码行数:20,代码来源:CassandraInputData.java


示例2: getRows

import org.apache.cassandra.thrift.KeySlice; //导入依赖的package包/类
@Override
public List<String> getRows(String storeName, String continuationToken, int count) {
    DBConn dbConn = getDBConnection();
    try {
        List<KeySlice> keys = dbConn.getRangeSlices(
                CassandraDefs.columnParent(storeName), 
                CassandraDefs.slicePredicateStartEndCol(null, null, 1),
                CassandraDefs.keyRangeStartRow(Utils.toBytes(continuationToken), count));
        List<String> result = new ArrayList<>(keys.size());
        for(KeySlice key: keys) {
            result.add(Utils.toString(key.getKey()));
        }
        return result;
    } finally {
        returnDBConnection(dbConn);
    }
}
 
开发者ID:QSFT,项目名称:Doradus,代码行数:18,代码来源:ThriftService.java


示例3: computeNext

import org.apache.cassandra.thrift.KeySlice; //导入依赖的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


示例4: getKeyValue

import org.apache.cassandra.thrift.KeySlice; //导入依赖的package包/类
/**
 * Return the decoded key value of a row. Assumes that the supplied row comes
 * from the column family that this meta data represents!!
 * 
 * @param row a Cassandra row
 * @return the decoded key value
 * @throws KettleException if a deserializer can't be determined
 */
public Object getKeyValue(KeySlice row) throws KettleException {
  ByteBuffer key = row.bufferForKey();

  if (m_keyValidator.indexOf("BytesType") > 0) {
    return row.getKey();
  }

  return getColumnValue(key, m_keyValidator);
}
 
开发者ID:javachen,项目名称:learning-hadoop,代码行数:18,代码来源:CassandraColumnMetaData.java


示例5: convertKeySliceList

import org.apache.cassandra.thrift.KeySlice; //导入依赖的package包/类
private List<Map<String,Object>> convertKeySliceList(List<KeySlice> keySliceList, String primaryKeyName) {
    List<Map<String,Object>> rowList = new ArrayList<Map<String,Object>>();
    try {
        for (KeySlice keySlice: keySliceList) {
            List<ColumnOrSuperColumn> columnList = keySlice.getColumns();
            if (!columnList.isEmpty()) {
                byte[] keyBytes = keySlice.getKey();
                String key = new String(keyBytes, "UTF-8");
                Map<String,Object> columnMap = new HashMap<String,Object>();
                columnMap.put(primaryKeyName, key);
                for (ColumnOrSuperColumn columnOrSuperColumn: columnList) {
                    Column column = columnOrSuperColumn.getColumn();
                    byte[] columnNameBytes = column.getName();
                    String columnName = new String(columnNameBytes, "UTF-8");
                    byte[] valueBytes = column.getValue();
                    String value = new String(valueBytes, "UTF-8");
                    if (value.equals(NULL_VALUE_STRING))
                        value = null;
                    columnMap.put(columnName, value);
                }
                rowList.add(columnMap);
            }
        }
        return rowList;
    }
    catch (UnsupportedEncodingException exc) {
        throw new StorageException("Character encoding exception with key range", exc);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:30,代码来源:Connection.java


示例6: getByKey

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

	String COLUMN_FAMILY = "student";
	// 讀取整筆
	ColumnParent columnParent = new ColumnParent(COLUMN_FAMILY);
	// 術語
	SlicePredicate predicate = new SlicePredicate();

	// InvalidRequestException(why:predicate column_names and slice_range
	// may not both be present)

	// 範圍
	// SliceRange sliceRange = new SliceRange();
	// sliceRange.setStart(new byte[0]);// 開始
	// sliceRange.setFinish(new byte[0]);// 結束
	// predicate.setSlice_range(sliceRange);

	// 讀取1個column
	predicate.addToColumn_names(ByteBufferHelper.toByteBuffer("grad"));

	// key範圍
	KeyRange keyRange = new KeyRange();
	keyRange.setStart_key(new byte[0]);
	keyRange.setEnd_key(new byte[0]);
	keyRange.setCount(100);

	// 結果
	// column_parent, predicate, range, consistency_level
	List<KeySlice> results = client.get_range_slices(columnParent,
			predicate, keyRange, ConsistencyLevel.ONE);

	for (KeySlice keySlice : results) {

		for (ColumnOrSuperColumn cos : keySlice.getColumns()) {
			Column column = cos.column;
			System.out.println(ByteHelper.toString(keySlice.getKey())
					+ ", " + ByteHelper.toString(column.getName()) + ": "
					+ ByteHelper.toString(column.getValue()) + ", "
					+ column.getTimestamp());
			// Rose, grad, 4, 1380931646061000
			// Jack, art, 87, 1380933848350
			// Jack, grad, 5, 1380932164492000
			// Jack, math, 97, 1380933848305
		}
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:55,代码来源:CassandraThriftDMLTest.java


示例7: findPOIByHotel

import org.apache.cassandra.thrift.KeySlice; //导入依赖的package包/类
public List<POI> findPOIByHotel(String hotel) throws Exception {

		// /query
		SlicePredicate predicate = new SlicePredicate();
		SliceRange sliceRange = new SliceRange();
		sliceRange.setStart(hotel.getBytes());
		sliceRange.setFinish(hotel.getBytes());
		predicate.setSlice_range(sliceRange);

		// read all columns in the row
		String scFamily = "PointOfInterest";
		ColumnParent parent = new ColumnParent(scFamily);

		KeyRange keyRange = new KeyRange();
		keyRange.start_key = bytes("");
		keyRange.end_key = bytes("");

		List<POI> pois = new ArrayList<POI>();

		// instead of a simple list, we get a map whose keys are row keys
		// and the values the list of columns returned for each
		// only row key + first column are indexed
		Connector cl = new Connector();
		Cassandra.Client client = cl.connect();
		List<KeySlice> slices = client.get_range_slices(parent, predicate, keyRange, CL);

		for (KeySlice slice : slices) {
			List<ColumnOrSuperColumn> cols = slice.columns;

			POI poi = new POI();
			poi.name = new String(ByteBufferUtil.string(slice.key));

			for (ColumnOrSuperColumn cosc : cols) {
				SuperColumn sc = cosc.super_column;

				List<Column> colsInSc = sc.columns;

				for (Column c : colsInSc) {
					String colName = new String(c.name.array(), UTF8);
					if (colName.equals("desc")) {
						poi.desc = new String(c.value.array(), UTF8);
					}
					if (colName.equals("phone")) {
						poi.phone = new String(c.value.array(), UTF8);
					}
				}

				LOG.debug("Found something neat nearby: " + poi.name + ". \nDesc: " + poi.desc + ". \nPhone: "
						+ poi.phone);
				pois.add(poi);
			}
		}

		cl.close();
		return pois;
	}
 
开发者ID:lhfei,项目名称:hadoop-in-action,代码行数:57,代码来源:HotelApp.java


示例8: findHotelByCity

import org.apache.cassandra.thrift.KeySlice; //导入依赖的package包/类
public List<Hotel> findHotelByCity(String city, String state) throws Exception {

		LOG.debug("Seaching for hotels in " + city + ", " + state);

		String key = city + ":" + state.toUpperCase();

		// /query
		SlicePredicate predicate = new SlicePredicate();
		SliceRange sliceRange = new SliceRange();
		sliceRange.setStart(new byte[0]);
		sliceRange.setFinish(new byte[0]);
		predicate.setSlice_range(sliceRange);

		// read all columns in the row
		String columnFamily = "HotelByCity";
		ColumnParent parent = new ColumnParent(columnFamily);

		KeyRange keyRange = new KeyRange();
		keyRange.setStart_key(key.getBytes());
		keyRange.setEnd_key("".getBytes()); // just outside lexical range
		keyRange.count = 5;

		Connector cl = new Connector();
		Cassandra.Client client = cl.connect();
		List<KeySlice> keySlices = client.get_range_slices(parent, predicate, keyRange, CL);

		List<Hotel> results = new ArrayList<Hotel>();

		for (KeySlice ks : keySlices) {
			List<ColumnOrSuperColumn> coscs = ks.columns;
			LOG.debug(new String("Using key " + ks.key));

			for (ColumnOrSuperColumn cs : coscs) {

				Hotel hotel = new Hotel();
				hotel.name = ByteBufferUtil.string(cs.column.name);
				hotel.city = city;
				hotel.state = state;

				results.add(hotel);
				LOG.debug("Found hotel result for " + hotel.name);
			}
		}
		// /end query
		cl.close();

		return results;
	}
 
开发者ID:lhfei,项目名称:hadoop-in-action,代码行数:49,代码来源:HotelApp.java


示例9: maybeInit

import org.apache.cassandra.thrift.KeySlice; //导入依赖的package包/类
private void maybeInit() {
  // check if we need another row
  if (rows != null && columnsRead < rowPageSize) {
    columnsRead = 0;
    startToken = partitioner.getTokenFactory().toString(partitioner.getToken(rows.get(0).key));
    predicate.getSlice_range().setStart(startSlicePredicate);
    rows = null;
    prevStartSlice = null;
    totalRead++;
  }

  if (startToken == null) {
    startToken = split.getStartToken();
  } else if (startToken.equals(split.getEndToken()) && rows == null) {
    // reached end of the split
    return;
  }

  KeyRange keyRange = new KeyRange(batchRowCount)
                            .setStart_token(startToken)
                            .setEnd_token(split.getEndToken());
  try {
    rows = client.get_range_slices(new ColumnParent(cfName),
                                           predicate,
                                           keyRange,
                                           consistencyLevel);

    // nothing new? reached the end
    if (rows.isEmpty()) {
      rows = null;
      return;
    }

    //detect infinite loop
    if (prevStartSlice != null && ByteBufferUtil.compareUnsigned(prevStartSlice, predicate.slice_range.start) == 0) {
        rows = null;
        return;
    }

    // prepare for the next slice to be read
    KeySlice row = rows.get(0);

    if (row.getColumnsSize() > 0) {

      ColumnOrSuperColumn cosc = row.getColumns().get(row.getColumnsSize() - 1);

      prevStartSlice = predicate.slice_range.start;

      //prepare next slice
      if (cosc.column != null) {
        predicate.slice_range.start = cosc.column.name;
      }

      if (cosc.super_column != null) {
        predicate.slice_range.start = cosc.super_column.name;
      }

      if (cosc.counter_column != null) {
        predicate.slice_range.start = cosc.counter_column.name;
      }

      if (cosc.counter_super_column != null) {
        predicate.slice_range.start = cosc.counter_super_column.name;
      }

      columnsRead = row.getColumnsSize();

      //If we've hit the max columns then rm the last column
      //to make sure we don't know where to start next without overlap
      if (columnsRead == rowPageSize) {
        row.getColumns().remove(columnsRead - 1);
      }
    } 
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:dvasilen,项目名称:Hive-Cassandra,代码行数:78,代码来源:ColumnFamilyWideRowRecordReader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EntryPlus3类代码示例发布时间:2022-05-23
下一篇:
Java AmazonCloudSearchClient类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap