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 "constants.h" |
40 | #include "address.h" |
41 | #include "w_web_site.h" |
42 | #include "genrand.h" |
43 | #include "tables.h" |
44 | #include "columns.h" |
45 | #include "scaling.h" |
46 | #include "build_support.h" |
47 | #include "misc.h" |
48 | #include "nulls.h" |
49 | #include "tdefs.h" |
50 | #include "scd.h" |
51 | |
52 | #include "append_info.h" |
53 | |
54 | struct W_WEB_SITE_TBL g_w_web_site; |
55 | static struct W_WEB_SITE_TBL g_OldValues; |
56 | |
57 | /* |
58 | * Routine: mk_web_site() |
59 | * Purpose: populate the web_site table |
60 | * Algorithm: |
61 | * Data Structures: |
62 | * |
63 | * Params: |
64 | * Returns: |
65 | * Called By: |
66 | * Calls: |
67 | * Assumptions: |
68 | * Side Effects: |
69 | * TODO: |
70 | */ |
71 | int mk_w_web_site(void *info_arr, ds_key_t index) { |
72 | int32_t nFieldChangeFlags, bFirstRecord = 0; |
73 | static decimal_t dMinTaxPercentage, dMaxTaxPercentage; |
74 | static int32_t bInit = 0; |
75 | |
76 | /* begin locals declarations */ |
77 | char szTemp[16], *sName1, *sName2; |
78 | struct W_WEB_SITE_TBL *r, *rOldValues = &g_OldValues; |
79 | tdef *pT = getSimpleTdefsByNumber(WEB_SITE); |
80 | |
81 | r = &g_w_web_site; |
82 | |
83 | if (!bInit) { |
84 | /* setup invariant values */ |
85 | sprintf(szTemp, "%d-%d-%d" , CURRENT_YEAR, CURRENT_MONTH, CURRENT_DAY); |
86 | strcpy(r->web_class, "Unknown" ); |
87 | strtodec(&dMinTaxPercentage, WEB_MIN_TAX_PERCENTAGE); |
88 | strtodec(&dMaxTaxPercentage, WEB_MAX_TAX_PERCENTAGE); |
89 | |
90 | bInit = 1; |
91 | } |
92 | |
93 | nullSet(&pT->kNullBitMap, WEB_NULLS); |
94 | r->web_site_sk = index; |
95 | |
96 | /* if we have generated the required history for this business key and |
97 | * generate a new one then reset associate fields (e.g., rec_start_date |
98 | * minimums) |
99 | */ |
100 | if (setSCDKeys(WEB_SITE_ID, index, r->web_site_id, &r->web_rec_start_date_id, &r->web_rec_end_date_id)) { |
101 | r->web_open_date = mk_join(WEB_OPEN_DATE, DATET, index); |
102 | r->web_close_date = mk_join(WEB_CLOSE_DATE, DATET, index); |
103 | if (r->web_close_date > r->web_rec_end_date_id) |
104 | r->web_close_date = -1; |
105 | sprintf(r->web_name, "site_%d" , (int)(index / 6)); |
106 | bFirstRecord = 1; |
107 | } |
108 | |
109 | /* |
110 | * this is where we select the random number that controls if a field |
111 | * changes from one record to the next. |
112 | */ |
113 | nFieldChangeFlags = next_random(WEB_SCD); |
114 | |
115 | /* the rest of the record in a history-keeping dimension can either be a new |
116 | * data value or not; use a random number and its bit pattern to determine |
117 | * which fields to replace and which to retain |
118 | */ |
119 | pick_distribution(&sName1, "first_names" , 1, 1, WEB_MANAGER); |
120 | pick_distribution(&sName2, "last_names" , 1, 1, WEB_MANAGER); |
121 | sprintf(r->web_manager, "%s %s" , sName1, sName2); |
122 | changeSCD(SCD_CHAR, &r->web_manager, &rOldValues->web_manager, &nFieldChangeFlags, bFirstRecord); |
123 | |
124 | genrand_integer(&r->web_market_id, DIST_UNIFORM, 1, 6, 0, WEB_MARKET_ID); |
125 | changeSCD(SCD_INT, &r->web_market_id, &rOldValues->web_market_id, &nFieldChangeFlags, bFirstRecord); |
126 | |
127 | gen_text(r->web_market_class, 20, RS_WEB_MARKET_CLASS, WEB_MARKET_CLASS); |
128 | changeSCD(SCD_CHAR, &r->web_market_class, &rOldValues->web_market_class, &nFieldChangeFlags, bFirstRecord); |
129 | |
130 | gen_text(r->web_market_desc, 20, RS_WEB_MARKET_DESC, WEB_MARKET_DESC); |
131 | changeSCD(SCD_CHAR, &r->web_market_desc, &rOldValues->web_market_desc, &nFieldChangeFlags, bFirstRecord); |
132 | |
133 | pick_distribution(&sName1, "first_names" , 1, 1, WEB_MARKET_MANAGER); |
134 | pick_distribution(&sName2, "last_names" , 1, 1, WEB_MARKET_MANAGER); |
135 | sprintf(r->web_market_manager, "%s %s" , sName1, sName2); |
136 | changeSCD(SCD_CHAR, &r->web_market_manager, &rOldValues->web_market_manager, &nFieldChangeFlags, bFirstRecord); |
137 | |
138 | genrand_integer(&r->web_company_id, DIST_UNIFORM, 1, 6, 0, WEB_COMPANY_ID); |
139 | changeSCD(SCD_INT, &r->web_company_id, &rOldValues->web_company_id, &nFieldChangeFlags, bFirstRecord); |
140 | |
141 | mk_word(r->web_company_name, "Syllables" , r->web_company_id, RS_WEB_COMPANY_NAME, WEB_COMPANY_NAME); |
142 | changeSCD(SCD_CHAR, &r->web_company_name, &rOldValues->web_company_name, &nFieldChangeFlags, bFirstRecord); |
143 | |
144 | mk_address(&r->web_address, WEB_ADDRESS); |
145 | changeSCD(SCD_PTR, &r->web_address.city, &rOldValues->web_address.city, &nFieldChangeFlags, bFirstRecord); |
146 | changeSCD(SCD_PTR, &r->web_address.county, &rOldValues->web_address.county, &nFieldChangeFlags, bFirstRecord); |
147 | changeSCD(SCD_INT, &r->web_address.gmt_offset, &rOldValues->web_address.gmt_offset, &nFieldChangeFlags, |
148 | bFirstRecord); |
149 | changeSCD(SCD_PTR, &r->web_address.state, &rOldValues->web_address.state, &nFieldChangeFlags, bFirstRecord); |
150 | changeSCD(SCD_PTR, &r->web_address.street_type, &rOldValues->web_address.street_type, &nFieldChangeFlags, |
151 | bFirstRecord); |
152 | changeSCD(SCD_PTR, &r->web_address.street_name1, &rOldValues->web_address.street_name1, &nFieldChangeFlags, |
153 | bFirstRecord); |
154 | changeSCD(SCD_PTR, &r->web_address.street_name2, &rOldValues->web_address.street_name2, &nFieldChangeFlags, |
155 | bFirstRecord); |
156 | changeSCD(SCD_INT, &r->web_address.street_num, &rOldValues->web_address.street_num, &nFieldChangeFlags, |
157 | bFirstRecord); |
158 | changeSCD(SCD_INT, &r->web_address.zip, &rOldValues->web_address.zip, &nFieldChangeFlags, bFirstRecord); |
159 | |
160 | genrand_decimal(&r->web_tax_percentage, DIST_UNIFORM, &dMinTaxPercentage, &dMaxTaxPercentage, NULL, |
161 | WEB_TAX_PERCENTAGE); |
162 | changeSCD(SCD_DEC, &r->web_tax_percentage, &rOldValues->web_tax_percentage, &nFieldChangeFlags, bFirstRecord); |
163 | |
164 | void *info = append_info_get(info_arr, WEB_SITE); |
165 | append_row_start(info); |
166 | |
167 | char szStreetName[128]; |
168 | |
169 | append_key(info, r->web_site_sk); |
170 | append_varchar(info, &r->web_site_id[0]); |
171 | append_date(info, (int)r->web_rec_start_date_id); |
172 | append_date(info, (int)r->web_rec_end_date_id); |
173 | append_varchar(info, &r->web_name[0]); |
174 | append_key(info, r->web_open_date); |
175 | append_key(info, r->web_close_date); |
176 | append_varchar(info, &r->web_class[0]); |
177 | append_varchar(info, &r->web_manager[0]); |
178 | append_integer(info, r->web_market_id); |
179 | append_varchar(info, &r->web_market_class[0]); |
180 | append_varchar(info, &r->web_market_desc[0]); |
181 | append_varchar(info, &r->web_market_manager[0]); |
182 | append_integer(info, r->web_company_id); |
183 | append_varchar(info, &r->web_company_name[0]); |
184 | append_integer(info, r->web_address.street_num); |
185 | if (r->web_address.street_name2) { |
186 | sprintf(szStreetName, "%s %s" , r->web_address.street_name1, r->web_address.street_name2); |
187 | append_varchar(info, szStreetName); |
188 | } else |
189 | append_varchar(info, r->web_address.street_name1); |
190 | append_varchar(info, r->web_address.street_type); |
191 | append_varchar(info, r->web_address.suite_num); |
192 | append_varchar(info, r->web_address.city); |
193 | append_varchar(info, r->web_address.county); |
194 | append_varchar(info, r->web_address.state); |
195 | sprintf(szStreetName, "%05d" , r->web_address.zip); |
196 | append_varchar(info, szStreetName); |
197 | append_varchar(info, r->web_address.country); |
198 | append_integer(info, r->web_address.gmt_offset); |
199 | append_decimal(info, &r->web_tax_percentage); |
200 | |
201 | append_row_end(info); |
202 | |
203 | return 0; |
204 | } |
205 | |