TEST_F(ObTabletJoinTest, get_right_table_rowkey) { ObRowDesc row_desc; row_desc.add_column_desc(LEFT_TABLE_ID, 1); const char *rowkey_str = "oceanbase"; ObString row_key_str; row_key_str.assign_ptr(const_cast<char *>(rowkey_str), (int32_t)strlen(rowkey_str)); ObObj row_key_obj; row_key_obj.set_varchar(row_key_str); ObRowkey row_key; row_key.assign(&row_key_obj, 1); ObObj value; value.set_varchar(row_key_str); ObRow row; row.set_row_desc(row_desc); row.raw_set_cell(0, value); ObObj rowkey_obj[OB_MAX_ROWKEY_COLUMN_NUMBER]; ObRowkey rowkey2; ObTabletCacheJoin tablet_join; tablet_join.set_table_join_info(tablet_join_info_); OK(tablet_join.get_right_table_rowkey(row, rowkey2, rowkey_obj)); ASSERT_TRUE(row_key == rowkey2); }
int ObMultipleScanMerge::write_row(ObRow &row) { int ret = OB_SUCCESS; const ObRowDesc *row_desc = NULL; const ObObj *cell = NULL; ObObj value; uint64_t table_id = OB_INVALID_ID; uint64_t column_id = OB_INVALID_ID; row_desc = row.get_row_desc(); if (NULL == row_desc) { ret = OB_INVALID_ARGUMENT; TBSYS_LOG(WARN, "row_desc is null"); } for (int64_t i = row_desc->get_rowkey_cell_count(); 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, "fail to get cell:ret[%d]", ret); } else if (OB_SUCCESS != (ret = ob_write_obj(allocator_, *cell, value) )) { TBSYS_LOG(WARN, "fail to write obj:ret[%d]", ret); } else if (OB_SUCCESS != (ret = row.raw_set_cell(i, value) )) { TBSYS_LOG(WARN, "fail to set cell:ret[%d]", ret); } } return ret; }
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)); }
TEST_F(ObRowFuseTest, basic_test) { ObRowDesc row_desc; uint64_t table_id = 1000; for(int i=0;i<8;i++) { row_desc.add_column_desc(table_id, OB_APP_MIN_COLUMN_ID + i); } ObUpsRow ups_row; ups_row.set_row_desc(row_desc); ups_row.set_delete_row(false); ObObj cell; for(int i=0;i<8;i++) { cell.set_int(i, true); ups_row.raw_set_cell(i, cell); } ObRow row; row.set_row_desc(row_desc); for(int i=0;i<8;i++) { cell.set_int(i); row.raw_set_cell(i, cell); } ObRow result; ObRowFuse::fuse_row(&ups_row, &row, &result); const ObObj *result_cell = NULL; uint64_t result_table_id = 0; uint64_t result_column_id = 0; int64_t int_value = 0; for(int i=0;i<8;i++) { result.raw_get_cell(i, result_cell, result_table_id, result_column_id); result_cell->get_int(int_value); ASSERT_EQ(i * 2, int_value); } ups_row.set_delete_row(true); ObRowFuse::fuse_row(&ups_row, &row, &result); for(int i=0;i<8;i++) { result.raw_get_cell(i, result_cell, result_table_id, result_column_id); result_cell->get_int(int_value); ASSERT_EQ(i, int_value); } for(int i=0;i<8;i++) { cell.set_int(i, false); ups_row.raw_set_cell(i, cell); } ups_row.set_delete_row(false); ObRowFuse::fuse_row(&ups_row, &row, &result); for(int i=0;i<8;i++) { result.raw_get_cell(i, result_cell, result_table_id, result_column_id); result_cell->get_int(int_value); ASSERT_EQ(i, int_value); } }
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)); }
// 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() ); }
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); } } }