| 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 "w_web_page.h" |
| 41 | #include "date.h" |
| 42 | #include "decimal.h" |
| 43 | #include "genrand.h" |
| 44 | #include "build_support.h" |
| 45 | #include "misc.h" |
| 46 | #include "scaling.h" |
| 47 | #include "constants.h" |
| 48 | #include "tables.h" |
| 49 | #include "nulls.h" |
| 50 | #include "tdefs.h" |
| 51 | #include "scd.h" |
| 52 | |
| 53 | #include "append_info.h" |
| 54 | |
| 55 | struct W_WEB_PAGE_TBL g_w_web_page; |
| 56 | static struct W_WEB_PAGE_TBL g_OldValues; |
| 57 | |
| 58 | /* |
| 59 | * Routine: mk_web_page() |
| 60 | * Purpose: populate the web_page table |
| 61 | * Algorithm: |
| 62 | * Data Structures: |
| 63 | * |
| 64 | * Params: |
| 65 | * Returns: |
| 66 | * Called By: |
| 67 | * Calls: |
| 68 | * Assumptions: |
| 69 | * Side Effects: |
| 70 | * TODO: |
| 71 | * 20020815 jms check text generation/seed usage |
| 72 | */ |
| 73 | int mk_w_web_page(void *info_arr, ds_key_t index) { |
| 74 | int32_t bFirstRecord = 0, nFieldChangeFlags; |
| 75 | static date_t dToday; |
| 76 | static ds_key_t nConcurrent, nRevisions; |
| 77 | |
| 78 | /* begin locals declarations */ |
| 79 | int32_t nTemp, nAccess; |
| 80 | char szTemp[16]; |
| 81 | static int32_t bInit = 0; |
| 82 | struct W_WEB_PAGE_TBL *r, *rOldValues = &g_OldValues; |
| 83 | tdef *pT = getSimpleTdefsByNumber(WEB_PAGE); |
| 84 | |
| 85 | r = &g_w_web_page; |
| 86 | |
| 87 | if (!bInit) { |
| 88 | /* setup invariant values */ |
| 89 | sprintf(szTemp, "%d-%d-%d" , CURRENT_YEAR, CURRENT_MONTH, CURRENT_DAY); |
| 90 | strtodt(&dToday, szTemp); |
| 91 | |
| 92 | /* set up for the SCD handling */ |
| 93 | nConcurrent = (int)get_rowcount(CONCURRENT_WEB_SITES); |
| 94 | nRevisions = (int)get_rowcount(WEB_PAGE) / nConcurrent; |
| 95 | |
| 96 | bInit = 1; |
| 97 | } |
| 98 | |
| 99 | nullSet(&pT->kNullBitMap, WP_NULLS); |
| 100 | r->wp_page_sk = index; |
| 101 | |
| 102 | /* if we have generated the required history for this business key and |
| 103 | * generate a new one then reset associate fields (e.g., rec_start_date |
| 104 | * minimums) |
| 105 | */ |
| 106 | if (setSCDKeys(WP_PAGE_ID, index, r->wp_page_id, &r->wp_rec_start_date_id, &r->wp_rec_end_date_id)) { |
| 107 | |
| 108 | /* |
| 109 | * some fields are not changed, even when a new version of the row is |
| 110 | * written |
| 111 | */ |
| 112 | bFirstRecord = 1; |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * this is where we select the random number that controls if a field |
| 117 | * changes from one record to the next. |
| 118 | */ |
| 119 | nFieldChangeFlags = next_random(WP_SCD); |
| 120 | |
| 121 | r->wp_creation_date_sk = mk_join(WP_CREATION_DATE_SK, DATET, index); |
| 122 | changeSCD(SCD_KEY, &r->wp_creation_date_sk, &rOldValues->wp_creation_date_sk, &nFieldChangeFlags, bFirstRecord); |
| 123 | |
| 124 | genrand_integer(&nAccess, DIST_UNIFORM, 0, WP_IDLE_TIME_MAX, 0, WP_ACCESS_DATE_SK); |
| 125 | r->wp_access_date_sk = dToday.julian - nAccess; |
| 126 | changeSCD(SCD_KEY, &r->wp_access_date_sk, &rOldValues->wp_access_date_sk, &nFieldChangeFlags, bFirstRecord); |
| 127 | if (r->wp_access_date_sk == 0) |
| 128 | r->wp_access_date_sk = -1; /* special case for dates */ |
| 129 | |
| 130 | genrand_integer(&nTemp, DIST_UNIFORM, 0, 99, 0, WP_AUTOGEN_FLAG); |
| 131 | r->wp_autogen_flag = (nTemp < WP_AUTOGEN_PCT) ? 1 : 0; |
| 132 | changeSCD(SCD_INT, &r->wp_autogen_flag, &rOldValues->wp_autogen_flag, &nFieldChangeFlags, bFirstRecord); |
| 133 | |
| 134 | r->wp_customer_sk = mk_join(WP_CUSTOMER_SK, CUSTOMER, 1); |
| 135 | changeSCD(SCD_KEY, &r->wp_customer_sk, &rOldValues->wp_customer_sk, &nFieldChangeFlags, bFirstRecord); |
| 136 | |
| 137 | if (!r->wp_autogen_flag) |
| 138 | r->wp_customer_sk = -1; |
| 139 | |
| 140 | genrand_url(r->wp_url, WP_URL); |
| 141 | changeSCD(SCD_CHAR, &r->wp_url, &rOldValues->wp_url, &nFieldChangeFlags, bFirstRecord); |
| 142 | |
| 143 | pick_distribution(&r->wp_type, "web_page_use" , 1, 1, WP_TYPE); |
| 144 | changeSCD(SCD_PTR, &r->wp_type, &rOldValues->wp_type, &nFieldChangeFlags, bFirstRecord); |
| 145 | |
| 146 | genrand_integer(&r->wp_link_count, DIST_UNIFORM, WP_LINK_MIN, WP_LINK_MAX, 0, WP_LINK_COUNT); |
| 147 | changeSCD(SCD_INT, &r->wp_link_count, &rOldValues->wp_link_count, &nFieldChangeFlags, bFirstRecord); |
| 148 | |
| 149 | genrand_integer(&r->wp_image_count, DIST_UNIFORM, WP_IMAGE_MIN, WP_IMAGE_MAX, 0, WP_IMAGE_COUNT); |
| 150 | changeSCD(SCD_INT, &r->wp_image_count, &rOldValues->wp_image_count, &nFieldChangeFlags, bFirstRecord); |
| 151 | |
| 152 | genrand_integer(&r->wp_max_ad_count, DIST_UNIFORM, WP_AD_MIN, WP_AD_MAX, 0, WP_MAX_AD_COUNT); |
| 153 | changeSCD(SCD_INT, &r->wp_max_ad_count, &rOldValues->wp_max_ad_count, &nFieldChangeFlags, bFirstRecord); |
| 154 | |
| 155 | genrand_integer(&r->wp_char_count, DIST_UNIFORM, r->wp_link_count * 125 + r->wp_image_count * 50, |
| 156 | r->wp_link_count * 300 + r->wp_image_count * 150, 0, WP_CHAR_COUNT); |
| 157 | changeSCD(SCD_INT, &r->wp_char_count, &rOldValues->wp_char_count, &nFieldChangeFlags, bFirstRecord); |
| 158 | |
| 159 | void *info = append_info_get(info_arr, WEB_PAGE); |
| 160 | append_row_start(info); |
| 161 | |
| 162 | append_key(info, r->wp_page_sk); |
| 163 | append_varchar(info, r->wp_page_id); |
| 164 | append_date(info, r->wp_rec_start_date_id); |
| 165 | append_date(info, r->wp_rec_end_date_id); |
| 166 | append_key(info, r->wp_creation_date_sk); |
| 167 | append_key(info, r->wp_access_date_sk); |
| 168 | append_boolean(info, r->wp_autogen_flag); |
| 169 | append_key(info, r->wp_customer_sk); |
| 170 | append_varchar(info, &r->wp_url[0]); |
| 171 | append_varchar(info, &r->wp_type[0]); |
| 172 | append_integer(info, r->wp_char_count); |
| 173 | append_integer(info, r->wp_link_count); |
| 174 | append_integer(info, r->wp_image_count); |
| 175 | append_integer(info, r->wp_max_ad_count); |
| 176 | append_row_end(info); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |