public MultigetSliceQueryImpl(
      Keyspace ks, ColumnFamily<K, T, N> cf, List<NamedColumn<K, T, N, ?>> columns) {
    N[] columnNames = QueryUtils.getColumnNamesUnresolved(cf, columns);

    wrappedQuery =
        HFactory.createMultigetSliceQuery(
                ks, cf.getKeySerializer(), cf.getColumnNameSerializer(), DummySerializer.get())
            .setColumnFamily(cf.getName())
            .setColumnNames(columnNames);
  }
  public MultigetSliceQueryImpl(
      Keyspace ks,
      ColumnFamily<K, T, N> cf,
      ColumnRange<K, T, N, ?> columnRange,
      N start,
      N finish,
      boolean reversed,
      int count) {
    QueryUtils.checkColumnBelongsToColumnFamily(cf, columnRange);

    wrappedQuery =
        HFactory.createMultigetSliceQuery(
                ks, cf.getKeySerializer(), cf.getColumnNameSerializer(), DummySerializer.get())
            .setColumnFamily(cf.getName())
            .setRange(start, finish, reversed, count);
  }
  public void runQuery() throws IOException {
    MultigetSliceQuery<DataPointsRowKey, Integer, ByteBuffer> msliceQuery =
        HFactory.createMultigetSliceQuery(
            m_keyspace, ROW_KEY_SERIALIZER, IntegerSerializer.get(), ByteBufferSerializer.get());

    msliceQuery.setColumnFamily(m_columnFamily);
    msliceQuery.setKeys(m_rowKeys);
    if (m_descending) msliceQuery.setRange(m_endTime, m_startTime, true, m_multiRowReadSize);
    else msliceQuery.setRange(m_startTime, m_endTime, false, m_multiRowReadSize);

    Rows<DataPointsRowKey, Integer, ByteBuffer> rows = msliceQuery.execute().get();

    List<Row<DataPointsRowKey, Integer, ByteBuffer>> unfinishedRows =
        new ArrayList<Row<DataPointsRowKey, Integer, ByteBuffer>>();

    for (Row<DataPointsRowKey, Integer, ByteBuffer> row : rows) {
      List<HColumn<Integer, ByteBuffer>> columns = row.getColumnSlice().getColumns();
      if (!m_limit && columns.size() == m_multiRowReadSize) unfinishedRows.add(row);

      writeColumns(row.getKey(), columns);
    }

    // Iterate through the unfinished rows and get the rest of the data.
    // todo: use multiple threads to retrieve this data
    for (Row<DataPointsRowKey, Integer, ByteBuffer> unfinishedRow : unfinishedRows) {
      DataPointsRowKey key = unfinishedRow.getKey();

      SliceQuery<DataPointsRowKey, Integer, ByteBuffer> sliceQuery =
          HFactory.createSliceQuery(
              m_keyspace, ROW_KEY_SERIALIZER, IntegerSerializer.get(), ByteBufferSerializer.get());

      sliceQuery.setColumnFamily(m_columnFamily);
      sliceQuery.setKey(key);

      List<HColumn<Integer, ByteBuffer>> columns = unfinishedRow.getColumnSlice().getColumns();

      do {
        Integer lastTime = columns.get(columns.size() - 1).getName();

        if (m_descending) sliceQuery.setRange(lastTime - 1, m_startTime, true, m_singleRowReadSize);
        else sliceQuery.setRange(lastTime + 1, m_endTime, false, m_singleRowReadSize);

        columns = sliceQuery.execute().get().getColumns();
        writeColumns(key, columns);
      } while (columns.size() == m_singleRowReadSize);
    }
  }
Example #4
0
 public Rows<K, N, V> multiGetSliceRange(
     List<K> keys, N startName, N endName, boolean reverse, int size) {
   this.policy.loadConsistencyLevelForRead(columnFamily);
   Rows<K, N, V> result;
   try {
     result =
         HFactory.createMultigetSliceQuery(
                 keyspace, keySerializer, columnNameSerializer, valueSerializer)
             .setColumnFamily(columnFamily)
             .setKeys(keys)
             .setRange(startName, endName, reverse, size)
             .execute()
             .get();
   } catch (Throwable throwable) {
     throw new RuntimeException(throwable);
   } finally {
     this.policy.reinitDefaultConsistencyLevel();
   }
   return result;
 }
  public List<byte[]> scan(
      String startKey, String columnFamilyName, int maxRows) // throws IOException
      {
    List<byte[]> results = new ArrayList<byte[]>();

    MultigetSliceQuery<String, String, byte[]> multigetSliceQuery =
        HFactory.createMultigetSliceQuery(
            this._keyspace,
            StringSerializer.get(),
            StringSerializer.get(),
            BytesArraySerializer.get());
    multigetSliceQuery.setColumnFamily(columnFamilyName);
    multigetSliceQuery.setKeys(startKey);
    multigetSliceQuery.setRange(startKey, "", false, maxRows);
    QueryResult<Rows<String, String, byte[]>> queryResult = multigetSliceQuery.execute();
    Rows<String, String, byte[]> rows = queryResult.get();
    for (Row<String, String, byte[]> row : rows) {
      boolean fail = true;
      HColumn<String, byte[]> column = row.getColumnSlice().getColumnByName(DEFAULT_COLUMN_NAME);
      if (column != null) {
        byte[] value = column.getValue();

        if (value != null) {
          results.add(value);
          fail = false;
          /*
          if (this._debug)
          {
          	String key = rows.getKey();

          	if (this._failMap.containsKey(key))
          	{
          		System.out.println("Successful scan for previously failed key: " + key);
          	}
          }
          */
        }
      }
      if (fail) {
        /*
        if (this._debug)
        {
        	String key = rows.getKey();

        	// Track the keys that fail and check whether we ever see a key for a value that failed before
        	if (this._failMap.containsKey(key))
        	{
        		int count = this._failMap.get(key);
        		count++;
        		this._failMap.put(key, count);
        	}
        	else
        	{
        		this._failMap.put(key, 1);
        	}
        }
        */
      }
    }

    return results;
  }