public SuperColumn get_super_column(
      String table, String key, SuperColumnPath super_column_path, int consistency_level)
      throws InvalidRequestException, NotFoundException {
    if (logger.isDebugEnabled()) logger.debug("get_superColumn");
    ThriftValidation.validateSuperColumnPath(table, super_column_path);

    ColumnFamily cfamily =
        readColumnFamily(
            new SliceByNamesReadCommand(
                table,
                key,
                new QueryPath(super_column_path.column_family),
                Arrays.asList(super_column_path.super_column)),
            consistency_level);
    if (cfamily == null) {
      throw new NotFoundException();
    }
    Collection<IColumn> columns = cfamily.getSortedColumns();
    if (columns == null || columns.size() == 0) {
      throw new NotFoundException();
    }

    assert columns.size() == 1;
    IColumn column = columns.iterator().next();
    if (column.getSubColumns().size() == 0) {
      throw new NotFoundException();
    }

    return new SuperColumn(column.name(), thriftifyColumns(column.getSubColumns()));
  }
  public Column get_column(String table, String key, ColumnPath column_path, int consistency_level)
      throws InvalidRequestException, NotFoundException {
    if (logger.isDebugEnabled()) logger.debug("get_column");
    ThriftValidation.validateColumnPath(table, column_path);

    QueryPath path = new QueryPath(column_path.column_family, column_path.super_column);
    ColumnFamily cfamily =
        readColumnFamily(
            new SliceByNamesReadCommand(table, key, path, Arrays.asList(column_path.column)),
            consistency_level);
    // TODO can we leverage getSlice here and just check that it returns one column?
    if (cfamily == null) {
      throw new NotFoundException();
    }
    Collection<IColumn> columns = null;
    if (column_path.super_column != null) {
      IColumn column = cfamily.getColumn(column_path.super_column);
      if (column != null) {
        columns = column.getSubColumns();
      }
    } else {
      columns = cfamily.getSortedColumns();
    }
    if (columns == null || columns.size() == 0) {
      throw new NotFoundException();
    }

    assert columns.size() == 1;
    IColumn column = columns.iterator().next();
    if (column.isMarkedForDelete()) {
      throw new NotFoundException();
    }

    return new Column(column.name(), column.value(), column.timestamp());
  }
  private Map<String, ColumnOrSuperColumn> multigetInternal(
      String keyspace, List<String> keys, ColumnPath cp, ConsistencyLevel level)
      throws InvalidRequestException, UnavailableException, TimedOutException {
    AvroValidation.validateColumnPath(keyspace, cp);

    // FIXME: This is repetitive.
    byte[] column, super_column;
    column = cp.column == null ? null : cp.column.array();
    super_column = cp.super_column == null ? null : cp.super_column.array();

    QueryPath path =
        new QueryPath(cp.column_family.toString(), column == null ? null : super_column);
    List<byte[]> nameAsList = Arrays.asList(column == null ? super_column : column);
    List<ReadCommand> commands = new ArrayList<ReadCommand>();
    for (String key : keys) {
      AvroValidation.validateKey(key);
      commands.add(new SliceByNamesReadCommand(keyspace, key, path, nameAsList));
    }

    Map<String, ColumnOrSuperColumn> columnFamiliesMap = new HashMap<String, ColumnOrSuperColumn>();
    Map<String, Collection<IColumn>> columnsMap = multigetColumns(commands, level);

    for (ReadCommand command : commands) {
      ColumnOrSuperColumn columnorsupercolumn;

      Collection<IColumn> columns = columnsMap.get(command.key);
      if (columns == null) {
        columnorsupercolumn = new ColumnOrSuperColumn();
      } else {
        assert columns.size() == 1;
        IColumn col = columns.iterator().next();

        if (col.isMarkedForDelete()) {
          columnorsupercolumn = new ColumnOrSuperColumn();
        } else {
          columnorsupercolumn =
              col instanceof org.apache.cassandra.db.Column
                  ? newColumnOrSuperColumn(newColumn(col.name(), col.value(), col.timestamp()))
                  : newColumnOrSuperColumn(
                      newSuperColumn(col.name(), avronateSubColumns(col.getSubColumns())));
        }
      }
      columnFamiliesMap.put(command.key, columnorsupercolumn);
    }

    return columnFamiliesMap;
  }
Exemple #4
0
    private SimpleBlockFetcher() throws IOException {
      IColumnSerializer columnSerializer = emptyColumnFamily.getColumnSerializer();
      int columns = file.readInt();
      for (int i = 0; i < columns; i++) {
        IColumn column = columnSerializer.deserialize(file);
        if (reversed) blockColumns.addFirst(column);
        else blockColumns.addLast(column);

        /* see if we can stop seeking. */
        boolean outOfBounds = false;
        if (!reversed && finishColumn.remaining() > 0)
          outOfBounds = comparator.compare(column.name(), finishColumn) >= 0;
        else if (reversed && startColumn.remaining() > 0)
          outOfBounds = comparator.compare(column.name(), startColumn) >= 0;
        if (outOfBounds) break;
      }
    }
