Пример #1
0
  /**
   * Get List of Strings in a Given ROW in a Cassandra Column Family Here we assume that the columns
   * in a given row have string data and key and value in the given column in that row have same
   * values.
   *
   * @param columnFamilyName Name of the column Family
   * @param rowName Row name
   * @param keyspace keySpace
   * @return List of string in that given row.
   * @throws CassandraDataAccessException In case of database access error or data error
   */
  public static List<String> getRowList(String columnFamilyName, String rowName, Keyspace keyspace)
      throws CassandraDataAccessException {
    ArrayList<String> rowList = new ArrayList<String>();

    if (keyspace == null) {
      throw new CassandraDataAccessException("Can't access Data , no keyspace provided ");
    }

    if (columnFamilyName == null || rowName == null) {
      throw new CassandraDataAccessException(
          "Can't access data with columnFamily =" + columnFamilyName + " and rowName=" + rowName);
    }

    try {
      SliceQuery<String, String, String> sliceQuery =
          HFactory.createSliceQuery(keyspace, stringSerializer, stringSerializer, stringSerializer);
      sliceQuery.setKey(rowName);
      sliceQuery.setColumnFamily(columnFamilyName);
      sliceQuery.setRange("", "", false, 10000);

      QueryResult<ColumnSlice<String, String>> result = sliceQuery.execute();
      ColumnSlice<String, String> columnSlice = result.get();
      for (HColumn<String, String> column : columnSlice.getColumns()) {
        rowList.add(column.getName());
      }
    } catch (Exception e) {
      throw new CassandraDataAccessException(
          "Error while accessing data from :" + columnFamilyName, e);
    }
    return rowList;
  }
Пример #2
0
  public boolean shouldInclude(SSTableReader sstable) {
    List<ByteBuffer> minColumnNames = sstable.getSSTableMetadata().minColumnNames;
    List<ByteBuffer> maxColumnNames = sstable.getSSTableMetadata().maxColumnNames;
    CellNameType comparator = sstable.metadata.comparator;

    if (minColumnNames.isEmpty() || maxColumnNames.isEmpty()) return true;

    for (ColumnSlice slice : slices)
      if (slice.intersects(minColumnNames, maxColumnNames, comparator, reversed)) return true;

    return false;
  }
Пример #3
0
  public SliceQueryFilter withUpdatedStart(Composite newStart, CFMetaData cfm) {
    Comparator<Composite> cmp = reversed ? cfm.comparator.reverseComparator() : cfm.comparator;

    // Check our slices to see if any fall before the new start (in which case they can be removed)
    // or
    // if they contain the new start (in which case they should start from the page start).
    // However, if the
    // slices would include static columns, we need to ensure they are also fetched, and so a
    // separate
    // slice for the static columns may be required.
    // Note that if the query is reversed, we can't handle statics by simply adding a separate slice
    // here, so
    // the reversed case is handled by SliceFromReadCommand instead. See CASSANDRA-8502 for more
    // details.
    List<ColumnSlice> newSlices = new ArrayList<>();
    boolean pastNewStart = false;
    for (ColumnSlice slice : slices) {
      if (pastNewStart) {
        newSlices.add(slice);
        continue;
      }

      if (slice.isBefore(cmp, newStart)) {
        if (!reversed && sliceIncludesStatics(slice, cfm))
          newSlices.add(new ColumnSlice(Composites.EMPTY, cfm.comparator.staticPrefix().end()));

        continue;
      } else if (slice.includes(cmp, newStart)) {
        if (!reversed && sliceIncludesStatics(slice, cfm) && !newStart.isEmpty())
          newSlices.add(new ColumnSlice(Composites.EMPTY, cfm.comparator.staticPrefix().end()));

        newSlices.add(new ColumnSlice(newStart, slice.finish));
      } else {
        newSlices.add(slice);
      }

      pastNewStart = true;
    }
    return withUpdatedSlices(newSlices.toArray(new ColumnSlice[newSlices.size()]));
  }
Пример #4
0
 public boolean maySelectPrefix(CType type, Composite prefix) {
   for (ColumnSlice slice : slices) if (slice.includes(type, prefix)) return true;
   return false;
 }
Пример #5
0
 /** Returns true if the slice includes static columns, false otherwise. */
 private boolean sliceIncludesStatics(ColumnSlice slice, CFMetaData cfm) {
   return cfm.hasStaticColumns()
       && slice.includes(
           reversed ? cfm.comparator.reverseComparator() : cfm.comparator,
           cfm.comparator.staticPrefix().end());
 }