def reconstruct_table(self, file_name, name): path = self.bufferpool.path with open(os.path.join(path, file_name), 'rb') as ff: f = ff.read() # Read RID counter rid_counter = int.from_bytes(f[0:8], byteorder='big') offset = 1 # Read page directory keys page_directory_keys = [] for i in range(0, rid_counter): start = offset*8 end = (offset+1)*8 page_directory_key = int.from_bytes(f[start:end], byteorder='big') page_directory_keys.append(page_directory_key) offset += 1 # Read page directory values page_directory_values = [] for i in range(0, rid_counter): page_directory_value_list = [] for j in range(0, 3): start = offset * 8 end = (offset + 1) * 8 page_directory_value = int.from_bytes(f[start:end], byteorder='big') page_directory_value_list.append(page_directory_value) offset += 1 page_directory_values.append(page_directory_value_list) page_directory = self.construct_dictionary(page_directory_keys, page_directory_values) # Read length of index directory index_directory_length = int.from_bytes(f[offset*8:(offset+1)*8], byteorder='big') offset += 1 index_directory_keys = [] for i in range(0, index_directory_length): start = offset*8 end = (offset+1)*8 index_directory_key = int.from_bytes(f[start:end], byteorder='big') index_directory_keys.append(index_directory_key) offset += 1 index_directory_values = [] for i in range(0, index_directory_length): start = offset * 8 end = (offset + 1) * 8 index_directory_value = int.from_bytes(f[start:end], byteorder='big') index_directory_values.append(index_directory_value) offset += 1 index_directory = self.construct_dictionary(index_directory_keys, index_directory_values) # Read number of columns num_columns = int.from_bytes(f[offset * 8:(offset + 1) * 8], byteorder='big') offset += 1 # Read key key = int.from_bytes(f[offset * 8:(offset + 1) * 8], byteorder='big') offset += 1 # Read length of base page internal and base page external base_page_length = int.from_bytes(f[offset * 8:(offset + 1) * 8], byteorder='big') offset += 1 # Read base_page_internal base_page_internal = [] for i in range(0, base_page_length): start = offset * 8 end = (offset + 1) * 8 base_page_internal_value = int.from_bytes(f[start:end], byteorder='big') base_page_internal.append(base_page_internal_value) offset += 1 # Read base external base_page_external = [] for i in range(0, base_page_length): start = offset * 8 end = (offset + 1) * 8 base_page_external_value = int.from_bytes(f[start:end], byteorder='big') base_page_external.append(base_page_external_value) offset += 1 # Read length of tail page tail_page_length = int.from_bytes(f[offset * 8:(offset + 1) * 8], byteorder='big') offset += 1 tail_page = [] for i in range(0, tail_page_length): start = offset * 8 end = (offset + 1) * 8 tail_page_value = int.from_bytes(f[start:end], byteorder='big') tail_page.append(tail_page_value) offset += 1 # Read number of pages num_pages = int.from_bytes(f[offset * 8:(offset + 1) * 8], byteorder='big') # Now, manually reconstruct the table object and return it new_table = Table(name, num_columns, key, self.bufferpool) new_table.page_directory = page_directory new_table.index_directory = index_directory new_table.rid_counter = rid_counter new_table.num_page = num_pages new_table.base_pages_internal = base_page_internal new_table.base_pages_external = base_page_external new_table.tail_pages = tail_page return new_table
def create_table(self, name, num_columns, key): table = Table(name, num_columns, key, self.bufferpool) self.tables.append(table) table.create_new_file(1, name, 4) table.create_new_file(2, name, num_columns) return table
def create_table(self, name, num_columns, key): table = Table(name, num_columns, key) return table
def create_table(self, name, num_columns, key): table = Table(name, num_columns, key) self.tables.append(table) return table
def create_table(self, name, num_columns, key): table = Table(name, num_columns, key) self.tables[name] = table return table