Exemple #5
0
    public boolean getNextBlock() throws IOException {
      if (curRangeIndex < 0 || curRangeIndex >= indexes.size()) return false;

      /* seek to the correct offset to the data, and calculate the data size */
      IndexHelper.IndexInfo curColPosition = indexes.get(curRangeIndex);

      /* see if this read is really necessary. */
      if (reversed) {
        if ((finishColumn.remaining() > 0
                && comparator.compare(finishColumn, curColPosition.lastName) > 0)
            || (startColumn.remaining() > 0
                && comparator.compare(startColumn, curColPosition.firstName) < 0)) return false;
      } else {
        if ((startColumn.remaining() > 0
                && comparator.compare(startColumn, curColPosition.lastName) > 0)
            || (finishColumn.remaining() > 0
                && comparator.compare(finishColumn, curColPosition.firstName) < 0)) return false;
      }

      boolean outOfBounds = false;
      long positionToSeek = basePosition + curColPosition.offset;

      // With new promoted indexes, our first seek in the data file will happen at that point.
      if (file == null)
        file = originalInput == null ? sstable.getFileDataInput(positionToSeek) : originalInput;

      IColumnSerializer columnSerializer = emptyColumnFamily.getColumnSerializer();
      file.seek(positionToSeek);
      FileMark mark = file.mark();
      while (file.bytesPastMark(mark) < curColPosition.width && !outOfBounds) {
        IColumn column = columnSerializer.deserialize(file);
        if (reversed) blockColumns.addFirst(column);
        else blockColumns.addLast(column);

        /* see if we can stop seeking. */
        if (!reversed && finishColumn.remaining() > 0)
          outOfBounds = comparator.compare(column.name(), finishColumn) >= 0;
        else if (reversed && startColumn.remaining() > 0)
          outOfBounds = comparator.compare(column.name(), startColumn) >= 0;
      }

      if (reversed) curRangeIndex--;
      else curRangeIndex++;
      return true;
    }
  // Don't playa hate, avronate.
  public GenericArray<Column> avronateSubColumns(Collection<IColumn> columns) {
    if (columns == null || columns.isEmpty()) return EMPTY_SUBCOLUMNS;

    GenericData.Array<Column> avroColumns =
        new GenericData.Array<Column>(columns.size(), Column.SCHEMA$);

    for (IColumn column : columns) {
      if (column.isMarkedForDelete()) continue;

      Column avroColumn = newColumn(column.name(), column.value(), column.timestamp());
      avroColumns.add(avroColumn);
    }

    return avroColumns;
  }
Exemple #7
0
 private boolean isColumnNeeded(IColumn column) {
   if (startColumn.remaining() == 0 && finishColumn.remaining() == 0) return true;
   else if (startColumn.remaining() == 0 && !reversed)
     return comparator.compare(column.name(), finishColumn) <= 0;
   else if (startColumn.remaining() == 0 && reversed)
     return comparator.compare(column.name(), finishColumn) >= 0;
   else if (finishColumn.remaining() == 0 && !reversed)
     return comparator.compare(column.name(), startColumn) >= 0;
   else if (finishColumn.remaining() == 0 && reversed)
     return comparator.compare(column.name(), startColumn) <= 0;
   else if (!reversed)
     return comparator.compare(column.name(), startColumn) >= 0
         && comparator.compare(column.name(), finishColumn) <= 0;
   else // if reversed
   return comparator.compare(column.name(), startColumn) <= 0
         && comparator.compare(column.name(), finishColumn) >= 0;
 }
  public List<Column> thriftifyColumns(Collection<IColumn> columns, boolean reverseOrder) {
    if (columns == null || columns.isEmpty()) {
      return EMPTY_COLUMNS;
    }

    ArrayList<Column> thriftColumns = new ArrayList<Column>(columns.size());
    for (IColumn column : columns) {
      if (column.isMarkedForDelete()) {
        continue;
      }
      Column thrift_column = new Column(column.name(), column.value(), column.timestamp());
      thriftColumns.add(thrift_column);
    }

    // we have to do the reversing here, since internally we pass results around in ColumnFamily
    // objects, which always sort their columns in the "natural" order
    if (reverseOrder) Collections.reverse(thriftColumns);
    return thriftColumns;
  }
  private List<SuperColumn> thriftifySuperColumns(
      Collection<IColumn> columns, boolean reverseOrder) {
    if (columns == null || columns.isEmpty()) {
      return EMPTY_SUPERCOLUMNS;
    }

    ArrayList<SuperColumn> thriftSuperColumns = new ArrayList<SuperColumn>(columns.size());
    for (IColumn column : columns) {
      List<Column> subcolumns = thriftifyColumns(column.getSubColumns());
      if (subcolumns.isEmpty()) {
        continue;
      }
      thriftSuperColumns.add(new SuperColumn(column.name(), subcolumns));
    }

    if (reverseOrder) Collections.reverse(thriftSuperColumns);

    return thriftSuperColumns;
  }