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 "columns.h" |
41 | #include "w_customer.h" |
42 | #include "genrand.h" |
43 | #include "build_support.h" |
44 | #include "tables.h" |
45 | #include "nulls.h" |
46 | #include "tdefs.h" |
47 | |
48 | #include "append_info.h" |
49 | |
50 | struct W_CUSTOMER_TBL g_w_customer; |
51 | /* extern tdef w_tdefs[]; */ |
52 | |
53 | /* |
54 | * Routine: mk_customer |
55 | * Purpose: populate the customer dimension |
56 | * Algorithm: |
57 | * Data Structures: |
58 | * |
59 | * Params: |
60 | * Returns: |
61 | * Called By: |
62 | * Calls: |
63 | * Assumptions: |
64 | * Side Effects: |
65 | * TODO: |
66 | */ |
67 | int mk_w_customer(void *info_arr, ds_key_t index) { |
68 | int nTemp; |
69 | |
70 | static int nBaseDate; |
71 | /* begin locals declarations */ |
72 | int nNameIndex, nGender; |
73 | struct W_CUSTOMER_TBL *r; |
74 | static int bInit = 0; |
75 | date_t dtTemp; |
76 | static date_t dtBirthMin, dtBirthMax, dtToday, dt1YearAgo, dt10YearsAgo; |
77 | tdef *pT = getSimpleTdefsByNumber(CUSTOMER); |
78 | |
79 | r = &g_w_customer; |
80 | |
81 | if (!bInit) { |
82 | date_t min_date; |
83 | strtodt(&min_date, DATE_MINIMUM); |
84 | nBaseDate = dttoj(&min_date); |
85 | |
86 | strtodt(&dtBirthMax, "1992-12-31" ); |
87 | strtodt(&dtBirthMin, "1924-01-01" ); |
88 | strtodt(&dtToday, TODAYS_DATE); |
89 | jtodt(&dt1YearAgo, dtToday.julian - 365); |
90 | jtodt(&dt10YearsAgo, dtToday.julian - 3650); |
91 | |
92 | bInit = 1; |
93 | } |
94 | |
95 | nullSet(&pT->kNullBitMap, C_NULLS); |
96 | r->c_customer_sk = index; |
97 | mk_bkey(&r->c_customer_id[0], index, C_CUSTOMER_ID); |
98 | genrand_integer(&nTemp, DIST_UNIFORM, 1, 100, 0, C_PREFERRED_CUST_FLAG); |
99 | r->c_preferred_cust_flag = (nTemp < C_PREFERRED_PCT) ? 1 : 0; |
100 | |
101 | /* demographic keys are a composite of values. rebuild them a la |
102 | * bitmap_to_dist */ |
103 | r->c_current_hdemo_sk = mk_join(C_CURRENT_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1); |
104 | |
105 | r->c_current_cdemo_sk = mk_join(C_CURRENT_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1); |
106 | |
107 | r->c_current_addr_sk = mk_join(C_CURRENT_ADDR_SK, CUSTOMER_ADDRESS, r->c_customer_sk); |
108 | nNameIndex = pick_distribution(&r->c_first_name, "first_names" , 1, 3, C_FIRST_NAME); |
109 | pick_distribution(&r->c_last_name, "last_names" , 1, 1, C_LAST_NAME); |
110 | dist_weight(&nGender, "first_names" , nNameIndex, 2); |
111 | pick_distribution(&r->c_salutation, "salutations" , 1, (nGender == 0) ? 2 : 3, C_SALUTATION); |
112 | |
113 | genrand_date(&dtTemp, DIST_UNIFORM, &dtBirthMin, &dtBirthMax, NULL, C_BIRTH_DAY); |
114 | r->c_birth_day = dtTemp.day; |
115 | r->c_birth_month = dtTemp.month; |
116 | r->c_birth_year = dtTemp.year; |
117 | genrand_email(r->c_email_address, r->c_first_name, r->c_last_name, C_EMAIL_ADDRESS); |
118 | genrand_date(&dtTemp, DIST_UNIFORM, &dt1YearAgo, &dtToday, NULL, C_LAST_REVIEW_DATE); |
119 | r->c_last_review_date = dtTemp.julian; |
120 | genrand_date(&dtTemp, DIST_UNIFORM, &dt10YearsAgo, &dtToday, NULL, C_FIRST_SALES_DATE_ID); |
121 | r->c_first_sales_date_id = dtTemp.julian; |
122 | r->c_first_shipto_date_id = r->c_first_sales_date_id + 30; |
123 | |
124 | pick_distribution(&r->c_birth_country, "countries" , 1, 1, C_BIRTH_COUNTRY); |
125 | |
126 | void *info = append_info_get(info_arr, CUSTOMER); |
127 | append_row_start(info); |
128 | |
129 | append_key(info, r->c_customer_sk); |
130 | append_varchar(info, r->c_customer_id); |
131 | append_key(info, r->c_current_cdemo_sk); |
132 | append_key(info, r->c_current_hdemo_sk); |
133 | append_key(info, r->c_current_addr_sk); |
134 | append_integer(info, r->c_first_shipto_date_id); |
135 | append_integer(info, r->c_first_sales_date_id); |
136 | append_varchar(info, r->c_salutation); |
137 | append_varchar(info, r->c_first_name); |
138 | append_varchar(info, r->c_last_name); |
139 | append_boolean(info, r->c_preferred_cust_flag); |
140 | append_integer(info, r->c_birth_day); |
141 | append_integer(info, r->c_birth_month); |
142 | append_integer(info, r->c_birth_year); |
143 | append_varchar(info, r->c_birth_country); |
144 | append_varchar(info, &r->c_login[0]); |
145 | append_varchar(info, &r->c_email_address[0]); |
146 | append_integer(info, r->c_last_review_date); |
147 | |
148 | append_row_end(info); |
149 | |
150 | return 0; |
151 | } |
152 | |