Example #1
0
TEST_F(ObRowFuseTest, test2)
{
  uint64_t TABLE_ID = 1000;

  ObRowDesc row_desc;
  for(int i=0;i<8;i++)
  {
    row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + i);
  }

  ObRow row;
  row.set_row_desc(row_desc);
  ObObj value;

  for(int i=0;i<8;i++)
  {
    value.set_int(i);
    row.raw_set_cell(i, value);
  }

  ObRowDesc ups_row_desc;
  for(int i=0;i<4;i++)
  {
    ups_row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + i);
  }

  ObUpsRow ups_row;
  ups_row.set_row_desc(ups_row_desc);

  ups_row.set_delete_row(true);

  for(int i=0;i<4;i++)
  {
    value.set_ext(ObActionFlag::OP_NOP);
    ups_row.raw_set_cell(i, value); 
  }

  ObRow result;
  OK(ObRowFuse::fuse_row(&ups_row, &row, &result));

  uint64_t table_id = OB_INVALID_ID;
  uint64_t column_id = OB_INVALID_ID;
  
  const ObObj *cell = NULL;

  for(int i=0;i<4;i++)
  {
    OK(result.raw_get_cell(i, cell, table_id, column_id));
    ASSERT_EQ(ObNullType, cell->get_type());
  }

  for(int i=4;i<8;i++)
  {
    int64_t int_value = 0;
    OK(result.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(int_value, i);
  }


  for(int i=0;i<4;i++)
  {
    value.set_int(i+100);
    ups_row.raw_set_cell(i, value);
  }

  OK(ObRowFuse::fuse_row(&ups_row, &row, &result));
  for(int i=0;i<4;i++)
  {
    int64_t int_value = 0;
    OK(result.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(int_value, i+100);
  }

  for(int i=4;i<8;i++)
  {
    int64_t int_value = 0;
    OK(result.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(int_value, i);
  }

  ups_row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + 10);
  ASSERT_TRUE(OB_SUCCESS != ObRowFuse::fuse_row(&ups_row, &row, &result));
}
Example #2
0
TEST_F(ObRunFileTest, test_all)
{
  static const int64_t BUFFER_SIZE = 1024;
  char compact_row_buff_[BUFFER_SIZE];
  ObRunFile run_file;
  char* fname = (char*)"ob_run_file_test.run";
  ObString filename;
  ASSERT_EQ(false, run_file.is_opened());
  ASSERT_NE(OB_SUCCESS, run_file.open(filename));
  filename.assign(fname, strlen(fname));
  ASSERT_EQ(OB_SUCCESS, run_file.open(filename));
  ASSERT_EQ(true, run_file.is_opened());
  const int64_t bucket_count = 4;
  const int64_t run_count_per_bucket = 8;
  for (int64_t j = 0; j < run_count_per_bucket; ++j)
  {
    for (int64_t i = 0; i < bucket_count; ++i)
    {
      ASSERT_EQ(OB_SUCCESS, run_file.begin_append_run(i));
      const ObRow *row = NULL;
      ObString compact_row;
      compact_row.assign_buffer(compact_row_buff_, BUFFER_SIZE);
      ASSERT_EQ(OB_SUCCESS, input_data_.open());
      while (OB_SUCCESS == input_data_.get_next_row(row))
      {
        compact_row.assign_buffer(compact_row_buff_, BUFFER_SIZE);
        ASSERT_EQ(OB_SUCCESS, ObRowUtil::convert(*row, compact_row));
        ASSERT_EQ(OB_SUCCESS, run_file.append_row(compact_row));
      } // end for
      ASSERT_EQ(OB_SUCCESS, input_data_.close());
      ASSERT_EQ(OB_SUCCESS, run_file.end_append_run());
    } // end for
  }
  // read and check
  ObRow row;
  const ObObj *cell = NULL;
  uint64_t table_id;
  uint64_t column_id;
  ASSERT_EQ(OB_SUCCESS, input_data_.open());
  row.set_row_desc(input_data_.get_row_desc());
  for (int64_t i = 0; i < bucket_count; ++i)
  {
    int64_t run_count = 0;
    ASSERT_EQ(OB_SUCCESS, run_file.begin_read_bucket(i, run_count));
    ASSERT_EQ(run_count, run_count_per_bucket);
    for (int64_t j = 0; j < ROW_COUNT; ++j)
    {
      for (int64_t k = 0; k < run_count; ++k)
      {
        ASSERT_EQ(OB_SUCCESS, run_file.get_next_row(k, row));
        ASSERT_EQ(OB_SUCCESS, row.raw_get_cell(1, cell, table_id, column_id));
        int64_t int_value;
        ASSERT_EQ(OB_SUCCESS, cell->get_int(int_value));
        ASSERT_EQ(j, int_value);
      }
    } // end for
    for (int64_t k = 0; k < run_count; ++k)
    {
      ASSERT_EQ(OB_ITER_END, run_file.get_next_row(k, row));
    }
    ASSERT_EQ(OB_SUCCESS, run_file.end_read_bucket());
  }
  ASSERT_EQ(OB_SUCCESS, run_file.close());
  ASSERT_EQ(false, run_file.is_opened());
  ASSERT_EQ(OB_SUCCESS, input_data_.close());
}
Example #3
0
// ObRow.reset
TEST_F(ObRowTest, reset_test)
{
  ObRow row;
  ObRowDesc row_desc;
  const uint64_t TABLE_ID = 1001;
  const int64_t COLUMN_NUM = 8;
  ObObj cell;
  const ObObj *value = NULL;
  uint64_t table_id = 0;
  uint64_t column_id = 0;
  int64_t int_value = 0;

  row_desc.set_rowkey_cell_count(2);

  for (int i = 0; i < COLUMN_NUM; i ++)
  {
    row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + i);
  }
  row.set_row_desc(row_desc);

  for (int i = 0; i < COLUMN_NUM; i ++)
  {
    cell.set_int(i);
    row.raw_set_cell(i, cell);
  }

  row.reset(true, ObRow::DEFAULT_NULL);
  for (int i = 0; i < row_desc.get_rowkey_cell_count(); i ++)
  {
    row.raw_get_cell(i, value, table_id, column_id);
    value->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }

  for (int64_t i = row_desc.get_rowkey_cell_count(); i < COLUMN_NUM; i ++)
  {
    row.raw_get_cell(i, value, table_id, column_id);
    ASSERT_TRUE( ObNullType == value->get_type() );
  }

  row_desc.add_column_desc(OB_INVALID_ID, OB_ACTION_FLAG_COLUMN_ID);
  cell.set_ext(ObActionFlag::OP_DEL_ROW);
  row.set_cell(OB_INVALID_ID, OB_ACTION_FLAG_COLUMN_ID, cell);

  row.reset(true, ObRow::DEFAULT_NOP);

  for (int i = 0; i < row_desc.get_rowkey_cell_count(); i ++)
  {
    row.raw_get_cell(i, value, table_id, column_id);
    value->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }

  for (int64_t i = row_desc.get_rowkey_cell_count(); i < COLUMN_NUM; i ++)
  {
    row.raw_get_cell(i, value, table_id, column_id);
    ASSERT_TRUE( ObActionFlag::OP_NOP == value->get_ext() ) << "ext value: " << value->get_ext();
  }

  row.get_cell(OB_INVALID_ID, OB_ACTION_FLAG_COLUMN_ID, value);
  ASSERT_TRUE( ObActionFlag::OP_ROW_DOES_NOT_EXIST == value->get_ext() );
}
int ObRowStore::append_row(const ObRowkey *rowkey, const ObRow &row, BlockInfo &block, StoredRow &stored_row)
{
  int ret = OB_SUCCESS;

  const int64_t reserved_columns_count = reserved_columns_.count();
  ObCompactCellWriter cell_writer;

  if(NULL == rowkey)
  {
    cell_writer.init(block.get_buffer(), block.get_remain_size(), SPARSE);
  }
  else
  {
    cell_writer.init(block.get_buffer(), block.get_remain_size(), DENSE_SPARSE);
  }

  const ObObj *cell = NULL;
  uint64_t table_id = OB_INVALID_ID;
  uint64_t column_id = OB_INVALID_ID;
  ObObj cell_clone;

  const ObUpsRow *ups_row = dynamic_cast<const ObUpsRow *>(&row);
  if(OB_SUCCESS == ret && NULL != rowkey)
  {
    if(OB_SUCCESS != (ret = cell_writer.append_rowkey(*rowkey)))
    {
      TBSYS_LOG(WARN, "append rowkey fail:ret[%d]", ret);
    }
  }

  if(OB_SUCCESS == ret && NULL != ups_row)
  {
    if( ups_row->get_is_delete_row() )
    {
      if(OB_SUCCESS != (ret = cell_writer.row_delete()))
      {
        TBSYS_LOG(WARN, "append row delete flag fail:ret[%d]", ret);
      }
    }
  }

  int64_t ext_value = 0;

  for (int64_t i = 0; 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, "failed to get cell, err=%d", ret);
      break;
    }
    if (OB_SUCCESS == ret)
    {
      if (ObExtendType == cell->get_type())
      {
        if(OB_SUCCESS != (ret = cell->get_ext(ext_value)))
        {
          TBSYS_LOG(WARN, "get ext value fail:ret[%d]", ret);
        }
        else if (ObActionFlag::OP_VALID == ext_value)
        {
          if (OB_SUCCESS != (ret = cell_writer.append_escape(ObCellMeta::ES_VALID)))
          {
            TBSYS_LOG(WARN, "fail to append escape:ret[%d]", ret);
          }
        }
        else if (ObActionFlag::OP_ROW_DOES_NOT_EXIST == ext_value)
        {
          if (OB_SUCCESS != (ret = cell_writer.append_escape(ObCellMeta::ES_NOT_EXIST_ROW)))
          {
            TBSYS_LOG(WARN, "fail to append escape:ret[%d]", ret);
          }
        }
        else if(ObActionFlag::OP_NOP != ext_value)
        {
          ret = OB_NOT_SUPPORTED;
          TBSYS_LOG(WARN, "not supported ext value:ext[%ld]", ext_value);
        }
        else if(NULL == ups_row)
        {
          ret = OB_NOT_SUPPORTED;
          TBSYS_LOG(WARN, "OP_NOP can only used in ups row");
        }
        else //OP_NOP不需要序列化
        {
          cell_clone = *cell;
        }
      }
      else if (OB_SUCCESS != (ret = cell_writer.append(column_id, *cell, &cell_clone)))
      {
        if (OB_BUF_NOT_ENOUGH != ret)
        {
          TBSYS_LOG(WARN, "failed to append cell, err=%d", ret);
        }
        break;
      }
    }
    if (OB_SUCCESS == ret)
    {
      // whether reserve this cell
      for (int32_t j = 0; j < reserved_columns_count; ++j)
      {
        const std::pair<uint64_t,uint64_t> &tid_cid = reserved_columns_.at(j);
        if (table_id == tid_cid.first && column_id == tid_cid.second)
        {
          stored_row.reserved_cells_[j] = cell_clone;
          break;
        }
      } // end for j
    }
  } // end for i
  if (OB_SUCCESS == ret)
  {
    if (OB_SUCCESS != (ret = cell_writer.row_finish()))
    {
      if (OB_BUF_NOT_ENOUGH != ret)
      {
        TBSYS_LOG(WARN, "failed to append cell, err=%d", ret);
      }
    }
    else
    {
      stored_row.compact_row_size_ = static_cast<int32_t>(cell_writer.size());
      block.advance(cell_writer.size());
      cur_size_counter_ += cell_writer.size();
    }
  }
  return ret;
}
Example #5
0
TEST_F(ObRowStoreTest, rowkey)
{
  ObRowStore row_store;

  char rowkey_buf[100];
  ObString rowkey;

  ObRowDesc row_desc;
  for(int64_t i=0;i<10;i++)
  {
    row_desc.add_column_desc(TABLE_ID, i + OB_APP_MIN_COLUMN_ID);
  }

  ObRow row;
  row.set_row_desc(row_desc);

  ObObj cell;
  const ObRowStore::StoredRow *stored_row = NULL;
  const ObObj *value = NULL;
  uint64_t table_id = OB_INVALID_ID;
  uint64_t column_id = OB_INVALID_ID;
  int64_t int_value = 0;

  ObCompactCellIterator cell_reader;


  for(int64_t j=0;j<9;j++)
  {
    sprintf(rowkey_buf, "rowkey_%05ld", j);
    rowkey.assign_ptr(rowkey_buf, (int32_t)strlen(rowkey_buf));
    for(int64_t i=0;i<10;i++)
    {
      cell.set_int(j * 1000 + i);
      OK(row.raw_set_cell(i, cell));
    }
    OK(row_store.add_row(rowkey, row, stored_row));

    OK(cell_reader.init(stored_row->get_compact_row(), DENSE_SPARSE));

    OK(cell_reader.next_cell());
    OK(cell_reader.get_cell(value));
    value->get_varchar(rowkey);
    ASSERT_EQ(0, strncmp(rowkey_buf, rowkey.ptr(), rowkey.length()));

    for(int64_t i=0;i<10;i++)
    {
      OK(cell_reader.next_cell());
      OK(cell_reader.get_cell(column_id, value));
      value->get_int(int_value);
      ASSERT_EQ(j * 1000 + i, int_value);
    }
  }

  
  for(int64_t j=0;j<9;j++)
  {
    OK(row_store.get_next_row(&rowkey, row));
    sprintf(rowkey_buf, "rowkey_%05ld", j);
    ASSERT_EQ(0, strncmp(rowkey_buf, rowkey.ptr(), rowkey.length()));

    for(int64_t i=0;i<10;i++)
    {
      OK(row.raw_get_cell(i, value, table_id, column_id));
      value->get_int(int_value);
      ASSERT_EQ( j * 1000 + i, int_value);
    }
  }
}