Exemplo n.º 1
0
 //-------------------------------------------------------------------------------
 int set_ext_obj_value(char * buf, const int64_t buf_len, int64_t & pos, const int64_t value)
 {
   int ret = OB_SUCCESS;
   ObObj obj;
   obj.set_ext(value);
   ret = obj.serialize(buf, buf_len, pos);
   return ret;
 }
Exemplo n.º 2
0
 int64_t ObReadParam::get_reserve_param_serialize_size(void) const
 {
   ObObj obj;
   // reserve for read master
   obj.set_ext(ObActionFlag::RESERVE_PARAM_FIELD);
   int64_t total_size = obj.get_serialize_size();
   obj.set_int(get_is_read_consistency());
   total_size += obj.get_serialize_size();
   return total_size;
 }
Exemplo n.º 3
0
    int ObSqlGetParam::serialize_flag(char* buf, const int64_t buf_len, int64_t& pos,
        const int64_t flag) const
    {
      int ret = OB_SUCCESS;
      ObObj obj;

      obj.set_ext(flag);
      ret = obj.serialize(buf, buf_len, pos);

      return ret;
    }
Exemplo n.º 4
0
 int ObReadParam::serialize_reserve_param(char * buf, const int64_t buf_len, int64_t & pos) const
 {
   ObObj obj;
   // serialize RESERVER PARAM FIELD
   obj.set_ext(ObActionFlag::RESERVE_PARAM_FIELD);
   int ret = obj.serialize(buf, buf_len, pos);
   if (ret == OB_SUCCESS)
   {
     obj.set_int(get_is_read_consistency());
     ret = obj.serialize(buf, buf_len, pos);
   }
   return ret;
 }
Exemplo n.º 5
0
TEST_F(ObRowFuseTest, assign)
{
  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);
    OK(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);

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

  ups_row.set_delete_row(true);
  OK(ObRowFuse::assign(ups_row, row));

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

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

  ASSERT_TRUE(OB_SUCCESS != row.raw_get_cell(4, cell, table_id, column_id));
}
Exemplo n.º 6
0
    int64_t ObSqlGetParam::get_obj_serialize_size(const int64_t value, bool is_ext) const
    {
      ObObj obj;

      if (is_ext)
      {
        obj.set_ext(value);
      }
      else
      {
        obj.set_int(value);
      }

      return obj.get_serialize_size();
    }
 int64_t ObSqlScanParam::get_basic_param_serialize_size(void) const
 {
   int64_t total_size = 0;
   ObObj obj;
   // BASIC_PARAM_FIELD
   obj.set_ext(ObActionFlag::BASIC_PARAM_FIELD);
   total_size += obj.get_serialize_size();
   // scan range
   obj.set_int(range_.table_id_);
   total_size += obj.get_serialize_size();
   obj.set_int(range_.border_flag_.get_data());
   total_size += obj.get_serialize_size();
   // start_key_
   total_size += get_rowkey_obj_array_size(
       range_.start_key_.get_obj_ptr(), range_.start_key_.get_obj_cnt());
   // end_key_
   total_size += get_rowkey_obj_array_size(
       range_.end_key_.get_obj_ptr(), range_.end_key_.get_obj_cnt());
   obj.set_int(scan_flag_.flag_);
   total_size += obj.get_serialize_size();
   return total_size;
 }
 int ObSqlReadParam::serialize_end_param(char * buf, const int64_t buf_len, int64_t & pos) const
 {
   ObObj obj;
   obj.set_ext(ObActionFlag::END_PARAM_FIELD);
   return obj.serialize(buf, buf_len, pos);
 }
 int64_t ObSqlScanParam::get_end_param_serialize_size(void) const
 {
   ObObj obj;
   obj.set_ext(ObActionFlag::END_PARAM_FIELD);
   return obj.get_serialize_size();
 }
