def load_orders(self): print(f'Loading orders ({self.warehouse_id})') self.order_lines = [] self.c_ids = list(range(1, NUM_ORDERS + 1)) self.random.shuffle(self.c_ids) with DBConn(self.dsn) as conn: it = StringIteratorIO(( self.generate_order(d_id, o_id) # generate in the order that a higher order number means a later transaction for o_id in range(1, NUM_ORDERS + 1) for d_id in range(1, DIST_PER_WARE + 1))) conn.cursor.copy_from(it, 'orders', null='None', size=COPY_SIZE) with DBConn(self.dsn) as conn: conn.cursor.execute(f''' INSERT INTO new_orders(no_o_id, no_d_id, no_w_id) SELECT o_id, o_d_id, o_w_id FROM orders WHERE o_id >= {FIRST_UNPROCESSED_O_ID} AND o_w_id = { self.warehouse_id }''' ) print(f'Loading order_line ({self.warehouse_id})') with DBConn(self.dsn) as conn: it = StringIteratorIO((self.generate_order_lines(order_line) for order_line in self.order_lines)) conn.cursor.copy_from(it, 'order_line', null='None', size=COPY_SIZE)
def load_supplier(self): print(f'Loading suppliers') assert self.warehouse_id == 0 with DBConn(self.dsn) as conn: it = StringIteratorIO((self.generate_supplier(su_id) for su_id in range(NUM_SUPPLIERS))) conn.cursor.copy_from(it, 'supplier', null='None', size=COPY_SIZE)
def load_item(self): print(f'Loading items') assert self.warehouse_id == 0 with DBConn(self.dsn) as conn: it = StringIteratorIO( (self.generate_item(i_id) for i_id in range(1, MAX_ITEMS + 1))) conn.cursor.copy_from(it, 'item', null='None', size=COPY_SIZE)
def load_customer(self): print(f'Loading customer ({self.warehouse_id})') with DBConn(self.dsn) as conn: it = StringIteratorIO((self.generate_customer(d_id, c_id) for d_id in range(1, DIST_PER_WARE + 1) for c_id in range(1, CUST_PER_DIST + 1))) conn.cursor.copy_from(it, 'customer', null='None', size=COPY_SIZE)
def load_history(self): print(f'Loading history ({self.warehouse_id})') copy_columns = ('h_c_id', 'h_c_d_id', 'h_c_w_id', 'h_d_id', 'h_w_id', 'h_date', 'h_amount', 'h_data') with DBConn(self.dsn) as conn: it = StringIteratorIO((self.generate_history(d_id, c_id) for d_id in range(1, DIST_PER_WARE + 1) for c_id in range(1, CUST_PER_DIST + 1))) conn.cursor.copy_from(it, 'history', null='None', columns=copy_columns, size=COPY_SIZE)
def load_district(self): print(f'Loading district ({self.warehouse_id})') with DBConn(self.dsn) as conn: it = StringIteratorIO((self.generate_district(d_id) for d_id in range(1, DIST_PER_WARE + 1))) conn.cursor.copy_from(it, 'district', null='None', size=COPY_SIZE)
def load_stock(self): print(f'Loading stock ({self.warehouse_id})') with DBConn(self.dsn) as conn: it = StringIteratorIO( (self.generate_stock(s_id) for s_id in range(1, STOCKS + 1))) conn.cursor.copy_from(it, 'stock', null='None', size=COPY_SIZE)