本文整理汇总了C++中ObString::length方法的典型用法代码示例。如果您正苦于以下问题:C++ ObString::length方法的具体用法?C++ ObString::length怎么用?C++ ObString::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObString
的用法示例。
在下文中一共展示了ObString::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_int
int ObSystemConfigKey::set_int(const ObString &key, int64_t intval)
{
int ret = OB_SUCCESS;
if (key == ObString::make_string("cluster_id"))
{
cluster_id_ = intval;
}
else if (key == ObString::make_string("svr_port"))
{
server_port_ = intval;
}
else
{
ret = OB_INVALID_ARGUMENT;
TBSYS_LOG(ERROR, "unknow sys config column name: %.*s",
key.length(), key.ptr());
}
return ret;
}
示例2: if
int ObMetaTable3::get_table_schema(const ObString &tname, TableSchema &table_schema)
{
int ret = OB_SUCCESS;
if (OB_SUCCESS != (ret = schema_service_.get_table_schema(tname, table_schema)))
{
TBSYS_LOG(WARN, "failed to get table schema, err=%d", ret);
}
else if (TableSchema::META != table_schema.table_type_)
{
ret = OB_ERR_UNEXPECTED;
TBSYS_LOG(ERROR, "this table is not meta table, tname=%.*s type=%d",
tname.length(), tname.ptr(), table_schema.table_type_);
}
else if (0 >= table_schema.rowkey_column_num_)
{
ret = OB_ERR_UNEXPECTED;
TBSYS_LOG(ERROR, "BUG rowkey column num=%d", table_schema.rowkey_column_num_);
}
return ret;
}
示例3: main
int main(int argc, char ** argv)
{
UNUSED(argc);
UNUSED(argv);
int ret = OB_SUCCESS;
//char * test = "00596331192663719";
char * test = "00912219024438372";
ObString rowkey;
rowkey.assign(test, strlen(test));
char temp[1024];
hex_to_str(rowkey.ptr(), rowkey.length(), temp, 1024);
printf("test2str:test[%s], str[%s]\n", test, temp);
int64_t ip = 539289610; //488957962; //522512394;
ObServer server;
server.set_ipv4_addr(ip, 1024);
static const int32_t MAX_SERVER_ADDR_SIZE = 128;
char server_addr[MAX_SERVER_ADDR_SIZE];
server.to_string(server_addr, MAX_SERVER_ADDR_SIZE);
printf("server:[%ld], server[%s]\n", ip, server_addr);
return ret;
}
示例4: update_all_trigger_event
int ObInnerTableOperator::update_all_trigger_event(ObString & sql, const int64_t timestamp,
const ObServer & server, const int64_t type, const int64_t param)
{
UNUSED(param);
int ret = OB_SUCCESS;
if ((sql.ptr() == NULL) || (0 == sql.size()))
{
TBSYS_LOG(WARN, "Check SQL buffer size failed! ptr[%p], size[%d]", sql.ptr(), sql.size());
ret = OB_INVALID_ARGUMENT;
}
else
{
char buf[OB_MAX_SERVER_ADDR_SIZE] = "";
if (server.ip_to_string(buf, sizeof(buf)) != true)
{
ret = OB_CONVERT_ERROR;
}
else
{
const char * format = "REPLACE INTO %s"
"(event_ts, src_ip, event_type, event_param) "
"values (%ld, '%s', %ld, %ld);";
int size = snprintf(sql.ptr(), sql.size(), format,
OB_ALL_TRIGGER_EVENT_TABLE_NAME, timestamp, buf, type, param);
if (size >= sql.size())
{
TBSYS_LOG(ERROR, "SQL buffer size not enough! size: [%d], need: [%d], sql: [%.*s]",
sql.size(), size, sql.length(), sql.ptr());
ret = OB_SIZE_OVERFLOW;
}
else
{
sql.assign_ptr(sql.ptr(), size);
}
}
}
return ret;
}
示例5: update_all_server
int ObInnerTableOperator::update_all_server(ObString & sql, const int64_t cluster_id,
const char * server_type, const ObServer & server, const uint32_t inner_port, const char * version)
{
int ret = OB_SUCCESS;
if ((sql.ptr() == NULL) || (0 == sql.size()))
{
TBSYS_LOG(WARN, "Check SQL buffer size failed! ptr[%p], size[%d]", sql.ptr(), sql.size());
ret = OB_INVALID_ARGUMENT;
}
else
{
char buf[OB_MAX_SERVER_ADDR_SIZE] = "";
if (server.ip_to_string(buf, sizeof(buf)) != true)
{
ret = OB_CONVERT_ERROR;
}
else
{
const char * format = "REPLACE INTO %s"
"(cluster_id, svr_type, svr_ip, svr_port, inner_port, svr_role, svr_version) "
"values (%d, '%s', '%s', %u, %u, %d, '%s');";
int size = snprintf(sql.ptr(), sql.size(), format, OB_ALL_SERVER, cluster_id,
server_type, buf, server.get_port(), inner_port, 0, version);
if (size >= sql.size())
{
TBSYS_LOG(ERROR, "SQL buffer size not enough! size: [%d], need: [%d], sql: [%.*s]",
sql.size(), size, sql.length(), sql.ptr());
ret = OB_SIZE_OVERFLOW;
}
else
{
sql.assign_ptr(sql.ptr(), size);
}
}
}
return ret;
}
示例6: get_table_id
static int get_table_id(ResultPlan* result_plan, const ObString &table_name, uint64_t &table_id)
{
int ret = OB_SUCCESS;
OB_ASSERT(NULL != result_plan);
ObLogicalPlan* logical_plan = static_cast<ObLogicalPlan*>(result_plan->plan_tree_);
ObSchemaChecker* schema_checker = static_cast<ObSchemaChecker*>(result_plan->schema_checker_);
if (logical_plan == NULL)
{
ret = OB_ERR_UNEXPECTED;
PARSER_LOG("unexpected branch, logical_plan is NULL");
}
else if (NULL == schema_checker)
{
ret = OB_ERR_SCHEMA_UNSET;
PARSER_LOG("unexpected branch, schema_checker is NULL");
}
else if (OB_INVALID_ID == (table_id = schema_checker->get_table_id(table_name)))
{
ret = OB_ERR_TABLE_UNKNOWN;
PARSER_LOG("Table `%.*s' does not exist", table_name.length(), table_name.ptr());
}
return ret;
}
示例7: init_new_task
int TaskFactory::init_new_task(const ObString & table_name, const ObRowkey & start_key,
const ObRowkey & end_key, ObScanParam & scan_param, TaskInfo & task) const
{
int ret = OB_SUCCESS;
if (!check_string(table_name))
{
TBSYS_LOG(WARN, "check table name or end key failed:name[%.*s]",
table_name.length(), table_name.ptr());
ret = OB_ERROR;
}
else
{
ObNewRange range;
range.border_flag_.unset_inclusive_start();
range.border_flag_.set_inclusive_end();
if (NULL == start_key.ptr())
{
range.border_flag_.set_min_value();
}
else
{
range.start_key_ = start_key;
range.border_flag_.unset_min_value();
}
range.border_flag_.unset_max_value();
range.end_key_ = end_key;
scan_param.set(OB_INVALID_ID, table_name, range);
// deep copy the param to task info param
ret = task.set_param(scan_param);
if (ret != OB_SUCCESS)
{
TBSYS_LOG(ERROR, "set param failed:ret[%d]", ret);
}
}
return ret;
}
示例8: delete_all_server
int ObInnerTableOperator::delete_all_server(ObString & sql, const int64_t cluster_id,
const char * server_type, const ObServer & server)
{
int ret = OB_SUCCESS;
if ((sql.ptr() == NULL) || (0 == sql.size()))
{
TBSYS_LOG(WARN, "Check SQL buffer size failed! ptr[%p], size[%d]", sql.ptr(), sql.size());
ret = OB_INVALID_ARGUMENT;
}
else
{
char buf[OB_MAX_SERVER_ADDR_SIZE] = "";
if (server.ip_to_string(buf, sizeof (buf)) != true)
{
ret = OB_CONVERT_ERROR;
}
else
{
const char * format = "DELETE FROM %s WHERE cluster_id = %d AND svr_type = '%s' "
"AND svr_ip = '%s' AND svr_port = %u;";
int size = snprintf(sql.ptr(), sql.size(), format, OB_ALL_SERVER,
cluster_id, server_type, buf, server.get_port());
if (size >= sql.size())
{
TBSYS_LOG(ERROR, "SQL buffer size not enough! size: [%d], need: [%d], sql: [%.*s]",
sql.size(), size, sql.length(), sql.ptr());
ret = OB_SIZE_OVERFLOW;
}
else
{
sql.assign_ptr(sql.ptr(), size);
}
}
}
return ret;
}
示例9: test_big_data
void ObTabletJoinTest::test_big_data(ObTabletJoin &tablet_join)
{
system("python gen_test_data.py join");
ObTabletJoin::TableJoinInfo tablet_join_info;
tablet_join_info.left_table_id_ = LEFT_TABLE_ID;
tablet_join_info.right_table_id_ = RIGHT_TABLE_ID;
ObTabletJoin::JoinInfo join_info;
OK(tablet_join_info.join_condition_.push_back(1));
OK(read_join_info(tablet_join_info, "tablet_join_test_data/join_info.ini"));
tablet_join.set_table_join_info(tablet_join_info);
ObFakeUpsMultiGet fake_ups_multi_get("tablet_join_test_data/big_ups_scan2.ini");
ObFileTable result("tablet_join_test_data/big_result2.ini");
ObFakeSSTableScan sstable("tablet_join_test_data/big_sstable2.ini");
ObFakeUpsScan ups_scan("tablet_join_test_data/none_ups.ini");
ObTabletScanFuse tablet_fuse;
OK(tablet_fuse.set_sstable_scan(&sstable));
OK(tablet_fuse.set_incremental_scan(&ups_scan));
tablet_join.set_child(0, tablet_fuse);
tablet_join.set_batch_count(30000);
tablet_join.set_ups_multi_get(&fake_ups_multi_get);
OK(sstable.open());
OK(sstable.close());
uint64_t table_id = OB_INVALID_ID;
uint64_t column_id = OB_INVALID_ID;
const ObRowDesc *row_desc = NULL;
sstable.get_row_desc(row_desc);
for(int64_t i=0;i<row_desc->get_column_num();i++)
{
row_desc->get_tid_cid(i, table_id, column_id);
tablet_join.add_column_id(column_id);
}
ObGetParam get_param(true);
const ObRow *row = NULL;
const ObRow *result_row = NULL;
const ObObj *value = NULL;
const ObObj *result_value = NULL;
OK(result.open());
OK(tablet_join.open());
int err = OB_SUCCESS;
int64_t count = 0;
while(OB_SUCCESS == (err = tablet_join.get_next_row(row)))
{
OK(result.get_next_row(result_row));
count ++;
for(int64_t i=0;i<row->get_column_num();i++)
{
OK(row->raw_get_cell(i, value, table_id, column_id));
OK(result_row->get_cell(table_id, column_id, result_value));
if( *value != *result_value )
{
printf("row:[%ld], column[%ld]===========\n", count, i);
ObString rowkey;
get_rowkey(*row, rowkey);
printf("row rowkey: %.*s\n", rowkey.length(), rowkey.ptr());
printf("row: %s\n", print_obj(*value));
get_rowkey(*result_row, rowkey);
printf("result rowkey: %.*s\n", rowkey.length(), rowkey.ptr());
printf("result: %s\n", print_obj(*result_value));
}
ASSERT_TRUE((*value) == (*result_value));
}
}
ASSERT_TRUE(OB_SUCCESS == err || OB_ITER_END == err);
OK(result.close());
OK(tablet_join.close());
}
示例10: check_string
bool TaskFactory::check_string(const ObString & name)
{
return ((NULL != name.ptr()) && (0 != name.length()));
}
示例11: switch
const char *print_obj(const ObObj &obj)
{
static __thread char buffer[1024 * 10];
switch (obj.get_type())
{
case ObNullType:
sprintf(buffer, "obj_type=null");
break;
case ObIntType:
{
bool is_add = false;
int64_t tmp = 0;
obj.get_int(tmp, is_add);
sprintf(buffer, "obj_type=int value=%ld is_add=%s", tmp, STR_BOOL(is_add));
}
break;
case ObFloatType:
{
bool is_add = false;
float tmp = 0.0;
obj.get_float(tmp, is_add);
sprintf(buffer, "obj_type=float value=%f is_add=%s", tmp, STR_BOOL(is_add));
}
break;
case ObDoubleType:
{
bool is_add = false;
double tmp = 0.0;
obj.get_double(tmp, is_add);
sprintf(buffer, "obj_type=double value=%lf is_add=%s", tmp, STR_BOOL(is_add));
}
break;
case ObDateTimeType:
{
bool is_add = false;
ObDateTime tmp;
obj.get_datetime(tmp, is_add);
sprintf(buffer, "obj_type=data_time value=%s is_add=%s", time2str(tmp), STR_BOOL(is_add));
}
break;
case ObPreciseDateTimeType:
{
bool is_add = false;
ObDateTime tmp;
obj.get_precise_datetime(tmp, is_add);
sprintf(buffer, "obj_type=precise_data_time value=%s is_add=%s", time2str(tmp), STR_BOOL(is_add));
}
break;
case ObVarcharType:
{
ObString tmp;
obj.get_varchar(tmp);
sprintf(buffer, "obj_type=var_char value=[%.*s]", tmp.length(), tmp.ptr());
}
break;
case ObSeqType:
{
sprintf(buffer, "obj_type=seq");
}
break;
case ObCreateTimeType:
{
ObCreateTime tmp = 0;
obj.get_createtime(tmp);
snprintf(buffer, BUFFER_SIZE, "obj_type=create_time value=%s", time2str(tmp));
}
break;
case ObModifyTimeType:
{
ObModifyTime tmp = 0;
obj.get_modifytime(tmp);
snprintf(buffer, BUFFER_SIZE, "obj_type=modify_time value=%s", time2str(tmp));
}
break;
case ObExtendType:
{
int64_t tmp = 0;
obj.get_ext(tmp);
sprintf(buffer, "obj_type=extend value=%ld", tmp);
}
break;
default:
break;
}
return buffer;
}
示例12: open
int ObAlterSysCnf::open()
{
int ret = OB_SUCCESS;
if (sys_cnf_items_.count() <= 0)
{
ret = OB_NOT_INIT;
TBSYS_LOG(USER_ERROR, "No param to be changed, ret=%d", ret);
}
else if ((local_context_.schema_manager_ =
local_context_.merger_schema_mgr_->get_user_schema(0)) == NULL)
{
ret = OB_ERROR;
TBSYS_LOG(USER_ERROR, "Fail to get schema manager, ret=%d", ret);
}
else if ((ret = execute_transaction_stmt(START_TRANSACTION)) != OB_SUCCESS)
{
TBSYS_LOG(WARN, "Start transaction failed, ret=%d", ret);
}
else
{
for (int64_t i = 0; i < sys_cnf_items_.count(); i++)
{
ObSysCnfItem& cnf_item = sys_cnf_items_.at(i);
if (cnf_item.server_ip_.length() > 15)
{
ret = OB_ERROR;
TBSYS_LOG(USER_ERROR, "Invalid server ip: %.*s",
cnf_item.server_ip_.length(), cnf_item.server_ip_.ptr());
break;
}
else if (cnf_item.server_ip_.length() > 0)
{
// check ip address
uint32_t ip = 0;
char buf[16];
memcpy(buf, cnf_item.server_ip_.ptr(), cnf_item.server_ip_.length());
buf[cnf_item.server_ip_.length()] = '\0';
if ((ip = inet_addr(buf)) == INADDR_NONE)
{
ret = OB_ERROR;
TBSYS_LOG(USER_ERROR, "Invalid server ip: %.*s",
cnf_item.server_ip_.length(), cnf_item.server_ip_.ptr());
break;
}
}
else
{
cnf_item.server_ip_ = ObString::make_string("ANY"); // @see
}
/**
mysql> desc __all_sys_config;
+--------------+--------------+----------+------+---------+-------+
| field | type | nullable | key | default | extra |
+--------------+--------------+----------+------+---------+-------+
| gm_create | createtime | | 0 | NULL | |
| gm_modify | modifytime | | 0 | NULL | |
| cluster_id | int | | 1 | NULL | |
| svr_type | varchar(16) | | 2 | NULL | |
| svr_ip | varchar(32) | | 3 | NULL | |
| svr_port | int | | 4 | NULL | |
| name | varchar(256) | | 5 | NULL | |
| section | varchar(256) | | 0 | NULL | |
| data_type | varchar(256) | | 0 | NULL | |
| value | varchar(256) | | 0 | NULL | |
| value_strict | varchar(512) | | 0 | NULL | |
| info | varchar(512) | | 0 | NULL | |
+--------------+--------------+----------+------+---------+-------+
*/
int64_t pos = 0;
char sql_buff[OB_MAX_VARCHAR_LENGTH];
databuff_printf(sql_buff, OB_MAX_VARCHAR_LENGTH, pos,
"replace into %s"
"(cluster_id, svr_type, svr_ip, "
"svr_port, name, section, data_type, "
"value, value_strict, info) "
"values(%lu, '%s', '%.*s', %lu, '%.*s', 'unknown', '%s', '",
OB_ALL_SYS_CONFIG_TABLE_NAME,
cnf_item.cluster_id_ != OB_INVALID_ID ? cnf_item.cluster_id_ : 0,
print_role(cnf_item.server_type_),
cnf_item.server_ip_.length(), cnf_item.server_ip_.ptr(),
cnf_item.server_port_ != OB_INVALID_ID ? cnf_item.server_port_ : 0,
cnf_item.param_name_.length(), cnf_item.param_name_.ptr(),
ob_obj_type_str(cnf_item.param_value_.get_type()));
if (cnf_item.param_value_.get_type() == ObNullType)
{
databuff_printf(sql_buff, OB_MAX_VARCHAR_LENGTH, pos, "NULL");
}
else
{
char varchar_buf[OB_MAX_VARCHAR_LENGTH];
ObString varchar(OB_MAX_VARCHAR_LENGTH, OB_MAX_VARCHAR_LENGTH, varchar_buf);
ObObj casted_cell;
casted_cell.set_varchar(varchar);
const ObObj *res_value = NULL;
ObObj data_type;
data_type.set_type(ObVarcharType);
ObString val;
if ((ret = obj_cast(cnf_item.param_value_, data_type, casted_cell, res_value)) != OB_SUCCESS)
{
TBSYS_LOG(WARN, "Fail to cast obj, err=%d", ret);
//.........这里部分代码省略.........
示例13: check_having_ident
int ObSelectStmt::check_having_ident(
ResultPlan& result_plan,
ObString& column_name,
TableItem* table_item,
ObRawExpr*& ret_expr) const
{
ObSqlRawExpr *sql_expr;
ObRawExpr *expr;
ret_expr = NULL;
int& ret = result_plan.err_stat_.err_code_ = OB_SUCCESS;
ObLogicalPlan* logical_plan = static_cast<ObLogicalPlan*>(result_plan.plan_tree_);
if (logical_plan == NULL)
{
ret = OB_ERR_LOGICAL_PLAN_FAILD;
snprintf(result_plan.err_stat_.err_msg_, MAX_ERROR_MSG,
"Wrong invocation of ObStmt::add_table_item, logical_plan must exist!!!");
}
ObSchemaChecker* schema_checker = NULL;
if (ret == OB_SUCCESS)
{
schema_checker = static_cast<ObSchemaChecker*>(result_plan.schema_checker_);
if (schema_checker == NULL)
{
ret = OB_ERR_SCHEMA_UNSET;
snprintf(result_plan.err_stat_.err_msg_, MAX_ERROR_MSG,
"Schema(s) are not set");
}
}
for (int32_t i = 0; ret == OB_SUCCESS && i < select_items_.size(); i++)
{
const SelectItem& select_item = get_select_item(i);
// for single column expression, we already set it as alias name
if (column_name == select_item.alias_name_)
{
sql_expr = logical_plan->get_expr(select_item.expr_id_);
expr = sql_expr->get_expr();
if (table_item)
{
if (expr->get_expr_type() == T_REF_COLUMN)
{
ObBinaryRefRawExpr* col_expr = dynamic_cast<ObBinaryRefRawExpr *>(expr);
if (col_expr && col_expr->get_first_ref_id() == table_item->table_id_)
{
ColumnItem* column_item = get_column_item_by_id(col_expr->get_first_ref_id(), col_expr->get_second_ref_id());
if (column_item && column_item->column_name_ == column_name)
{
ObBinaryRefRawExpr *b_expr = (ObBinaryRefRawExpr*)parse_malloc(sizeof(ObBinaryRefRawExpr), name_pool_);
b_expr = new(b_expr) ObBinaryRefRawExpr();
b_expr->set_expr_type(T_REF_COLUMN);
b_expr->set_first_ref_id(col_expr->get_first_ref_id());
b_expr->set_second_ref_id(col_expr->get_second_ref_id());
ret_expr = b_expr;
break;
}
}
}
}
else
{
if (ret_expr)
{
ret = OB_ERR_COLUMN_AMBIGOUS;
snprintf(result_plan.err_stat_.err_msg_, MAX_ERROR_MSG,
"column %.*s of having clause is ambiguous", column_name.length(), column_name.ptr());
parse_free(ret_expr);
ret_expr = NULL;
break;
}
// for having clause: having cc > 0
// type 1: select t1.cc
if (expr->get_expr_type() == T_REF_COLUMN && !select_item.is_real_alias_)
{
ObBinaryRefRawExpr *col_expr = dynamic_cast<ObBinaryRefRawExpr *>(expr);
ObBinaryRefRawExpr *b_expr = (ObBinaryRefRawExpr*)parse_malloc(sizeof(ObBinaryRefRawExpr), name_pool_);
b_expr = new(b_expr) ObBinaryRefRawExpr();
b_expr->set_expr_type(T_REF_COLUMN);
b_expr->set_first_ref_id(col_expr->get_first_ref_id());
b_expr->set_second_ref_id(col_expr->get_second_ref_id());
ret_expr = b_expr;
}
// type 2: select t1.cc as cc
// type 3: select t1.c1 as cc
// type 4: select t1.c1 + t2.c1 as cc
else
{
ObBinaryRefRawExpr *b_expr = (ObBinaryRefRawExpr*)parse_malloc(sizeof(ObBinaryRefRawExpr), name_pool_);
b_expr = new(b_expr) ObBinaryRefRawExpr();
b_expr->set_expr_type(T_REF_COLUMN);
b_expr->set_first_ref_id(OB_INVALID_ID);
b_expr->set_second_ref_id(sql_expr->get_column_id());
ret_expr = b_expr;
}
}
}
}
// No non-duplicated ident found
if (ret == OB_SUCCESS && ret_expr == NULL)
//.........这里部分代码省略.........
示例14: strlen
TEST(ObObj,NOP)
{
ObObj src_obj;
ObObj mut_obj;
int64_t val = 0;
int64_t mutation = 5;
///create time
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_createtime(mutation);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_createtime(val),OB_SUCCESS);
ASSERT_EQ(val, mutation);
ASSERT_FALSE(src_obj.get_add());
///create time
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_modifytime(mutation);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_modifytime(val),OB_SUCCESS);
ASSERT_EQ(val, mutation);
ASSERT_FALSE(src_obj.get_add());
///precise time
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_precise_datetime(mutation);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_precise_datetime(val),OB_SUCCESS);
ASSERT_EQ(val, mutation);
ASSERT_FALSE(src_obj.get_add());
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_precise_datetime(mutation, true);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_precise_datetime(val),OB_SUCCESS);
ASSERT_EQ(val, mutation);
ASSERT_TRUE(src_obj.get_add());
///date time
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_datetime(mutation);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_datetime(val),OB_SUCCESS);
ASSERT_EQ(val, mutation);
ASSERT_FALSE(src_obj.get_add());
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_datetime(mutation, true);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_datetime(val),OB_SUCCESS);
ASSERT_EQ(val, mutation);
ASSERT_TRUE(src_obj.get_add());
/// int
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_int(mutation);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_int(val),OB_SUCCESS);
ASSERT_EQ(val, mutation);
ASSERT_FALSE(src_obj.get_add());
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_int(mutation, true);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_int(val),OB_SUCCESS);
ASSERT_EQ(val, mutation);
ASSERT_TRUE(src_obj.get_add());
/// obstring
const char * cname = "cname";
ObString str;
ObString res;
str.assign((char*)cname, static_cast<int32_t>(strlen(cname)));
src_obj.set_ext(ObActionFlag::OP_NOP);
mut_obj.set_varchar(str);
ASSERT_EQ(src_obj.apply(mut_obj),OB_SUCCESS);
ASSERT_EQ(src_obj.get_varchar(res),OB_SUCCESS);
ASSERT_EQ((uint64_t)res.length(), strlen(cname));
ASSERT_EQ(memcmp(res.ptr(),cname, res.length()), 0);
ASSERT_FALSE(src_obj.get_add());
}
示例15: while
TEST(TestMemTable, trans_set)
{
MemTable mt;
mt.init();
PageArena<char> allocer;
ObUpsMutator ups_mutator;
//ObMutator &mutator = ups_mutator.get_mutator();
ObMutator result;
ObScanParam scan_param;
read_scan_param("test_cases/test_mt_set.scan.ini", "MT_SET_SCAN", allocer, scan_param);
MemTableTransDescriptor td;
EXPECT_EQ(OB_SUCCESS, mt.start_transaction(WRITE_TRANSACTION, td));
EXPECT_NE(OB_SUCCESS, mt.start_transaction(WRITE_TRANSACTION, td));
_US_
// case begin
// 对于hash engine,测试在已经有rowkey A 的情况下,开一个事务按A B A的顺序写入,在结束事务的时候是否正常
// 避免出现结束事务时引用的rowkey是mutator临时申请的
ObUpsMutator ups_mutator;
ObMutator &mutator = ups_mutator.get_mutator();
ObMutator result;
read_cell_infos("test_cases/test_mt_set_unsorted.ci.ini", "MT_SET_UNSORTED_CI", allocer, mutator, result);
EXPECT_EQ(OB_SUCCESS, mt.start_mutation(td));
EXPECT_EQ(OB_SUCCESS, mt.set(td, ups_mutator));
EXPECT_EQ(OB_SUCCESS, mt.end_mutation(td, false));
EXPECT_EQ(OB_SUCCESS, mt.end_transaction(td, false));
EXPECT_EQ(OB_SUCCESS, mt.start_transaction(WRITE_TRANSACTION, td));
EXPECT_EQ(OB_SUCCESS, mt.start_mutation(td));
EXPECT_EQ(OB_SUCCESS, mt.set(td, ups_mutator));
// 此处模拟mutator被析构或重置
while (OB_SUCCESS == mutator.next_cell())
{
ObMutatorCellInfo *mutator_ci = NULL;
if (OB_SUCCESS == mutator.get_cell(&mutator_ci))
{
ObString rk = mutator_ci->cell_info.row_key_;
memset(rk.ptr(), 0, rk.length());
}
}
mutator.reset_iter();
EXPECT_EQ(OB_SUCCESS, mt.end_mutation(td, false));
EXPECT_EQ(OB_SUCCESS, mt.end_transaction(td, false));
mutator.reset();
result.reset();
read_cell_infos("test_cases/test_mt_ret_unsorted.ci.ini", "MT_RET_UNSORTED_CI", allocer, mutator, result);
MemTableIterator iter;
EXPECT_EQ(OB_SUCCESS, mt.start_transaction(READ_TRANSACTION, td));
EXPECT_EQ(OB_SUCCESS, mt.scan(td, *(scan_param.get_range()), false, iter));
ObRowCompaction rc;
rc.set_iterator(&iter);
while (OB_SUCCESS == result.next_cell())
{
ObMutatorCellInfo *ci_orig = NULL;
ObCellInfo *ci_scan = NULL;
EXPECT_EQ(OB_SUCCESS, rc.next_cell());
EXPECT_EQ(OB_SUCCESS, rc.get_cell(&ci_scan));
if (ObModifyTimeType == ci_scan->value_.get_type())
{
EXPECT_EQ(OB_SUCCESS, rc.next_cell());
EXPECT_EQ(OB_SUCCESS, rc.get_cell(&ci_scan));
}
if (ObCreateTimeType == ci_scan->value_.get_type())
{
EXPECT_EQ(OB_SUCCESS, rc.next_cell());
EXPECT_EQ(OB_SUCCESS, rc.get_cell(&ci_scan));
}
result.get_cell(&ci_orig);
EXPECT_EQ(true, equal(ci_orig->cell_info, *ci_scan));
}
EXPECT_EQ(OB_SUCCESS, mt.end_transaction(td, false));
mt.clear();
_UE_
// case end
EXPECT_EQ(OB_SUCCESS, mt.start_transaction(WRITE_TRANSACTION, td));
EXPECT_EQ(OB_SUCCESS, mt.start_mutation(td));
EXPECT_EQ(OB_SUCCESS, mt.set(td, ups_mutator));
// 事务没有提交,scan结果应该为空
_US_
MemTableTransDescriptor td;
MemTableIterator iter;
EXPECT_EQ(OB_SUCCESS, mt.start_transaction(READ_TRANSACTION, td));
_US_
MemTableTransDescriptor td;
EXPECT_EQ(OB_SUCCESS, mt.start_transaction(READ_TRANSACTION, td));
EXPECT_EQ(OB_SUCCESS, mt.end_transaction(td, false));
_UE_
EXPECT_EQ(OB_SUCCESS, mt.scan(td, *(scan_param.get_range()), false, iter));
EXPECT_EQ(OB_SUCCESS, mt.end_transaction(td, false));
EXPECT_EQ(OB_ITER_END, iter.next_cell());
_UE_
EXPECT_EQ(OB_SUCCESS, mt.end_mutation(td, false));
EXPECT_EQ(OB_SUCCESS, mt.end_transaction(td, false));
ObUpsMutator ups_mutator2;
ObMutator &mutator2 = ups_mutator2.get_mutator();
ObMutator result2;
read_cell_infos("test_cases/test_mt_trans_set.ci.ini", "MT_TRANS_SET_CI", allocer, mutator2, result2);
//.........这里部分代码省略.........