Exemplo n.º 1
0
ObExprObj ObExprObjTest::bool_obj(MyBool t1)
{
  ObExprObj ret;
  ObObj obj;
  switch(t1)
  {
    case MY_TRUE:
      obj.set_bool(true);
      break;
    case MY_FALSE:
      obj.set_bool(false);
      break;
    default:
      obj.set_null();
      break;
  }
  ret.assign(obj);
  return ret;
}
Exemplo n.º 2
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.º 3
0
int ObFileTable::parse_line(const ObRow *&row)
{
  int ret = OB_SUCCESS;
  ObObj value;
  int64_t int_value;
  ObString str_value;

  if (column_count_ == count_)
  {
    for (int32_t i=0;(OB_SUCCESS == ret) && i<count_;i++)
    {
      if(0 == strcmp(tokens_[i], "NULL"))
      {
        value.set_null();
      }
      else
      {
        if(ObIntType == column_type_[i])
        {
          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])
        {
          str_value.assign_ptr(tokens_[i], strlen(tokens_[i]));
          value.set_varchar(str_value);
        }
        else if(ObExtendType == column_type_[i])
        {
          value.set_ext(ObActionFlag::OP_DEL_ROW);
        }
        else
        {
          ret = OB_ERROR;
          TBSYS_LOG(WARN, "unsupport type [%d]", column_type_[i]);
        }
      }

      if(OB_SUCCESS == ret)
      {
        ret = get_curr_row()->set_cell(table_id_, column_ids_[i], value);
      }
    }
  }
  else
  {
    ret = OB_ERROR;
    TBSYS_LOG(WARN, "column_count_[%d], count_[%d]", column_count_, count_);
  }

  if (OB_SUCCESS == ret)
  {
    row = get_curr_row();
  }

  return ret;
}