/* Clause 2.6.1 */
int generate_order_status_data(int w_id, struct order_status_t *data)
{
	bzero(data, sizeof(struct order_status_t));
	data->c_w_id = w_id;
	data->c_d_id = get_random(D_ID_MAX) + 1;

	/* Select a customer by last name 60%, byt c_id 40% of the time. */
	if (get_random(100) < 60) {
		data->c_id = C_ID_UNKNOWN;
		get_c_last(data->c_last, get_nurand(255, 0, 999));
	} else {
		data->c_id = get_nurand(1023, 1, 3000);
	}

	return OK;
}
/* Clause 2.5.1 */
int generate_payment_data(int w_id, struct payment_t *data)
{
	bzero(data, sizeof(struct payment_t));
	data->w_id = w_id;
	data->d_id = get_random(D_ID_MAX) + 1;

	/* Select a customer by last name 60%, byt c_id 40% of the time. */
	if (get_random(100) < 60) {
		data->c_id = C_ID_UNKNOWN;
		get_c_last(data->c_last, get_nurand(255, 0, 999));
	} else {
		data->c_id = get_nurand(1023, 1, 3000);
	}

	if (mode_altered == 1 || get_random(100) < 85) {
		data->c_w_id = w_id;
		data->c_d_id = data->d_id;
	} else {
		data->c_d_id = get_random(D_ID_MAX) + 1;
		if (table_cardinality.warehouses > 1) {
			/*
			 * Select a random warehouse that is not the same
			 * as this user's home warehouse by shifting the
			 * numbers slightly.
			 */
			data->c_w_id =
				get_random(table_cardinality.warehouses - 1)
					+ 1;
			if (data->c_w_id >= w_id) {
				data->c_w_id = (data->c_w_id + 1) %
						table_cardinality.warehouses;
			}
			if (!data->c_w_id)
			{
			  data->c_w_id = 1;
			}
		} else {
			data->c_w_id = 1;
		}
	}
	data->h_amount = (double) (get_random(500000) + 100) / 100.0;

	return OK;
}
Exemple #3
0
/* 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;
}
Exemple #4
0
/* 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;
}