/* Clause 4.3.3.1 */ void gen_items() { FILE* output; int i; char a_string[128]; int j; char filename[1024] = "\0"; srand(0); printf("Generating item table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, ITEM_DATA); output = fopen(filename, "w"); if (output == nullptr) { printf("cannot open %s\n", ITEM_DATA); return; } // patched for hyrise - SB270911 if (mode_string == MODE_HYRISE) { gen_table_header(output, "item"); } for (i = 0; i < items; i++) { /* i_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* i_im_id */ FPRINTF(output, "%d", get_random(9999) + 1); METAPRINTF((output, "%c", delimiter)); /* i_name */ get_a_string(a_string, 14, 24); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* i_price */ FPRINTF(output, "%0.2f", ((double)get_random(9900) + 100.0) / 100.0); METAPRINTF((output, "%c", delimiter)); /* i_data */ get_a_string(a_string, 26, 50); if (get_percentage() < .10) { j = get_random(strlen(a_string) - 8); strncpy(a_string + j, "ORIGINAL", 8); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } fclose(output); printf("Finished item table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_warehouses() { FILE* output; int i; char a_string[48]; char filename[1024] = "\0"; srand(0); printf("Generating warehouse table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, WAREHOUSE_DATA); output = fopen(filename, "w"); if (output == nullptr) { printf("cannot open %s\n", WAREHOUSE_DATA); return; } // patched for hyrise - SB270911 if (mode_string == MODE_HYRISE) { gen_table_header(output, "warehouse"); } for (i = 0; i < warehouses; i++) { /* w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* w_name */ get_a_string(a_string, 6, 10); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* w_street_1 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* w_street_2 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* w_city */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* w_state */ get_l_string(a_string, 2, 2); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* w_zip */ get_n_string(a_string, 4, 4); FPRINTF(output, "%s11111", a_string); METAPRINTF((output, "%c", delimiter)); /* w_tax */ FPRINTF(output, "0.%04d", get_random(2000)); METAPRINTF((output, "%c", delimiter)); /* w_ytd */ FPRINTF2(output, "300000.00"); METAPRINTF((output, "\n")); } fclose(output); printf("Finished warehouse table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_stock() { FILE* output; int i, j, k; char a_string[128]; char filename[1024] = "\0"; srand(0); printf("Generating stock table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, STOCK_DATA); output = fopen(filename, "w"); if (output == nullptr) { printf("cannot open %s\n", STOCK_DATA); return; } // patched for hyrise - SB270911 if (mode_string == MODE_HYRISE) { gen_table_header(output, "stock"); } for (i = 0; i < warehouses; i++) { for (j = 0; j < items; j++) { /* s_i_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* s_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* s_quantity */ FPRINTF(output, "%d", get_random(90) + 10); METAPRINTF((output, "%c", delimiter)); /* s_dist_01 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_02 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_03 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_04 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_05 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_06 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_07 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_08 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_09 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_10 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_ytd */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_order_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_remote_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_data */ get_a_string(a_string, 26, 50); if (get_percentage() < .10) { k = get_random(strlen(a_string) - 8); strncpy(a_string + k, "ORIGINAL", 8); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } fclose(output); printf("Finished stock table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_history() { FILE* output; int i, j, k; char a_string[64]; struct tm* tm1; time_t t1; char filename[1024] = "\0"; srand(0); printf("Generating history table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, HISTORY_DATA); output = fopen(filename, "w"); if (output == nullptr) { printf("cannot open %s\n", HISTORY_DATA); return; } // patched for hyrise - SB270911 if (mode_string == MODE_HYRISE) { gen_table_header(output, "history"); } for (i = 0; i < warehouses; i++) { for (j = 0; j < DISTRICT_CARDINALITY; j++) { for (k = 0; k < customers; k++) { /* h_c_id */ FPRINTF(output, "%d", k + 1); METAPRINTF((output, "%c", delimiter)); /* h_c_d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* h_c_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* h_d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* h_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* h_date */ /* * Milliseconds are not calculated. This * should also be the time when the data is * loaded, I think. */ time(&t1); tm1 = localtime(&t1); print_timestamp(output, tm1); METAPRINTF((output, "%c", delimiter)); /* h_amount */ FPRINTF2(output, "10.00"); METAPRINTF((output, "%c", delimiter)); /* h_data */ get_a_string(a_string, 12, 24); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } } fclose(output); printf("Finished history table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_items() { FILE *output; int i; char a_string[128]; int j; char filename[1024] = "\0"; srand(0); printf("Generating item table data...\n"); if (mode_load == MODE_FLAT) { if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, ITEM_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", ITEM_DATA); return; } } else if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_PGSQL: output = popen("psql", "w"); if (output == NULL) { printf("error cannot open pipe for direct load\n"); return; } /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "BEGIN;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COPY item FROM STDIN DELIMITER '%c' NULL '%s';\n", delimiter, null_str); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; break; } } else { printf("error unknown load mode: %d\n", mode_load); } for (i = 0; i < items; i++) { /* i_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* i_im_id */ FPRINTF(output, "%d", get_random(9999) + 1); METAPRINTF((output, "%c", delimiter)); /* i_name */ get_a_string(a_string, 14, 24); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* i_price */ FPRINTF(output, "%0.2f", ((double) get_random(9900) + 100.0) / 100.0); METAPRINTF((output, "%c", delimiter)); /* i_data */ get_a_string(a_string, 26, 50); if (get_percentage() < .10) { j = get_random(strlen(a_string) - 8); strncpy(a_string + j, "ORIGINAL", 8); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } if (mode_load == MODE_FLAT) { fclose(output); } else { switch (mode_string) { case MODE_PGSQL: fprintf(output, "\\.\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COMMIT;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; pclose(output); break; } } printf("Finished item table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_customers() { FILE* output; int i, j, k; char a_string[1024]; struct tm* tm1; time_t t1; char filename[1024] = "\0"; srand(0); printf("Generating customer table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, CUSTOMER_DATA); output = fopen(filename, "w"); if (output == nullptr) { printf("cannot open %s\n", CUSTOMER_DATA); return; } // patched for hyrise - SB270911 if (mode_string == MODE_HYRISE) { gen_table_header(output, "customer"); } for (i = 0; i < warehouses; i++) { for (j = 0; j < DISTRICT_CARDINALITY; j++) { for (k = 0; k < customers; k++) { /* c_id */ FPRINTF(output, "%d", k + 1); METAPRINTF((output, "%c", delimiter)); /* c_d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* c_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* c_first */ get_a_string(a_string, 8, 16); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_middle */ FPRINTF2(output, "OE"); METAPRINTF((output, "%c", delimiter)); /* c_last Clause 4.3.2.7 */ if (k < 1000) { get_c_last(a_string, k); } else { get_c_last(a_string, get_nurand(255, 0, 999)); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_street_1 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_street_2 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_city */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_state */ get_l_string(a_string, 2, 2); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_zip */ get_n_string(a_string, 4, 4); FPRINTF(output, "%s11111", a_string); METAPRINTF((output, "%c", delimiter)); /* c_phone */ get_n_string(a_string, 16, 16); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_since */ /* * Milliseconds are not calculated. This * should also be the time when the data is * loaded, I think. */ time(&t1); tm1 = localtime(&t1); print_timestamp(output, tm1); METAPRINTF((output, "%c", delimiter)); /* c_credit */ if (get_percentage() < .10) { FPRINTF2(output, "BC"); } else { FPRINTF2(output, "GC"); } METAPRINTF((output, "%c", delimiter)); /* c_credit_lim */ FPRINTF2(output, "50000.00"); METAPRINTF((output, "%c", delimiter)); /* c_discount */ FPRINTF(output, "0.%04d", get_random(5000)); METAPRINTF((output, "%c", delimiter)); /* c_balance */ FPRINTF2(output, "-10.00"); METAPRINTF((output, "%c", delimiter)); /* c_ytd_payment */ FPRINTF2(output, "10.00"); METAPRINTF((output, "%c", delimiter)); /* c_payment_cnt */ FPRINTF2(output, "1"); METAPRINTF((output, "%c", delimiter)); /* c_delivery_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* c_data */ get_a_string(a_string, 300, 500); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } } fclose(output); printf("Finished customer table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_history() { FILE *output; int i, j, k; char a_string[64]; struct tm *tm1; time_t t1; char filename[1024] = "\0"; srand(0); printf("Generating history table data...\n"); if (mode_load == MODE_FLAT) { if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, HISTORY_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", HISTORY_DATA); return; } } else if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_PGSQL: output = popen("psql", "w"); if (output == NULL) { printf("error cannot open pipe for direct load\n"); return; } /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "BEGIN;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COPY history FROM STDIN DELIMITER '%c' NULL '%s';\n", delimiter, null_str); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; break; } } else { printf("error unknown load mode: %d\n", mode_load); } for (i = 0; i < warehouses; i++) { for (j = 0; j < DISTRICT_CARDINALITY; j++) { for (k = 0; k < customers; k++) { /* h_c_id */ FPRINTF(output, "%d", k + 1); METAPRINTF((output, "%c", delimiter)); /* h_c_d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* h_c_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* h_d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* h_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* h_date */ /* * Milliseconds are not calculated. This * should also be the time when the data is * loaded, I think. */ time(&t1); tm1 = localtime(&t1); print_timestamp(output, tm1); METAPRINTF((output, "%c", delimiter)); /* h_amount */ FPRINTF2(output, "10.00"); METAPRINTF((output, "%c", delimiter)); /* h_data */ get_a_string(a_string, 12, 24); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } } if (mode_load == MODE_FLAT) { fclose(output); } else { switch (mode_string) { case MODE_PGSQL: fprintf(output, "\\.\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COMMIT;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; pclose(output); break; } } printf("Finished history table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_districts() { FILE *output; int i, j; char a_string[48]; char filename[1024] = "\0"; srand(0); printf("Generating district table data...\n"); if (mode_load == MODE_FLAT) { if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, DISTRICT_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", DISTRICT_DATA); return; } } else if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_PGSQL: output = popen("psql", "w"); if (output == NULL) { printf("error cannot open pipe for direct load\n"); return; } /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "BEGIN;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COPY district FROM STDIN DELIMITER '%c' NULL '%s';\n", delimiter, null_str); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; break; } } else { printf("error unknown load mode: %d\n", mode_load); } for (i = 0; i < warehouses; i++) { for (j = 0; j < DISTRICT_CARDINALITY; j++) { /* d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* d_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* d_name */ get_a_string(a_string, 6, 10); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_street_1 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_street_2 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_city */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_state */ get_l_string(a_string, 2, 2); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_zip */ get_n_string(a_string, 4, 4); FPRINTF(output, "%s11111", a_string); METAPRINTF((output, "%c", delimiter)); /* d_tax */ FPRINTF(output, "0.%04d", get_random(2000)); METAPRINTF((output, "%c", delimiter)); /* d_ytd */ FPRINTF2(output, "30000.00"); METAPRINTF((output, "%c", delimiter)); /* d_next_o_id */ FPRINTF2(output, "3001"); METAPRINTF((output, "\n")); } } if (mode_load == MODE_FLAT) { fclose(output); } else { switch (mode_string) { case MODE_PGSQL: fprintf(output, "\\.\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COMMIT;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; pclose(output); break; } } printf("Finished district table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_customers() { FILE *output; int i, j, k; char a_string[1024]; struct tm *tm1; time_t t1; char filename[1024] = "\0"; srand(0); printf("Generating customer table data...\n"); if (mode_load == MODE_FLAT) { if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, CUSTOMER_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", CUSTOMER_DATA); return; } } else if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_PGSQL: output = popen("psql", "w"); if (output == NULL) { printf("error cannot open pipe for direct load\n"); return; } /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "BEGIN;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COPY customer FROM STDIN DELIMITER '%c' NULL '%s';\n", delimiter, null_str); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; break; } } else { printf("error unknown load mode: %d\n", mode_load); } for (i = 0; i < warehouses; i++) { for (j = 0; j < DISTRICT_CARDINALITY; j++) { for (k = 0; k < customers; k++) { /* c_id */ FPRINTF(output, "%d", k + 1); METAPRINTF((output, "%c", delimiter)); /* c_d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* c_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* c_first */ get_a_string(a_string, 8, 16); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_middle */ FPRINTF2(output, "OE"); METAPRINTF((output, "%c", delimiter)); /* c_last Clause 4.3.2.7 */ if (k < 1000) { get_c_last(a_string, k); } else { get_c_last(a_string, get_nurand(255, 0, 999)); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_street_1 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_street_2 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_city */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_state */ get_l_string(a_string, 2, 2); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_zip */ get_n_string(a_string, 4, 4); FPRINTF(output, "%s11111", a_string); METAPRINTF((output, "%c", delimiter)); /* c_phone */ get_n_string(a_string, 16, 16); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* c_since */ /* * Milliseconds are not calculated. This * should also be the time when the data is * loaded, I think. */ time(&t1); tm1 = localtime(&t1); print_timestamp(output, tm1); METAPRINTF((output, "%c", delimiter)); /* c_credit */ if (get_percentage() < .10) { FPRINTF2(output, "BC"); } else { FPRINTF2(output, "GC"); } METAPRINTF((output, "%c", delimiter)); /* c_credit_lim */ FPRINTF2(output, "50000.00"); METAPRINTF((output, "%c", delimiter)); /* c_discount */ FPRINTF(output, "0.%04d", get_random(5000)); METAPRINTF((output, "%c", delimiter)); /* c_balance */ FPRINTF2(output, "-10.00"); METAPRINTF((output, "%c", delimiter)); /* c_ytd_payment */ FPRINTF2(output, "10.00"); METAPRINTF((output, "%c", delimiter)); /* c_payment_cnt */ FPRINTF2(output, "1"); METAPRINTF((output, "%c", delimiter)); /* c_delivery_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* c_data */ get_a_string(a_string, 300, 500); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } } if (mode_load == MODE_FLAT) { fclose(output); } else { switch (mode_string) { case MODE_PGSQL: fprintf(output, "\\.\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COMMIT;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; pclose(output); break; } } printf("Finished customer table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_stock() { FILE *output; int i, j, k; char a_string[128]; char filename[1024] = "\0"; srand(0); printf("Generating stock table data...\n"); if (mode_load == MODE_FLAT) { if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, STOCK_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", STOCK_DATA); return; } } else if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_PGSQL: output = popen("psql", "w"); if (output == NULL) { printf("error cannot open pipe for direct load\n"); return; } /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "BEGIN;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COPY stock FROM STDIN DELIMITER '%c' NULL '%s';\n", delimiter, null_str); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; break; } } else { printf("error unknown load mode: %d\n", mode_load); } for (i = 0; i < warehouses; i++) { for (j = 0; j < items; j++) { /* s_i_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* s_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* s_quantity */ FPRINTF(output, "%d", get_random(90) + 10); METAPRINTF((output, "%c", delimiter)); /* s_dist_01 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_02 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_03 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_04 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_05 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_06 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_07 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_08 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_09 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_dist_10 */ get_l_string(a_string, 24, 24); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* s_ytd */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_order_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_remote_cnt */ FPRINTF2(output, "0"); METAPRINTF((output, "%c", delimiter)); /* s_data */ get_a_string(a_string, 26, 50); if (get_percentage() < .10) { k = get_random(strlen(a_string) - 8); strncpy(a_string + k, "ORIGINAL", 8); } escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "\n")); } } if (mode_load == MODE_FLAT) { fclose(output); } else { switch (mode_string) { case MODE_PGSQL: fprintf(output, "\\.\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; fprintf(output, "COMMIT;\n"); /* FIXME: Handle properly instead of blindly reading the output. */ while (fgetc(output) != EOF) ; pclose(output); break; } } printf("Finished stock table data...\n"); return; }
/* Clause 4.3.3.1 */ void gen_districts() { FILE *output; int i, j; char a_string[48]; char filename[1024] = "\0"; srand(0); printf("Generating district table data...\n"); if (strlen(output_path) > 0) { strcpy(filename, output_path); strcat(filename, "/"); } strcat(filename, DISTRICT_DATA); output = fopen(filename, "w"); if (output == NULL) { printf("cannot open %s\n", DISTRICT_DATA); return; } for (i = 0; i < warehouses; i++) { for (j = 0; j < DISTRICT_CARDINALITY; j++) { /* d_id */ FPRINTF(output, "%d", j + 1); METAPRINTF((output, "%c", delimiter)); /* d_w_id */ FPRINTF(output, "%d", i + 1); METAPRINTF((output, "%c", delimiter)); /* d_name */ get_a_string(a_string, 6, 10); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_street_1 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_street_2 */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_city */ get_a_string(a_string, 10, 20); escape_me(a_string); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_state */ get_l_string(a_string, 2, 2); FPRINTF(output, "%s", a_string); METAPRINTF((output, "%c", delimiter)); /* d_zip */ get_n_string(a_string, 4, 4); FPRINTF(output, "%s11111", a_string); METAPRINTF((output, "%c", delimiter)); /* d_tax */ FPRINTF(output, "0.%04d", get_random(2000)); METAPRINTF((output, "%c", delimiter)); /* d_ytd */ FPRINTF2(output, "30000.00"); METAPRINTF((output, "%c", delimiter)); /* d_next_o_id */ FPRINTF2(output, "3001"); METAPRINTF((output, "\n")); } } fclose(output); printf("Finished district table data...\n"); return; }