Beispiel #1
0
void read_get_param(const char *fname, const char *section, PageArena<char> &allocer, ObGetParam &get_param)
{
  init_opt_map_();
  init_obj_type_map_();
  TBSYS_CONFIG.load(fname);
  const char *str = NULL;

  int32_t cell_infos_num = TBSYS_CONFIG.getInt(section, CELL_INFOS_NUM);
  str = TBSYS_CONFIG.getString(section, GET_FROZEN_ONLY);
  if (0 == strcmp("YES", str))
  {
    //get_param.set_is_read_frozen_only(true);
  }
  for (int32_t i = 0; i < cell_infos_num; i++)
  {
    const char *str = NULL;
    int32_t len = 0;
    ObCellInfo *ci = (ObCellInfo*)allocer.alloc(sizeof(ObCellInfo));
    ci->reset();

    // table name
    sprintf(buffer, TABLE_NAME_KEY_FORMAT, i);
    str = getAndCopySting_(allocer, section, buffer, len);
    ci->table_name_.assign_ptr(const_cast<char*>(str), len);

    // table id
    if (NULL == str)
    {
      sprintf(buffer, TABLE_ID_KEY_FORMAT, i);
      ci->table_id_ = TBSYS_CONFIG.getInt(section, buffer);
    }
    else
    {
      ci->table_id_ = OB_INVALID_ID;
    }

    // row key
    sprintf(buffer, ROW_KEY_KEY_FORMAT, i);
    str = getAndCopySting_(allocer, section, buffer, len);
    ci->row_key_.assign_ptr(const_cast<char*>(str), len);

    // column name
    sprintf(buffer, COLUMN_NAME_KEY_FORMAT, i);
    str = getAndCopySting_(allocer, section, buffer, len);
    ci->column_name_.assign_ptr(const_cast<char*>(str), len);

    // column id
    if (NULL == str)
    {
      sprintf(buffer, COLUMN_ID_KEY_FORMAT, i);
      ci->column_id_ = TBSYS_CONFIG.getInt(section, buffer);
    }
    else
    {
      ci->column_id_ = OB_INVALID_ID;
    }

    get_param.add_cell(*ci);
  }
}
int ObScannerLoader::build_cell_info(int table_id, const ObRowkey& row_key, char *buf, ObScanner &param)
{
  ObCellInfo info;
  ObString tmpstr;
  uint64_t column_id = OB_INVALID_ID;
  char *p = NULL;

  info.reset();
  //info.table_name_ = table_name_;
  info.table_id_ = table_id;
  info.row_key_ = row_key;
  info.column_id_ = column_id;

  if(NULL == (p = strchr(buf, ':')))
  {
    p = buf;
    auto_set_val(info.value_, p);
  }
  else
  {
    *p = '\0';
    p++;
    info.column_id_ = atoi(buf);
    auto_set_val(info.value_, p);
  }
  TBSYS_LOG(DEBUG, "[%lu][%s] [%lu]:[%s]", info.table_id_,
      to_cstring(info.row_key_),  info.column_id_, p);

  actual_fullfilled_item_num_++;
  return param.add_cell(info);
}
Beispiel #3
0
void read_cell_infos(const char *fname, const char *section, PageArena<char> &allocer, ObMutator &mutator, ObMutator &result)
{
  init_opt_map_();
  init_obj_type_map_();
  TBSYS_CONFIG.load(fname);
  int32_t cell_infos_num = TBSYS_CONFIG.getInt(section, CELL_INFOS_NUM);
  std::vector<int64_t> table_ids;
  std::vector<int64_t> column_ids;
  for (int32_t i = 0; i < cell_infos_num; i++)
  {
    const char *str = NULL;
    int32_t len = 0;
    ObCellInfo *ci = (ObCellInfo*)allocer.alloc(sizeof(ObCellInfo));
    //ObCellInfo *op = (ObCellInfo*)allocer.alloc(sizeof(ObCellInfo));
    ci->reset();

    sprintf(buffer, OP_TYPE_KEY_FORMAT, i);
    str = getAndCopySting_(allocer, section, buffer, len);
    int8_t op_type = 0;
    bool is_add = (0 == strncmp("add", str, 3));
    opt_map.get(str, op_type);

    // table name
    sprintf(buffer, TABLE_NAME_KEY_FORMAT, i);
    str = getAndCopySting_(allocer, section, buffer, len);
    ci->table_name_.assign_ptr(const_cast<char*>(str), len);

    // table id
    sprintf(buffer, TABLE_ID_KEY_FORMAT, i);
    ci->table_id_ = TBSYS_CONFIG.getInt(section, buffer);

    // row key
    sprintf(buffer, ROW_KEY_KEY_FORMAT, i);
    str = getAndCopySting_(allocer, section, buffer, len);
    ci->row_key_.assign_ptr(const_cast<char*>(str), len);

    // column name
    sprintf(buffer, COLUMN_NAME_KEY_FORMAT, i);
    str = getAndCopySting_(allocer, section, buffer, len);
    ci->column_name_.assign_ptr(const_cast<char*>(str), len);

    // column id
    sprintf(buffer, COLUMN_ID_KEY_FORMAT, i);
    ci->column_id_ = TBSYS_CONFIG.getInt(section, buffer);

    //*op = *ci;
    //op->value_.set_ext(op_type);
    //mutator.add_cell(*op);
    //table_ids.push_back(op->table_id_);
    //column_ids.push_back(op->column_id_);
    //if (ObActionFlag::OP_DEL_ROW == op_type)
    //{
    //  result.add_cell(*op);
    //  continue;
    //}

    // value type
    sprintf(buffer, VALUE_TYPE_KEY_FORMAT, i);
    str = TBSYS_CONFIG.getString(section, buffer);
    int value_type = 0;
    obj_type_map.get(str, value_type);

    // value
    sprintf(buffer, VALUE_KEY_FORMAT, i);
    if (ObVarcharType == value_type)
    {
      str = getAndCopySting_(allocer, section, buffer, len);
      ObString varchar;
      varchar.assign_ptr(const_cast<char*>(str), len);
      //char *tmp = (char*)malloc(1024 * 1024 + 512 * 1024);
      //memset(tmp, 'a', 1024 * 1024 + 512 * 1024);
      //varchar.assign_ptr(tmp, 1024 * 1024 + 512 * 1024);
      ci->value_.set_varchar(varchar);
    }
    else if (ObIntType == value_type)
    {
      int64_t value = TBSYS_CONFIG.getInt(section, buffer);
      ci->value_.set_int(value, is_add);
    }
    else if (ObFloatType == value_type)
    {
      str = TBSYS_CONFIG.getString(section, buffer);
      float value = atof(str);
      ci->value_.set_float(value, is_add);
    }
    else if (ObDoubleType == value_type)
    {
      str = TBSYS_CONFIG.getString(section, buffer);
      double value = atof(str);
      ci->value_.set_double(value, is_add);
    }
    else if (ObDateTimeType == value_type)
    {
      int64_t value = TBSYS_CONFIG.getInt(section, buffer);
      ci->value_.set_datetime(value);
    }
    else if(ObPreciseDateTimeType == value_type)
    {
      int64_t value = TBSYS_CONFIG.getInt(section, buffer);
      ci->value_.set_precise_datetime(value);
    }
    else if (ObSeqType == value_type)
    {
      ci->value_.set_seq();
    }
    else if (ObCreateTimeType == value_type)
    {
      int64_t value = TBSYS_CONFIG.getInt(section, buffer);
      ci->value_.set_createtime(value);
    }
    else if(ObModifyTimeType == value_type)
    {
      int64_t value = TBSYS_CONFIG.getInt(section, buffer);
      ci->value_.set_modifytime(value);
    }
    else if (ObNullType == value_type)
    {
      ci->value_.set_null();
    }
    else
    {
      fprintf(stderr, "value_type=%d is not supported\n", value_type);
    }

    switch (op_type)
    {
      case ObActionFlag::OP_UPDATE:
        mutator.update(ci->table_name_, ci->row_key_, ci->column_name_, ci->value_);
        break;
      case ObActionFlag::OP_INSERT:
        mutator.insert(ci->table_name_, ci->row_key_, ci->column_name_, ci->value_);
        break;
      case ObActionFlag::OP_DEL_ROW:
        mutator.del_row(ci->table_name_, ci->row_key_);
        break;
      case ObActionFlag::OP_USE_DB_SEM:
        mutator.use_db_sem();
        break;
      case ObActionFlag::OP_USE_OB_SEM:
        mutator.use_ob_sem();
        break;
      default:
        fprintf(stderr, "op_type not support %d\n", op_type);
        break;
    }
    table_ids.push_back(ci->table_id_);
    column_ids.push_back(ci->column_id_);
    ObMutatorCellInfo mutator_ci;
    mutator_ci.cell_info = *ci;
    result.add_cell(mutator_ci);
  }

  for (int32_t i = 0; i < cell_infos_num; i++)
  {
    result.next_cell();
    ObMutatorCellInfo *mutator_ci = NULL;
    ObCellInfo *ci = NULL;
    result.get_cell(&mutator_ci);
    ci = &(mutator_ci->cell_info);

    // table id
    sprintf(buffer, TABLE_ID_KEY_FORMAT, i);
    ci->table_id_ = TBSYS_CONFIG.getInt(section, buffer);

    // column id
    sprintf(buffer, COLUMN_ID_KEY_FORMAT, i);
    ci->column_id_ = TBSYS_CONFIG.getInt(section, buffer);
  }
  result.reset_iter();

  for (uint64_t i = 0; i < table_ids.size(); i++)
  {
    mutator.next_cell();
    ObMutatorCellInfo *mutator_ci = NULL;
    ObCellInfo *ci = NULL;
    mutator.get_cell(&mutator_ci);
    ci = &(mutator_ci->cell_info);

    // table id
    ci->table_id_ = table_ids[i];

    // column id
    ci->column_id_ = column_ids[i];
  }
  mutator.reset_iter();
}