1 | /* |
2 | * Legal Notice |
3 | * |
4 | * This document and associated source code (the "Work") is a part of a |
5 | * benchmark specification maintained by the TPC. |
6 | * |
7 | * The TPC reserves all right, title, and interest to the Work as provided |
8 | * under U.S. and international laws, including without limitation all patent |
9 | * and trademark rights therein. |
10 | * |
11 | * No Warranty |
12 | * |
13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
23 | * WITH REGARD TO THE WORK. |
24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
32 | * |
33 | * Contributors: |
34 | * Gradient Systems |
35 | */ |
36 | #include "config.h" |
37 | #include "porting.h" |
38 | #include <stdio.h> |
39 | #include "genrand.h" |
40 | #include "w_promotion.h" |
41 | #include "columns.h" |
42 | #include "build_support.h" |
43 | #include "tables.h" |
44 | #include "misc.h" |
45 | #include "nulls.h" |
46 | #include "tdefs.h" |
47 | |
48 | #include "append_info.h" |
49 | |
50 | struct W_PROMOTION_TBL g_w_promotion; |
51 | |
52 | /* |
53 | * Routine: mk_promotion |
54 | * Purpose: populate the promotion table |
55 | * Algorithm: |
56 | * Data Structures: |
57 | * |
58 | * Params: |
59 | * Returns: |
60 | * Called By: |
61 | * Calls: |
62 | * Assumptions: |
63 | * Side Effects: |
64 | * TODO: |
65 | * 20020829 jms RNG usage on p_promo_name may be too large |
66 | * 20020829 jms RNG usage on P_CHANNEL_DETAILS may be too large |
67 | */ |
68 | int mk_w_promotion(void *info_arr, ds_key_t index) { |
69 | static int bInit = 0; |
70 | struct W_PROMOTION_TBL *r; |
71 | |
72 | /* begin locals declarations */ |
73 | static date_t start_date; |
74 | ds_key_t nTemp; |
75 | int nFlags; |
76 | tdef *pTdef = getSimpleTdefsByNumber(PROMOTION); |
77 | |
78 | r = &g_w_promotion; |
79 | |
80 | if (!bInit) { |
81 | memset(&g_w_promotion, 0, sizeof(struct W_PROMOTION_TBL)); |
82 | bInit = 1; |
83 | strtodt(&start_date, DATE_MINIMUM); |
84 | } |
85 | |
86 | nullSet(&pTdef->kNullBitMap, P_NULLS); |
87 | r->p_promo_sk = index; |
88 | mk_bkey(&r->p_promo_id[0], index, P_PROMO_ID); |
89 | nTemp = index; |
90 | r->p_start_date_id = start_date.julian + genrand_integer(NULL, DIST_UNIFORM, PROMO_START_MIN, PROMO_START_MAX, |
91 | PROMO_START_MEAN, P_START_DATE_ID); |
92 | r->p_end_date_id = r->p_start_date_id + |
93 | genrand_integer(NULL, DIST_UNIFORM, PROMO_LEN_MIN, PROMO_LEN_MAX, PROMO_LEN_MEAN, P_END_DATE_ID); |
94 | r->p_item_sk = mk_join(P_ITEM_SK, ITEM, 1); |
95 | strtodec(&r->p_cost, "1000.00" ); |
96 | r->p_response_target = 1; |
97 | mk_word(&r->p_promo_name[0], "syllables" , (int)index, PROMO_NAME_LEN, P_PROMO_NAME); |
98 | nFlags = genrand_integer(NULL, DIST_UNIFORM, 0, 511, 0, P_CHANNEL_DMAIL); |
99 | r->p_channel_dmail = nFlags & 0x01; |
100 | nFlags <<= 1; |
101 | r->p_channel_email = nFlags & 0x01; |
102 | nFlags <<= 1; |
103 | r->p_channel_catalog = nFlags & 0x01; |
104 | nFlags <<= 1; |
105 | r->p_channel_tv = nFlags & 0x01; |
106 | nFlags <<= 1; |
107 | r->p_channel_radio = nFlags & 0x01; |
108 | nFlags <<= 1; |
109 | r->p_channel_press = nFlags & 0x01; |
110 | nFlags <<= 1; |
111 | r->p_channel_event = nFlags & 0x01; |
112 | nFlags <<= 1; |
113 | r->p_channel_demo = nFlags & 0x01; |
114 | nFlags <<= 1; |
115 | r->p_discount_active = nFlags & 0x01; |
116 | gen_text(&r->p_channel_details[0], PROMO_DETAIL_LEN_MIN, PROMO_DETAIL_LEN_MAX, P_CHANNEL_DETAILS); |
117 | pick_distribution(&r->p_purpose, "promo_purpose" , 1, 1, P_PURPOSE); |
118 | |
119 | void *info = append_info_get(info_arr, PROMOTION); |
120 | append_row_start(info); |
121 | append_key(info, r->p_promo_sk); |
122 | append_varchar(info, r->p_promo_id); |
123 | append_key(info, r->p_start_date_id); |
124 | append_key(info, r->p_end_date_id); |
125 | append_key(info, r->p_item_sk); |
126 | append_decimal(info, &r->p_cost); |
127 | append_integer(info, r->p_response_target); |
128 | append_varchar(info, &r->p_promo_name[0]); |
129 | append_boolean(info, r->p_channel_dmail); |
130 | append_boolean(info, r->p_channel_email); |
131 | append_boolean(info, r->p_channel_catalog); |
132 | append_boolean(info, r->p_channel_tv); |
133 | append_boolean(info, r->p_channel_radio); |
134 | append_boolean(info, r->p_channel_press); |
135 | append_boolean(info, r->p_channel_event); |
136 | append_boolean(info, r->p_channel_demo); |
137 | append_varchar(info, &r->p_channel_details[0]); |
138 | append_varchar(info, r->p_purpose); |
139 | append_boolean(info, r->p_discount_active); |
140 | |
141 | append_row_end(info); |
142 | |
143 | return 0; |
144 | } |
145 | |