Esempio n. 1
0
    def create_table(self, name, key, num_columns):
        table = Table(name, key, num_columns)
        """
        update the base_pages field that was added in the table.py file
        """

        # Four extra columns for indirection, rid, schema encoding, and the timestamp
        for col in range(0, num_columns + 4):
            table.base_pages.append(table.create_page())

        self.tables.append(table)
        return table
Esempio n. 2
0
 def create_table(self, name, num_columns, key):
     
     for table in self.tables_directory:
         if name in table.name:
             print("Already exists such a table")
             print("Returning this table")
             return table
     os.mkdir(self.path + '/' + name)
     new_table = Table(name, num_columns, key, self.path)
     new_table.create()
     self.append_table(new_table)
     self.num_table += 1
     return new_table
Esempio n. 3
0
 def create_table(self, name, num_columns, key):
     if name in self.tables:
         return self.get_table(name)
     else:
         table = Table(name, num_columns, key)
         self.tables[name] = table
         return table
Esempio n. 4
0
    def create_table(self, name, num_columns, key):
        for table in self.tables:
            if table.name == name:
                return table

        self.num_tables += 1

        table = Table(name, num_columns, key)

        self.tables.append(table)

        return table
Esempio n. 5
0
 def create_table(self, name, num_columns, key):
     for x in range(0, len(self.tables)):
         if self.tables[x].getName() == name:
             print(
                 "Table with that name already exists! Choose another name or drop table: ",
                 name)
             exit()
             return None
         else:
             pass
     table = Table(name, num_columns, key)
     self.tables.append(table)
     return table
Esempio n. 6
0
 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
Esempio n. 7
0
 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
Esempio n. 8
0
 def create_table(self, name, num_columns, key):
     table = Table(name, num_columns, key)
     self.tables.append(table)
     return table
Esempio n. 9
0
 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[name] = table
     return table