27 #include <boost/algorithm/string.hpp>
28 #include <boost/shared_array.hpp>
41 boost::shared_array<char> line_ptr;
42 char *base, *ptr, *last;
47 static char emptybuf[] = { 0 };
49 while (getline(m_fin, line)) {
54 line_ptr.reset(
new char [strlen(line.c_str()) + 1]);
55 base = line_ptr.get();
56 strcpy(base, line.c_str());
58 if ((ptr = strtok_r(base,
"\t", &last)) == 0) {
59 cerr <<
"Mal-formed input on line " << (m_cur_line-1) << endl;
63 if (!strcasecmp(ptr,
"AUTO")) {
67 timestamp = strtoll(ptr, 0, 0);
68 if (timestamp == 0 && errno == EINVAL) {
69 cerr <<
"Invalid timestamp (" << ptr <<
") on line " << (m_cur_line-1)
73 if (m_min_timestamp == 0 || timestamp < m_min_timestamp)
74 m_min_timestamp = timestamp;
77 if ((rowkey = strtok_r(0,
"\t", &last)) == 0) {
78 cerr <<
"Mal-formed input on line " << (m_cur_line-1) << endl;
85 size_t row_key_len = strlen(rowkey);
86 if (row_key_len >= 2) {
87 if (!strcmp(&rowkey[row_key_len-2],
"??")) {
88 rowkey[row_key_len-1] = (char)0xff;
89 rowkey[row_key_len-2] = (char)0xff;
93 if ((column = strtok_r(0,
"\t", &last)) == 0) {
94 cerr <<
"Mal-formed input on line " << (m_cur_line-1) << endl;
98 if (!strcmp(column,
"DELETE")) {
99 if (!create_row_delete(rowkey, timestamp, key, value)) {
100 cerr <<
"Mal-formed input on line " << (m_cur_line-1) << endl;
106 if ((value_str = strtok_r(0,
"\t", &last)) == 0)
107 value_str = emptybuf;
109 if (!strcmp(value_str,
"DELETE")) {
110 if (!create_column_delete(rowkey, column, timestamp, key, value)) {
111 cerr <<
"Mal-formed input on line " << (m_cur_line-1) << endl;
117 row_key_len = strlen(value_str);
118 if (row_key_len >= 2) {
119 if (!strcmp(&value_str[row_key_len-2],
"??")) {
120 value_str[row_key_len-1] = (char)0xff;
121 value_str[row_key_len-2] = (char)0xff;
122 cerr <<
"converting end of value (" << value_str <<
")" << endl;
126 if (!create_insert(rowkey, column, timestamp, value_str, key, value)) {
127 cerr <<
"Mal-formed input on line " << (m_cur_line-1) << endl;
139 TestSource::create_row_delete(
const char *row, int64_t timestamp,
141 int32_t keylen = strlen(row) + 13;
149 m_key_buffer.clear();
150 m_key_buffer.ensure(keylen+6);
153 *m_key_buffer.ptr++ = control;
154 m_key_buffer.add_unchecked(row, strlen(row)+1);
155 *m_key_buffer.ptr++ = 0;
156 *m_key_buffer.ptr++ = 0;
158 Key::encode_ts64(&m_key_buffer.ptr, timestamp);
160 key.
ptr = m_key_buffer.base;
162 m_value_buffer.clear();
164 value.
ptr = m_value_buffer.base;
170 TestSource::create_column_delete(
const char *row,
const char *column,
174 const char *qualifier =
"";
175 const char *ptr = strchr(column,
':');
177 bool col_family_delete =
false;
185 col_family_delete =
true;
186 cfstr = string(column);
189 cfstr = string(column, ptr-column);
195 cerr <<
"Column family '" << cfstr <<
"' not found in schema" << endl;
199 if(col_family_delete) {
200 m_key_buffer.clear();
201 keylen = strlen(row) + 13;
202 m_key_buffer.ensure(keylen+6);
205 *m_key_buffer.ptr++ = control;
206 m_key_buffer.add_unchecked(row, strlen(row)+1);
207 *m_key_buffer.ptr++ = cf_spec->
get_id();
208 *m_key_buffer.ptr++ = 0;
210 Key::encode_ts64(&m_key_buffer.ptr, timestamp);
212 key.
ptr = m_key_buffer.base;
214 m_value_buffer.clear();
216 value.
ptr = m_value_buffer.base;
219 m_key_buffer.clear();
220 keylen = strlen(row) + strlen(qualifier) + 13;
221 m_key_buffer.ensure(keylen+6);
224 *m_key_buffer.ptr++ = control;
225 m_key_buffer.add_unchecked(row, strlen(row)+1);
226 *m_key_buffer.ptr++ = cf_spec->
get_id();
227 m_key_buffer.add_unchecked(qualifier, strlen(qualifier)+1);
229 Key::encode_ts64(&m_key_buffer.ptr, timestamp);
231 key.
ptr = m_key_buffer.base;
233 m_value_buffer.clear();
235 value.
ptr = m_value_buffer.base;
243 TestSource::create_insert(
const char *row,
const char *column,
244 int64_t timestamp,
const char *value_str,
ByteString &key,
248 const char *qualifier;
249 const char *ptr = strchr(column,
':');
258 cerr <<
"Bad column family specifier (no family)" << endl;
262 cfstr = string(column, ptr-column);
267 cerr <<
"Column family '" << cfstr <<
"' not found in schema" << endl;
271 m_key_buffer.clear();
272 keylen = strlen(row) + strlen(qualifier) + 13;
273 m_key_buffer.ensure(keylen+6);
276 *m_key_buffer.ptr++ = control;
277 m_key_buffer.add_unchecked(row, strlen(row)+1);
278 *m_key_buffer.ptr++ = cf_spec->
get_id();
279 m_key_buffer.add_unchecked(qualifier, strlen(qualifier)+1);
281 Key::encode_ts64(&m_key_buffer.ptr, timestamp);
283 key.
ptr = m_key_buffer.base;
285 m_value_buffer.clear();
287 value.
ptr = m_value_buffer.base;
static const uint32_t FLAG_DELETE_ROW
static const uint32_t FLAG_INSERT
Column family specification.
static const uint32_t FLAG_DELETE_CELL
static const uint32_t FLAG_DELETE_COLUMN_FAMILY
void append_as_byte_string(DynamicBuffer &dst_buf, const void *value, uint32_t value_len)
Serializes and appends a byte array to a DynamicBuffer object.
A class managing one or more serializable ByteStrings.
A dynamic, resizable memory buffer.
Compatibility Macros for C/C++.
int32_t get_id() const
Gets column ID.
const uint8_t * ptr
The pointer to the serialized data.
void encode_vi32(uint8_t **bufp, uint32_t val)
Encode a integer (up to 32-bit) in variable length encoding.
A String class based on std::string.
static const int64_t AUTO_ASSIGN