1 | /* |
2 | * general definitions and control information for the DSS code |
3 | * generator; if it controls the data set, it's here |
4 | */ |
5 | #ifndef DSS_H |
6 | #define DSS_H |
7 | |
8 | #ifdef __cplusplus |
9 | extern "C" { |
10 | #endif |
11 | |
12 | #ifdef TPCH |
13 | #define NAME "TPC-H" |
14 | #endif |
15 | #ifdef TPCR |
16 | #define NAME "TPC-R" |
17 | #endif |
18 | #ifndef NAME |
19 | #error Benchmark version must be defined in config.h |
20 | #endif |
21 | #define TPC "Transaction Processing Performance Council" |
22 | #define C_DATES "1994 - 2010" |
23 | |
24 | #include "config.h" |
25 | #include "shared.h" |
26 | |
27 | #include <stdio.h> |
28 | #include <stdlib.h> |
29 | |
30 | // some defines to avoid r warnings |
31 | #define exit(status) |
32 | #define printf(...) |
33 | #define fprintf(...) |
34 | |
35 | #define NONE -1 |
36 | #define PART 0 |
37 | #define PSUPP 1 |
38 | #define SUPP 2 |
39 | #define CUST 3 |
40 | #define ORDER 4 |
41 | #define LINE 5 |
42 | #define ORDER_LINE 6 |
43 | #define PART_PSUPP 7 |
44 | #define NATION 8 |
45 | #define REGION 9 |
46 | #define UPDATE 10 |
47 | #define MAX_TABLE 11 |
48 | #define ONE_STREAM 1 |
49 | #define ADD_AT_END 2 |
50 | |
51 | #ifdef MAX |
52 | #undef MAX |
53 | #endif |
54 | #ifdef MIN |
55 | #undef MIN |
56 | #endif |
57 | #define MAX(a, b) ((a > b) ? a : b) |
58 | #define MIN(A, B) ((A) < (B) ? (A) : (B)) |
59 | |
60 | #define INTERNAL_ERROR(p) // {fprintf(stderr,"%s", p);abort();} |
61 | #define LN_CNT 4 |
62 | // static char lnoise[4] = {'|', '/', '-', '\\' }; |
63 | #define LIFENOISE(n, var) // if (verbose > 0) fprintf(stderr, "%c\b", lnoise[(var%LN_CNT)]) |
64 | |
65 | #define MALLOC_CHECK(var) \ |
66 | if ((var) == NULL) { \ |
67 | fprintf(stderr, "Malloc failed at %s:%d\n", __FILE__, __LINE__); \ |
68 | exit(1); \ |
69 | } |
70 | #define OPEN_CHECK(var, path) \ |
71 | if ((var) == NULL) { \ |
72 | fprintf(stderr, "Open failed for %s at %s:%d\n", path, __FILE__, __LINE__); \ |
73 | exit(1); \ |
74 | } |
75 | #ifndef MAX_CHILDREN |
76 | #define MAX_CHILDREN 1000 |
77 | #endif |
78 | |
79 | /* |
80 | * macros that control sparse keys |
81 | * |
82 | * refer to Porting.Notes for a complete explanation |
83 | */ |
84 | #ifndef BITS_PER_LONG |
85 | #define BITS_PER_LONG 32 |
86 | #define MAX_LONG 0x7FFFFFFF |
87 | #endif /* BITS_PER_LONG */ |
88 | #define SPARSE_BITS 2 |
89 | #define SPARSE_KEEP 3 |
90 | #define MK_SPARSE(key, seq) (((((key >> 3) << 2) | (seq & 0x0003)) << 3) | (key & 0x0007)) |
91 | |
92 | #define RANDOM(tgt, lower, upper, stream) dss_random(&tgt, lower, upper, stream) |
93 | #define RANDOM64(tgt, lower, upper, stream) dss_random64(&tgt, lower, upper, stream) |
94 | |
95 | typedef struct { |
96 | long weight; |
97 | char *text; |
98 | } set_member; |
99 | |
100 | typedef struct { |
101 | int count; |
102 | int max; |
103 | set_member *list; |
104 | long *permute; |
105 | } distribution; |
106 | /* |
107 | * some handy access functions |
108 | */ |
109 | #define DIST_SIZE(d) d->count |
110 | #define DIST_MEMBER(d, i) ((set_member *)((d)->list + i))->text |
111 | #define DIST_PERMUTE(d, i) (d->permute[i]) |
112 | |
113 | typedef struct { |
114 | const char *name; |
115 | const char *; |
116 | DSS_HUGE base; |
117 | int (*loader)(); |
118 | long (*gen_seed)(); |
119 | int child; |
120 | DSS_HUGE vtotal; |
121 | } tdef; |
122 | |
123 | typedef struct SEED_T { |
124 | long table; |
125 | DSS_HUGE value; |
126 | DSS_HUGE usage; |
127 | DSS_HUGE boundary; |
128 | #ifdef RNG_TEST |
129 | DSS_HUGE nCalls; |
130 | #endif |
131 | } seed_t; |
132 | |
133 | #define PROTO(s) s |
134 | |
135 | /* bm_utils.c */ |
136 | const char *env_config PROTO((const char *var, const char *dflt)); |
137 | long yes_no PROTO((char *prompt)); |
138 | void a_rnd PROTO((int min, int max, int column, char *dest)); |
139 | int tx_rnd PROTO((long min, long max, long column, char *tgt)); |
140 | long julian PROTO((long date)); |
141 | long unjulian PROTO((long date)); |
142 | long dssncasecmp PROTO((const char *s1, const char *s2, int n)); |
143 | long dsscasecmp PROTO((const char *s1, const char *s2)); |
144 | int pick_str PROTO((distribution * s, int c, char *target)); |
145 | void agg_str PROTO((distribution * set, long count, long col, char *dest)); |
146 | void read_dist PROTO((const char *path, const char *name, distribution *target)); |
147 | void embed_str PROTO((distribution * d, int min, int max, int stream, char *dest)); |
148 | #ifndef STDLIB_HAS_GETOPT |
149 | int getopt PROTO((int arg_cnt, char **arg_vect, char *oprions)); |
150 | #endif /* STDLIB_HAS_GETOPT */ |
151 | DSS_HUGE set_state PROTO((int t, long scale, long procs, long step, DSS_HUGE *e)); |
152 | |
153 | /* rnd.c */ |
154 | DSS_HUGE NextRand PROTO((DSS_HUGE nSeed)); |
155 | DSS_HUGE UnifInt PROTO((DSS_HUGE nLow, DSS_HUGE nHigh, long nStream)); |
156 | void dss_random(DSS_HUGE *tgt, DSS_HUGE min, DSS_HUGE max, long seed); |
157 | void row_start(int t); |
158 | void row_stop_h(int t); |
159 | void dump_seeds_ds(int t); |
160 | |
161 | /* text.c */ |
162 | #define MAX_GRAMMAR_LEN 12 /* max length of grammar component */ |
163 | #define MAX_SENT_LEN 256 /* max length of populated sentence */ |
164 | #define RNG_PER_SENT 27 /* max number of RNG calls per sentence */ |
165 | |
166 | void dbg_text PROTO((char *t, int min, int max, int s)); |
167 | |
168 | #ifdef DECLARER |
169 | #define EXTERN |
170 | #else |
171 | #define EXTERN extern |
172 | #endif /* DECLARER */ |
173 | |
174 | EXTERN distribution nations; |
175 | EXTERN distribution nations2; |
176 | EXTERN distribution regions; |
177 | EXTERN distribution o_priority_set; |
178 | EXTERN distribution l_instruct_set; |
179 | EXTERN distribution l_smode_set; |
180 | EXTERN distribution l_category_set; |
181 | EXTERN distribution l_rflag_set; |
182 | EXTERN distribution c_mseg_set; |
183 | EXTERN distribution colors; |
184 | EXTERN distribution p_types_set; |
185 | EXTERN distribution p_cntr_set; |
186 | |
187 | /* distributions that control text generation */ |
188 | EXTERN distribution articles; |
189 | EXTERN distribution nouns; |
190 | EXTERN distribution adjectives; |
191 | EXTERN distribution adverbs; |
192 | EXTERN distribution prepositions; |
193 | EXTERN distribution verbs; |
194 | EXTERN distribution terminators; |
195 | EXTERN distribution auxillaries; |
196 | EXTERN distribution np; |
197 | EXTERN distribution vp; |
198 | EXTERN distribution grammar; |
199 | |
200 | EXTERN long scale; |
201 | EXTERN int refresh; |
202 | EXTERN int resume; |
203 | EXTERN long verbose; |
204 | EXTERN long force; |
205 | EXTERN long updates; |
206 | EXTERN long table; |
207 | EXTERN long children; |
208 | EXTERN int step; |
209 | EXTERN int set_seeds; |
210 | EXTERN char *d_path; |
211 | |
212 | /* added for segmented updates */ |
213 | EXTERN int insert_segments; |
214 | EXTERN int delete_segments; |
215 | EXTERN int insert_orders_segment; |
216 | EXTERN int insert_lineitem_segment; |
217 | EXTERN int delete_segment; |
218 | |
219 | #ifndef DECLARER |
220 | extern tdef tdefs[]; |
221 | |
222 | #endif /* DECLARER */ |
223 | |
224 | /***************************************************************** |
225 | ** table level defines use the following naming convention: t_ccc_xxx |
226 | ** with: t, a table identifier |
227 | ** ccc, a column identifier |
228 | ** xxx, a limit type |
229 | **************************************************************** |
230 | */ |
231 | |
232 | /* |
233 | * defines which control the parts table |
234 | */ |
235 | #define P_SIZE 126 |
236 | #define P_NAME_SCL 5 |
237 | #define P_MFG_TAG "Manufacturer#" |
238 | #define P_MFG_FMT "%%s%%0%d%s" |
239 | #define P_MFG_MIN 1 |
240 | #define P_MFG_MAX 5 |
241 | #define P_BRND_TAG "Brand#" |
242 | #define P_BRND_FMT "%%s%%0%d%s" |
243 | #define P_BRND_MIN 1 |
244 | #define P_BRND_MAX 5 |
245 | #define P_SIZE_MIN 1 |
246 | #define P_SIZE_MAX 50 |
247 | #define P_MCST_MIN 100 |
248 | #define P_MCST_MAX 99900 |
249 | #define P_MCST_SCL 100.0 |
250 | #define P_RCST_MIN 90000 |
251 | #define P_RCST_MAX 200000 |
252 | #define P_RCST_SCL 100.0 |
253 | /* |
254 | * defines which control the suppliers table |
255 | */ |
256 | #define S_SIZE 145 |
257 | #define S_NAME_TAG "Supplier#" |
258 | #define S_NAME_FMT "%%s%%0%d%s" |
259 | #define S_ABAL_MIN -99999 |
260 | #define S_ABAL_MAX 999999 |
261 | #define S_CMNT_MAX 101 |
262 | #define S_CMNT_BBB 10 /* number of BBB comments/SF */ |
263 | #define BBB_DEADBEATS 50 /* % that are complaints */ |
264 | #define BBB_BASE "Customer " |
265 | #define BBB_COMPLAIN "Complaints" |
266 | #define BBB_COMMEND "Recommends" |
267 | #define BBB_CMNT_LEN 19 |
268 | #define BBB_BASE_LEN 9 |
269 | #define BBB_TYPE_LEN 10 |
270 | |
271 | /* |
272 | * defines which control the partsupp table |
273 | */ |
274 | #define PS_SIZE 145 |
275 | #define PS_SKEY_MIN 0 |
276 | #define PS_SKEY_MAX ((tdefs[SUPP].base - 1) * scale) |
277 | #define PS_SCST_MIN 100 |
278 | #define PS_SCST_MAX 100000 |
279 | #define PS_QTY_MIN 1 |
280 | #define PS_QTY_MAX 9999 |
281 | /* |
282 | * defines which control the customers table |
283 | */ |
284 | #define C_SIZE 165 |
285 | #define C_NAME_TAG "Customer#" |
286 | #define C_NAME_FMT "%%s%%0%d%s" |
287 | #define C_MSEG_MAX 5 |
288 | #define C_ABAL_MIN -99999 |
289 | #define C_ABAL_MAX 999999 |
290 | /* |
291 | * defines which control the order table |
292 | */ |
293 | #define O_SIZE 109 |
294 | #define O_CKEY_MIN 1 |
295 | #define O_CKEY_MAX (tdefs[CUST].base * scale) |
296 | #define O_ODATE_MIN STARTDATE |
297 | #define O_ODATE_MAX (STARTDATE + TOTDATE - (L_SDTE_MAX + L_RDTE_MAX) - 1) |
298 | #define O_CLRK_TAG "Clerk#" |
299 | #define O_CLRK_FMT "%%s%%0%d%s" |
300 | #define O_CLRK_SCL 1000 |
301 | #define O_LCNT_MIN 1 |
302 | #define O_LCNT_MAX 7 |
303 | |
304 | /* |
305 | * defines which control the lineitem table |
306 | */ |
307 | #define L_SIZE 144L |
308 | #define L_QTY_MIN 1 |
309 | #define L_QTY_MAX 50 |
310 | #define L_TAX_MIN 0 |
311 | #define L_TAX_MAX 8 |
312 | #define L_DCNT_MIN 0 |
313 | #define L_DCNT_MAX 10 |
314 | #define L_PKEY_MIN 1 |
315 | #define L_PKEY_MAX (tdefs[PART].base * scale) |
316 | #define L_SDTE_MIN 1 |
317 | #define L_SDTE_MAX 121 |
318 | #define L_CDTE_MIN 30 |
319 | #define L_CDTE_MAX 90 |
320 | #define L_RDTE_MIN 1 |
321 | #define L_RDTE_MAX 30 |
322 | /* |
323 | * defines which control the time table |
324 | */ |
325 | #define T_SIZE 30 |
326 | #define T_START_DAY 3 /* wednesday ? */ |
327 | #define LEAP(y) ((!(y % 4) && (y % 100)) ? 1 : 0) |
328 | |
329 | /******************************************************************* |
330 | ******************************************************************* |
331 | *** |
332 | *** general or inter table defines |
333 | *** |
334 | ******************************************************************* |
335 | *******************************************************************/ |
336 | #define SUPP_PER_PART 4 |
337 | #define ORDERS_PER_CUST 10 /* sync this with CUST_MORTALITY */ |
338 | #define CUST_MORTALITY 3 /* portion with have no orders */ |
339 | #define NATIONS_MAX 90 /* limited by country codes in phone numbers */ |
340 | #define PHONE_FMT "%02d-%03d-%03d-%04d" |
341 | #define STARTDATE 92001 |
342 | #define CURRENTDATE 95168 |
343 | #define ENDDATE 98365 |
344 | #define TOTDATE 2557 |
345 | #define UPD_PCT 10 |
346 | #define MAX_STREAM 47 |
347 | #define V_STR_LOW 0.4 |
348 | #define PENNIES 100 /* for scaled int money arithmetic */ |
349 | #define Q11_FRACTION (double)0.0001 |
350 | /* |
351 | * max and min SF in GB; Larger SF will require changes to the build routines |
352 | */ |
353 | #define MIN_SCALE 1.0 |
354 | #define MAX_SCALE 100000.0 |
355 | /* |
356 | * beyond this point we need to allow for BCD calculations |
357 | */ |
358 | #define MAX_32B_SCALE 1000.0 |
359 | #define LONG2HUGE(src, dst) *dst = (DSS_HUGE)src |
360 | #define HUGE2LONG(src, dst) *dst = (long)src |
361 | #define HUGE_SET(src, dst) *dst = *src |
362 | #define HUGE_MUL(op1, op2) *op1 *= op2 |
363 | #define HUGE_DIV(op1, op2) *op1 /= op2 |
364 | #define HUGE_ADD(op1, op2, dst) *dst = *op1 + op2 |
365 | #define HUGE_SUB(op1, op2, dst) *dst = *op1 - op2 |
366 | #define HUGE_MOD(op1, op2) *op1 % op2 |
367 | #define HUGE_CMP(op1, op2) (*op1 == *op2) ? 0 : (*op1 < *op2) - 1 : 1 |
368 | |
369 | /******** environmental variables and defaults ***************/ |
370 | #define DIST_TAG "DSS_DIST" /* environment var to override ... */ |
371 | #define DIST_DFLT "dists.dss" /* default file to hold distributions */ |
372 | #define PATH_TAG "DSS_PATH" /* environment var to override ... */ |
373 | #define PATH_DFLT "." /* default directory to hold tables */ |
374 | #define CONFIG_TAG "DSS_CONFIG" /* environment var to override ... */ |
375 | #define CONFIG_DFLT "." /* default directory to config files */ |
376 | #define ADHOC_TAG "DSS_ADHOC" /* environment var to override ... */ |
377 | #define ADHOC_DFLT "adhoc.dss" /* default file name for adhoc vars */ |
378 | |
379 | /******* output macros ********/ |
380 | #ifndef SEPARATOR |
381 | #define SEPARATOR '|' /* field spearator for generated flat files */ |
382 | #endif |
383 | /* Data type flags for a single print routine */ |
384 | #define DT_STR 0 |
385 | #ifndef MVS |
386 | #define DT_VSTR DT_STR |
387 | #else |
388 | #define DT_VSTR 1 |
389 | #endif /* MVS */ |
390 | #define DT_INT 2 |
391 | #define DT_HUGE 3 |
392 | #define DT_KEY 4 |
393 | #define DT_MONEY 5 |
394 | #define DT_CHR 6 |
395 | |
396 | int dbg_print(int dt, FILE *tgt, void *data, int len, int eol); |
397 | #define PR_STR(f, str, len) dbg_print(DT_STR, f, (void *)str, len, 1) |
398 | #define PR_VSTR(f, str, len) dbg_print(DT_VSTR, f, (void *)str, len, 1) |
399 | #define PR_VSTR_LAST(f, str, len) dbg_print(DT_VSTR, f, (void *)str, len, 0) |
400 | #define PR_INT(f, str) dbg_print(DT_INT, f, (void *)str, 0, 1) |
401 | #define PR_HUGE(f, str) dbg_print(DT_HUGE, f, (void *)str, 0, 1) |
402 | #define PR_HUGE_LAST(f, str) dbg_print(DT_HUGE, f, (void *)str, 0, 0) |
403 | #define PR_KEY(f, str) dbg_print(DT_KEY, f, (void *)str, 0, -1) |
404 | #define PR_MONEY(f, str) dbg_print(DT_MONEY, f, (void *)str, 0, 1) |
405 | #define PR_CHR(f, str) dbg_print(DT_CHR, f, (void *)str, 0, 1) |
406 | #define PR_STRT(fp) /* any line prep for a record goes here */ |
407 | #define PR_END(fp) fprintf(fp, "\n") /* finish the record here */ |
408 | #ifdef MDY_DATE |
409 | #define PR_DATE(tgt, yr, mn, dy) sprintf(tgt, "%02d-%02d-19%02d", mn, dy, yr) |
410 | #else |
411 | #define PR_DATE(tgt, yr, mn, dy) sprintf(tgt, "19%02ld-%02ld-%02ld", yr, mn, dy) |
412 | #endif /* DATE_FORMAT */ |
413 | |
414 | /* |
415 | * verification macros |
416 | */ |
417 | #define VRF_STR(t, d) \ |
418 | { \ |
419 | char *xx = d; \ |
420 | while (*xx) \ |
421 | tdefs[t].vtotal += *xx++; \ |
422 | } |
423 | #define VRF_INT(t, d) tdefs[t].vtotal += d |
424 | #define VRF_HUGE(t, d) tdefs[t].vtotal = *((long *)&d) + *((long *)(&d + 1)) |
425 | /* assume float is a 64 bit quantity */ |
426 | #define VRF_MONEY(t, d) tdefs[t].vtotal = *((long *)&d) + *((long *)(&d + 1)) |
427 | #define VRF_CHR(t, d) tdefs[t].vtotal += d |
428 | #define VRF_STRT(t) |
429 | #define VRF_END(t) |
430 | |
431 | /*********** distribuitons currently defined *************/ |
432 | #define UNIFORM 0 |
433 | |
434 | /* |
435 | * seed indexes; used to separate the generation of individual columns |
436 | */ |
437 | #define P_MFG_SD 0 |
438 | #define P_BRND_SD 1 |
439 | #define P_TYPE_SD 2 |
440 | #define P_SIZE_SD 3 |
441 | #define P_CNTR_SD 4 |
442 | #define P_RCST_SD 5 |
443 | #define PS_QTY_SD 7 |
444 | #define PS_SCST_SD 8 |
445 | #define O_SUPP_SD 10 |
446 | #define O_CLRK_SD 11 |
447 | #define O_ODATE_SD 13 |
448 | #define L_QTY_SD 14 |
449 | #define L_DCNT_SD 15 |
450 | #define L_TAX_SD 16 |
451 | #define L_SHIP_SD 17 |
452 | #define L_SMODE_SD 18 |
453 | #define L_PKEY_SD 19 |
454 | #define L_SKEY_SD 20 |
455 | #define L_SDTE_SD 21 |
456 | #define L_CDTE_SD 22 |
457 | #define L_RDTE_SD 23 |
458 | #define L_RFLG_SD 24 |
459 | #define C_NTRG_SD 27 |
460 | #define C_PHNE_SD 28 |
461 | #define C_ABAL_SD 29 |
462 | #define C_MSEG_SD 30 |
463 | #define S_NTRG_SD 33 |
464 | #define S_PHNE_SD 34 |
465 | #define S_ABAL_SD 35 |
466 | #define P_NAME_SD 37 |
467 | #define O_PRIO_SD 38 |
468 | #define HVAR_SD 39 |
469 | #define O_CKEY_SD 40 |
470 | #define N_CMNT_SD 41 |
471 | #define R_CMNT_SD 42 |
472 | #define O_LCNT_SD 43 |
473 | #define BBB_JNK_SD 44 |
474 | #define BBB_TYPE_SD 45 |
475 | #define BBB_CMNT_SD 46 |
476 | #define BBB_OFFSET_SD 47 |
477 | |
478 | #ifdef __cplusplus |
479 | }; |
480 | #endif |
481 | |
482 | #endif /* DSS_H */ |
483 | |