22 #ifndef Hypertable_Lib_DataGeneratorColumn_h
23 #define Hypertable_Lib_DataGeneratorColumn_h
72 m_next_qualifier = m_qualifiers.
size();
75 virtual bool next() = 0;
76 virtual std::string &qualifier() = 0;
77 virtual const char *value() = 0;
78 virtual uint32_t value_len() = 0;
87 :
Column(spec), m_keys_only(keys_only), m_first_offset(0), m_size(0),
89 std::string s = source;
95 HT_FATAL(
"Source file not specified for word stream");
97 HT_FATAL(
"Size not specified for word stream");
98 m_word_stream = make_shared<WordStream>(s, seed, size, order ==
RANDOM);
103 m_value_data_len = size;
105 m_value_data_len *= 50;
106 m_value_data.reset(
new char [ m_value_data_len+1 ] );
108 ((
char *)m_value_data.get())[m_value_data_len] = 0;
109 m_source = (
const char *)m_value_data.get();
117 m_value_data_len -= size;
118 if (cooked_source.empty())
119 m_render_buf.reset(
new char [size * 2 + 1] );
121 m_render_buf.reset(
new char [1024 * 10] );
133 size_t first_word_size {};
134 size_t second_word_size {};
135 if (!cooked_source.empty()) {
137 p = m_source + m_first_offset;
138 while (*p && *p !=
'\n') {
142 p = m_source + m_second_offset;
143 while (*p && *p !=
'\n') {
148 m_cooked.insert(m_cooked.end(), m_source + m_first_offset,
149 m_source + m_first_offset + first_word_size);
151 m_cooked.insert(m_cooked.end(), m_source + m_second_offset,
152 m_source + m_second_offset + second_word_size);
155 m_second_offset += second_word_size + 1;
156 if (m_second_offset >= m_value_data_len) {
158 m_first_offset += first_word_size + 1;
159 if (m_first_offset >= m_value_data_len)
162 m_size = m_cooked.size();
164 else if (!m_word_stream) {
169 if (m_qualifiers.empty())
170 m_next_qualifier = 0;
172 m_next_qualifier = (m_next_qualifier + 1) % m_qualifiers.size();
174 if (m_next_qualifier == 0 && !m_keys_only) {
176 m_value = m_word_stream->next();
180 if (!m_cooked.empty())
181 m_value = m_cooked.c_str();
183 m_value = m_source + offset;
186 const char *src = m_source + offset;
187 if (!m_cooked.empty())
188 src = m_cooked.c_str();
189 char *dst = m_render_buf.get();
190 for (
size_t i=0; i<(size_t)value_len(); i++) {
195 else if (*src ==
'\t') {
199 else if (*src ==
'\0') {
208 m_value = m_render_buf.get();
212 if (m_qualifiers.empty())
214 m_qualifiers[m_next_qualifier]->next();
215 if (m_next_qualifier == (m_qualifiers.size()-1))
221 if (m_qualifiers.empty())
223 return m_qualifiers[m_next_qualifier]->get();
232 return strlen(m_value);
233 return m_size ? m_size : size;
253 #endif // Hypertable_Lib_DataGeneratorColumn_h
boost::shared_array< const char > m_value_data
A class generating a stream of words; the words are retrieved from a file and can be randomized...
int32_t random_int32(int32_t maximum)
Generate random 32-bit integer.
static Qualifier * create(QualifierSpec &spec)
std::string cooked_source
WordStreamPtr m_word_stream
virtual const char * value()
virtual std::string & qualifier()
File system utility functions.
virtual uint32_t value_len()
std::shared_ptr< WordStream > WordStreamPtr
std::vector< Qualifier * > m_qualifiers
void random_fill_with_chars(char *buf, size_t len, const char *charset=nullptr)
Fills a buffer with random values from a set of characters.
static void * mmap(const String &fname, off_t *lenp)
Maps a full file into memory using mmap; the mapping will be released when the application terminates...
boost::shared_array< char > m_render_buf
std::string column_family
A String class based on std::string.
ColumnString(ColumnSpec &spec, bool keys_only=false)