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); } }
void test_write_one_file() { ObSSTableSchemaColumnDef column_def; ObSSTableSchema schema; ObSSTableRow row; char *compressor_name = (char*)COMPRESSOR_NAME; ObSSTableWriter writer; ObString file_name(static_cast<int32_t>(strlen(sstable_path) + 1), static_cast<int32_t>(strlen(sstable_path) + 1), sstable_path); ObString compressor(static_cast<int32_t>(strlen(compressor_name) + 1), static_cast<int32_t>(strlen(compressor_name) + 1), compressor_name); int64_t disk_usage = 0; int64_t trailer_offset = 0; ObObj obj; ObObj key_obj; uint64_t table_id = 0; uint64_t column_group_id = 0; char value_data[1024 + 1]; char rowkey_str[32]; ObString row_key; ObRowkey key; char *ptr; int ret; // init schema for (int64_t i = 0; i < 5; ++i) { column_def.table_id_ = static_cast<uint32_t>(1025 + i); // add rowkey column column_def.column_group_id_ = 0; column_def.column_name_id_ = 1; column_def.column_value_type_ = ObVarcharType; column_def.rowkey_seq_ = 1; schema.add_column_def(column_def); for ( int j = 0; j < 10 ; ++j) { column_def.column_group_id_ = static_cast<uint16_t>(j); column_def.column_name_id_ = 2; column_def.column_value_type_ = ObDoubleType; column_def.rowkey_seq_ = 0; schema.add_column_def(column_def); column_def.column_name_id_ = 3; column_def.column_value_type_ = ObIntType; column_def.rowkey_seq_ = 0; schema.add_column_def(column_def); column_def.column_name_id_ = 4; column_def.column_value_type_ = ObVarcharType; column_def.rowkey_seq_ = 0; schema.add_column_def(column_def); } } //build data ptr = value_data; for (int64_t i = 0; i < 128; ++i) { memcpy(ptr, "testing ", 8); ptr += 8; } ObString value_str(1025, 1025, value_data); writer.set_dio(true); int64_t start_time = tbsys::CTimeUtil::getTime(); // create sstable file if (OB_ERROR == (ret = writer.create_sstable(schema, file_name, compressor, 2))) { TBSYS_LOG(ERROR, "Failed to create sstable file: %s", sstable_path); } for (int64_t i = 0; i < 5000000; ++i) { row.clear(); table_id = i / 1000000 + 1025; column_group_id = i % 1000000 / 100000; row.set_table_id(table_id); row.set_column_group_id(column_group_id); sprintf(rowkey_str, "row_key_%08ld", i); row_key.assign(rowkey_str, 16); key_obj.set_varchar(row_key); key.assign(&key_obj, 1); row.set_rowkey(key); obj.set_double((double)i); row.add_obj(obj); obj.set_int(i); row.add_obj(obj); obj.set_varchar(value_str); row.add_obj(obj); if (OB_ERROR == (ret = writer.append_row(row, disk_usage))) { TBSYS_LOG(ERROR, "add row failed, i=%ld", i); return; } } if (OB_ERROR == (ret = writer.close_sstable(trailer_offset))) { TBSYS_LOG(ERROR, "close sstable failed ------------------"); } printf("test_write_one_file, run_time=%ld\n", tbsys::CTimeUtil::getTime() - start_time); //remove(sstable_path); }