OmniSciDB  343343d194
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
anonymous_namespace{DataGen.cpp} Namespace Reference

Functions

std::default_random_engine random_gen (std::random_device{}())
 
std::string gen_int ()
 
std::string gen_real ()
 
std::string gen_string ()
 
std::string gen_bool ()
 
std::string gen_time ()
 
std::string gen_timestamp ()
 
std::string gen_date ()
 
void data_gen (const TRowDescriptor &row_desc, const char *delimiter, int num_rows)
 

Variables

const int max_str_len = 100
 

Function Documentation

void anonymous_namespace{DataGen.cpp}::data_gen ( const TRowDescriptor &  row_desc,
const char *  delimiter,
int  num_rows 
)

Definition at line 138 of file DataGen.cpp.

References gen_bool(), gen_date(), gen_int(), gen_real(), gen_string(), gen_time(), gen_timestamp(), and num_rows.

Referenced by main().

138  {
139  for (int i = 0; i < num_rows; i++) {
140  bool not_first = false;
141  for (auto p = row_desc.begin(); p != row_desc.end(); ++p) {
142  if (not_first) {
143  std::cout << delimiter;
144  } else {
145  not_first = true;
146  }
147  switch (p->col_type.type) {
148  case TDatumType::SMALLINT:
149  case TDatumType::INT:
150  case TDatumType::BIGINT:
151  std::cout << gen_int();
152  break;
153  case TDatumType::FLOAT:
154  case TDatumType::DOUBLE:
155  case TDatumType::DECIMAL:
156  std::cout << gen_real();
157  break;
158  case TDatumType::STR:
159  std::cout << gen_string();
160  break;
161  case TDatumType::TIME:
162  std::cout << gen_time();
163  break;
164  case TDatumType::TIMESTAMP:
165  case TDatumType::INTERVAL_DAY_TIME:
166  case TDatumType::INTERVAL_YEAR_MONTH:
167  std::cout << gen_timestamp();
168  break;
169  case TDatumType::DATE:
170  std::cout << gen_date();
171  break;
172  case TDatumType::BOOL:
173  std::cout << gen_bool();
174  break;
175  default:
176  std::cout << "???";
177  break;
178  }
179  }
180  std::cout << std::endl;
181  }
182 }
const int8_t const int64_t * num_rows

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string anonymous_namespace{DataGen.cpp}::gen_bool ( )

Definition at line 98 of file DataGen.cpp.

Referenced by data_gen().

98  {
99  std::uniform_int_distribution<int> dist(0, 1);
100  if (dist(random_gen) == 1) {
101  return "t";
102  }
103  return "f";
104 }
std::default_random_engine random_gen(std::random_device{}())

+ Here is the caller graph for this function:

std::string anonymous_namespace{DataGen.cpp}::gen_date ( )

Definition at line 127 of file DataGen.cpp.

Referenced by data_gen().

127  {
128  std::uniform_int_distribution<int> dist(0, INT32_MAX);
129  time_t t = dist(random_gen);
130  std::tm* tm_ptr = gmtime(&t);
131  char buf[11];
132  strftime(buf, 11, "%F", tm_ptr);
133  return buf;
134 }
std::default_random_engine random_gen(std::random_device{}())

+ Here is the caller graph for this function:

std::string anonymous_namespace{DataGen.cpp}::gen_int ( )

Definition at line 71 of file DataGen.cpp.

References to_string().

Referenced by data_gen().

71  {
72  std::uniform_int_distribution<int> dist(INT_MIN, INT_MAX);
73  return std::to_string(dist(random_gen));
74 }
std::default_random_engine random_gen(std::random_device{}())
std::string to_string(char const *&&v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string anonymous_namespace{DataGen.cpp}::gen_real ( )

Definition at line 77 of file DataGen.cpp.

References to_string().

Referenced by data_gen().

77  {
78  std::uniform_real_distribution<float> dist(0.0, 1.0);
79  return std::to_string(dist(random_gen));
80 }
std::default_random_engine random_gen(std::random_device{}())
std::string to_string(char const *&&v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string anonymous_namespace{DataGen.cpp}::gen_string ( )

Definition at line 85 of file DataGen.cpp.

Referenced by data_gen().

85  {
86  std::string chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
87  std::uniform_int_distribution<> char_dist(0, chars.size() - 1);
88  std::uniform_int_distribution<> len_dist(0, max_str_len);
89  int len = len_dist(random_gen);
90  std::string s(len, ' ');
91  for (int i = 0; i < len; i++) {
92  s[i] = chars[char_dist(random_gen)];
93  }
94  return s;
95 }
std::default_random_engine random_gen(std::random_device{}())

+ Here is the caller graph for this function:

std::string anonymous_namespace{DataGen.cpp}::gen_time ( )

Definition at line 107 of file DataGen.cpp.

Referenced by data_gen().

107  {
108  std::uniform_int_distribution<int> dist(0, INT32_MAX);
109  time_t t = dist(random_gen);
110  std::tm* tm_ptr = gmtime(&t);
111  char buf[9];
112  strftime(buf, 9, "%T", tm_ptr);
113  return buf;
114 }
std::default_random_engine random_gen(std::random_device{}())

+ Here is the caller graph for this function:

std::string anonymous_namespace{DataGen.cpp}::gen_timestamp ( )

Definition at line 117 of file DataGen.cpp.

Referenced by data_gen().

117  {
118  std::uniform_int_distribution<int> dist(0, INT32_MAX);
119  time_t t = dist(random_gen);
120  std::tm* tm_ptr = gmtime(&t);
121  char buf[20];
122  strftime(buf, 20, "%F %T", tm_ptr);
123  return buf;
124 }
std::default_random_engine random_gen(std::random_device{}())

+ Here is the caller graph for this function:

std::default_random_engine anonymous_namespace{DataGen.cpp}::random_gen ( std::random_device{}  ())

Variable Documentation

const int anonymous_namespace{DataGen.cpp}::max_str_len = 100

Definition at line 82 of file DataGen.cpp.