bool equal(const ObRow &r1, const ObRow &r2)
{
  bool bret = false;
  const ObRowDesc *rd1 = r1.get_row_desc();
  const ObRowDesc *rd2 = r2.get_row_desc();
  if (equal(*rd1, *rd2))
  {
    bret = true;
    for (int64_t i = 0; i < rd1->get_column_num(); i++)
    {
      const ObObj *c1 = NULL;
      uint64_t tid1 = OB_INVALID_ID;
      uint64_t cid1 = OB_INVALID_ID;
      const ObObj *c2 = NULL;
      uint64_t tid2 = OB_INVALID_ID;
      uint64_t cid2 = OB_INVALID_ID;
      r1.raw_get_cell(i, c1, tid1, cid1);
      r2.raw_get_cell(i, c2, tid2, cid2);
      if (*c1 != *c2
          || tid1 != tid2
          || cid1 != cid2)
      {
        bret = false;
        break;
      }
    }
  }
  return bret;
}
int ObMultipleScanMerge::write_row(ObRow &row)
{
  int ret = OB_SUCCESS;
  const ObRowDesc *row_desc = NULL;
  const ObObj *cell = NULL;
  ObObj value;
  uint64_t table_id = OB_INVALID_ID;
  uint64_t column_id = OB_INVALID_ID;

  row_desc = row.get_row_desc();
  if (NULL == row_desc)
  {
    ret = OB_INVALID_ARGUMENT;
    TBSYS_LOG(WARN, "row_desc is null");
  }

  for (int64_t i = row_desc->get_rowkey_cell_count(); OB_SUCCESS == ret && i < row.get_column_num(); i ++)
  {
    if (OB_SUCCESS != (ret = row.raw_get_cell(i, cell, table_id, column_id) ))
    {
      TBSYS_LOG(WARN, "fail to get cell:ret[%d]", ret);
    }
    else if (OB_SUCCESS != (ret = ob_write_obj(allocator_, *cell, value) ))
    {
      TBSYS_LOG(WARN, "fail to write obj:ret[%d]", ret);
    }
    else if (OB_SUCCESS != (ret = row.raw_set_cell(i, value) ))
    {
      TBSYS_LOG(WARN, "fail to set cell:ret[%d]", ret);
    }
  }
  return ret;
}
예제 #3
0
int ObRowStore::iterator::get_next_row(ObRowkey *rowkey, ObObj *rowkey_obj, ObRow &row, common::ObString *compact_row)
{
  int ret = OB_SUCCESS;
  const StoredRow *stored_row = NULL;

  if (NULL == row_store_)
  {
    TBSYS_LOG(ERROR, "row_store_ is NULL, should not reach here");
    ret = OB_ERROR;
  }

  if (OB_SUCCESS == ret && !got_first_next_)
  {
    cur_iter_block_ = row_store_->block_list_tail_;
    cur_iter_pos_ = 0;
    got_first_next_ = true;
  }

  if (OB_SUCCESS == ret && OB_ITER_END == (ret = next_iter_pos(cur_iter_block_, cur_iter_pos_)))
  {
    TBSYS_LOG(DEBUG, "iter end.block=%p, pos=%ld", cur_iter_block_, cur_iter_pos_);
  }
  else if (OB_SUCCESS == ret)
  {
    const char *buffer = cur_iter_block_->get_buffer_head() + cur_iter_pos_;
    stored_row = reinterpret_cast<const StoredRow *>(buffer);
    cur_iter_pos_ += (row_store_->get_reserved_cells_size(stored_row->reserved_cells_count_)
        + stored_row->compact_row_size_);
    //TBSYS_LOG(DEBUG, "stored_row->reserved_cells_count_=%d, stored_row->compact_row_size_=%d, sizeof(ObObj)=%lu, next_pos_=%ld",
    //stored_row->reserved_cells_count_, stored_row->compact_row_size_, sizeof(ObObj), cur_iter_pos_);

    if (OB_SUCCESS == ret && NULL != stored_row)
    {
      ObUpsRow *ups_row = dynamic_cast<ObUpsRow*>(&row);
      if (NULL != ups_row)
      {
        const ObRowDesc *row_desc = row.get_row_desc();
        uint64_t table_id = OB_INVALID_ID;
        uint64_t column_id = OB_INVALID_ID;

        if(NULL == row_desc)
        {
          ret = OB_INVALID_ARGUMENT;
          TBSYS_LOG(WARN, "row should set row desc first");
        }
        else if(OB_SUCCESS != (ret = row_desc->get_tid_cid(0, table_id, column_id)))
        {
          TBSYS_LOG(WARN, "get tid cid fail:ret[%d]", ret);
        }
        else if (OB_SUCCESS != (ret = ObUpsRowUtil::convert(table_id, stored_row->get_compact_row(), *ups_row, rowkey, rowkey_obj)))
        {
          TBSYS_LOG(WARN, "fail to convert compact row to ObUpsRow. ret=%d", ret);
        }
      }
      else
      {
        if(OB_SUCCESS != (ret = ObRowUtil::convert(stored_row->get_compact_row(), row, rowkey, rowkey_obj)))
        {
          TBSYS_LOG(WARN, "fail to convert compact row to ObRow:ret[%d]", ret);
        }
      }
      if (OB_SUCCESS == ret && NULL != compact_row)
      {
        *compact_row = stored_row->get_compact_row();
      }
    }
    else
    {
      TBSYS_LOG(WARN, "fail to get next row. stored_row=%p, ret=%d", stored_row, ret);
    }
  }

  return ret;
}