Exemplo n.º 10
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));
}
Exemplo n.º 11
0
void CellinfoBuilder::build_cell_(struct drand48_data &rand_data, const ObString &row_key, const ObSchema &schema,
                                  ObObj &obj, int64_t &column_pos, int &op_type,
                                  PageArena<char> &allocer)
{
  const ObColumnSchema *column_schema = schema.column_begin();
  int64_t column_num = schema.column_end() - schema.column_begin();
  int64_t rand = 0;

  lrand48_r(&rand_data, &rand);
  op_type = calc_op_type_(rand);
  //while (true)
  //{
  //  lrand48_r(&rand_data, &rand);
  //  column_pos = range_rand(0, column_num - 3, rand);
  //  if (ObIntType <= column_schema[column_pos].get_type()
  //      && ObVarcharType >= column_schema[column_pos].get_type())
  //  {
  //    break;
  //  }
  //}
  column_pos=0;

  lrand48_r(&rand_data, &rand);
  switch (column_schema[column_pos].get_type())
  {
    case ObIntType:
      {
        int64_t tmp = rand;
        obj.set_int(tmp, ADD == op_type);
        break;
      }
    case ObFloatType:
      {
        float tmp = static_cast<float>(rand);
        obj.set_float(tmp, ADD == op_type);
        break;
      }
    case ObDoubleType:
      {
        double tmp = static_cast<double>(rand);
        obj.set_double(tmp, ADD == op_type);
        break;
      }
    case ObDateTimeType:
      {
        ObDateTime tmp = static_cast<ObDateTime>(rand);
        obj.set_datetime(tmp, ADD == op_type);
        break;
      }
    case ObPreciseDateTimeType:
      {
        ObPreciseDateTime tmp = static_cast<ObPreciseDateTime>(rand);
        obj.set_precise_datetime(tmp, ADD == op_type);
        break;
      }
    case ObVarcharType:
      {
        int64_t length = range_rand(1, column_schema[column_pos].get_size(), rand);
        char *ptr = allocer.alloc(length);
        build_string(ptr, length, rand);
        ObString str;
        str.assign_ptr(ptr, length);
        if (ADD == op_type)
        {
          op_type = UPDATE;
        }
        obj.set_varchar(str);
        break;
      }
    default:
      break;
  }
  if (DEL_CELL == op_type)
  {
    obj.set_null();
  }
  else if (DEL_ROW == op_type)
  {
    obj.set_ext(ObActionFlag::OP_DEL_ROW);
  }
}
Exemplo n.º 12
0
int ObUpsFileTable::parse_line(const ObRow *&row)
{
  int ret = OB_SUCCESS;
  ObObj value;
  int64_t int_value;
  ObString str_value;

  if (column_count_ + 1 == count_)
  {

    for (int32_t i=1;(OB_SUCCESS == ret) && i<count_;i++)
    {
      if( tokens_[0][0] == '-' )
      {
        curr_ups_row_.set_delete_row(true);
      }
      else
      {
        curr_ups_row_.set_delete_row(false);
      }

      if(0 == strcmp(tokens_[i], "NOP"))
      {
        value.set_ext(ObActionFlag::OP_NOP);
      }
      else
      {
        if(ObIntType == column_type_[i-1])
        {
          bool is_add = false;
          if( tokens_[i][strlen(tokens_[i]) - 1] == '+' )
          {
            tokens_[i][strlen(tokens_[i]) - 1] = '\0';
            is_add = true;
          }
          int_value = atoi(tokens_[i]);
          value.set_int(int_value, is_add);
        }
        else if(ObVarcharType == column_type_[i-1])
        {
          str_value.assign_ptr(tokens_[i], strlen(tokens_[i]));
          value.set_varchar(str_value);
        }
        else if(ObExtendType == column_type_[i-1])
        {
          value.set_ext(ObActionFlag::OP_DEL_ROW);
        }
        else
        {
          ret = OB_ERROR;
          TBSYS_LOG(WARN, "unsupport type [%d]", column_type_[i-1]);
        }
      }

      if(OB_SUCCESS == ret)
      {
        ret = curr_ups_row_.set_cell(table_id_, column_ids_[i-1], value);
      }
    }
  }
  else
  {
    ret = OB_ERROR;
    TBSYS_LOG(WARN, "column_count_[%d], count_[%d], line_[%s]", column_count_, count_, line_);
  }

  if (OB_SUCCESS == ret)
  {
    row = &curr_ups_row_;
  }
  return ret;
}
Exemplo n.º 13
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() );
}