8 using boost::minstd_rand;
9 using boost::uniform_real;
10 using boost::variate_generator;
11 using namespace impala;
32 for (
int i = 0; i <
cols_.size(); ++i) {
45 variate_generator<minstd_rand&, uniform_real<> >& rand) {
46 int min_len = min.
len;
47 int max_len = max.
len;
48 int len = r * (max_len - min_len) + min_len;
49 char* ptr =
reinterpret_cast<char*
>(pool->
Allocate(len));
53 for (
int i = 0; i < len; ++i) {
54 int min_char = i < min_len ? min.
ptr[i] :
'a';
55 int max_char = (i < max_len ? max.
ptr[i] :
'z') + 1;
56 ptr[i] = rand() * (max_char - min_char) + min_char;
62 *rows_returned = num_rows;
63 if (num_rows == 0)
return NULL;
66 uniform_real<> dist(0,1);
67 variate_generator<minstd_rand&, uniform_real<> > rand_double(
rand_generator_, dist);
69 char* data =
data_.get();
70 for (
int i = 0, row_idx =
rows_returned_; i < num_rows; ++i, ++row_idx) {
71 for (
int j = 0; j <
cols_.size(); ++j) {
72 double r = rand_double();
76 *
reinterpret_cast<bool*
>(data) = col.
Generate<
bool>(r, row_idx);
79 *
reinterpret_cast<int8_t*
>(data) = col.
Generate<int8_t>(r, row_idx);
82 *
reinterpret_cast<int16_t*
>(data) = col.
Generate<int16_t>(r, row_idx);
85 *
reinterpret_cast<int32_t*
>(data) = col.
Generate<int32_t>(r, row_idx);
88 *
reinterpret_cast<int64_t*
>(data) = col.
Generate<int64_t>(r, row_idx);
91 *
reinterpret_cast<float*
>(data) = col.
Generate<
float>(r, row_idx);
94 *
reinterpret_cast<double*
>(data) = col.
Generate<
double>(r, row_idx);
110 return reinterpret_cast<void*
>(
data_.get());
114 char* next_col =
reinterpret_cast<char*
>(data);
115 for (
int i = 0; i < rows; ++i) {
116 for (
int j = 0; j <
cols_.size(); ++j) {
117 switch (
cols_[j].type) {
119 *stream << (*reinterpret_cast<int8_t*>(next_col) ?
"true" :
"false");
122 *stream << (int)*reinterpret_cast<int8_t*>(next_col);
125 *stream << *reinterpret_cast<int16_t*>(next_col);
128 *stream << *reinterpret_cast<int32_t*>(next_col);
131 *stream << *reinterpret_cast<int64_t*>(next_col);
134 *stream << *reinterpret_cast<float*>(next_col);
137 *stream << *reinterpret_cast<double*>(next_col);
141 *stream << *reinterpret_cast<StringValue*>(next_col);
144 *stream <<
"BAD" << endl;
147 if (j !=
cols_.size() - 1) *stream <<
", ";
148 next_col +=
cols_[j].bytes;
void Reset(int num_rows, int batch_size, const std::vector< ColDesc > &columns)
void * NextBatch(int *rows_returned)
#define COUNTER_ADD(c, v)
impala::RuntimeProfile::Counter * bytes_generated_
boost::minstd_rand rand_generator_
T Generate(double d, int i) const
std::vector< ColDesc > cols_
#define ADD_COUNTER(profile, name, unit)
impala::PrimitiveType type
#define COUNTER_SET(c, v)
boost::scoped_ptr< char > data_
void RandString(MemPool *pool, StringValue *result, const StringValue &min, const StringValue &max, double r, variate_generator< minstd_rand &, uniform_real<> > &rand)
DataProvider(impala::MemPool *pool, impala::RuntimeProfile *profile)
void Print(std::ostream *, char *data, int num_rows) const
Print the row data in csv format.
uint8_t * Allocate(int size)