MCPcopy Create free account
hub / github.com/baidu/tera / ModifyTable

Function ModifyTable

src/sample/tera_sample.cc:60–98  ·  view source on GitHub ↗

修改一个表的内容

Source from the content-addressed store, hash-verified

58
59/// 修改一个表的内容
60int ModifyTable(tera::Table* table) {
61 tera::ErrorCode error_code;
62
63 // 修改需要先创建一个 RowMutation
64
65 tera::RowMutation* row = table->NewRowMutation("com.baidu.www/");
66 // 写一个column
67 row->Put("title", "abc", "Baidu.com");
68 row->Put("title", "abd", "Baidu.com");
69 row->Put("title", "abe", "Baidu.com");
70 row->Put("title", "abf", "Baidu.com");
71 row->Put("anchor", "www.hao123.com/", "百度");
72 row->Put("html", "", time(NULL), "<html>Test content</html>");
73 // 删除一个column过去24小时内的所有版本
74 // row->DeleteColumns("title", "abc", time(NULL), time(NULL) - 86400);
75 // 删除一个column24小时之前的所有版本
76 row->DeleteColumns("title", "abd", time(NULL) - 86400);
77 // 删除一个column的所有版本
78 row->DeleteColumns("title", "abe");
79 // 删除一个columnfamily的所有列
80 row->DeleteFamily("links");
81
82 // 提交修改
83 table->ApplyMutation(row);
84 printf("Write to table : %s\n", tera::strerr(row->GetError()));
85 delete row;
86
87 // 批量提交修改
88 tera::RowMutation* row2 = table->NewRowMutation("com.baidu.tieba/");
89 // 删除一行的所有column family
90 row2->DeleteRow();
91 std::vector<tera::RowMutation*> mutation_list;
92 mutation_list.push_back(row2);
93 table->ApplyMutation(mutation_list);
94 printf("Write to table : %s\n", tera::strerr(mutation_list[0]->GetError()));
95 delete row2;
96
97 return 0;
98}
99
100/// 扫描一个表
101int ScanTable(tera::Table* table) {

Callers 1

ShowBigTableFunction · 0.85

Calls 9

strerrFunction · 0.85
push_backMethod · 0.80
NewRowMutationMethod · 0.45
PutMethod · 0.45
DeleteColumnsMethod · 0.45
DeleteFamilyMethod · 0.45
ApplyMutationMethod · 0.45
GetErrorMethod · 0.45
DeleteRowMethod · 0.45

Tested by

no test coverage detected