def create_random_table(self, table_name, min_number_of_cols, max_number_of_cols, allowed_storage_formats): '''Create and return a Table with a random number of cols.''' col_count = randint(min_number_of_cols, max_number_of_cols) storage_format = choice(allowed_storage_formats) table = Table(table_name) table.storage_format = storage_format for col_idx in xrange(col_count): col_type = choice(TYPES) col_type = choice( filter(lambda type_: issubclass(type_, col_type), EXACT_TYPES)) if issubclass(col_type, VarChar) and not issubclass(col_type, String): col_type = get_varchar_class(randint(1, VarChar.MAX)) elif issubclass(col_type, Char) and not issubclass(col_type, String): col_type = get_char_class(randint(1, Char.MAX)) elif issubclass(col_type, Decimal): max_digits = randint(1, Decimal.MAX_DIGITS) col_type = get_decimal_class(max_digits, randint(1, max_digits)) col = Column( table, '%s_col_%s' % (col_type.__name__.lower(), col_idx + 1), col_type) table.cols.append(col) return table
def create_random_table(self, table_name, min_number_of_cols, max_number_of_cols, allowed_storage_formats): '''Create and return a Table with a random number of cols.''' col_count = randint(min_number_of_cols, max_number_of_cols) storage_format = choice(allowed_storage_formats) table = Table(table_name) table.storage_format = storage_format for col_idx in xrange(col_count): col_type = choice(TYPES) col_type = choice(filter(lambda type_: issubclass(type_, col_type), EXACT_TYPES)) if issubclass(col_type, VarChar) and not issubclass(col_type, String): col_type = get_varchar_class(randint(1, VarChar.MAX)) elif issubclass(col_type, Char) and not issubclass(col_type, String): col_type = get_char_class(randint(1, Char.MAX)) elif issubclass(col_type, Decimal): max_digits = randint(1, Decimal.MAX_DIGITS) col_type = get_decimal_class(max_digits, randint(1, max_digits)) col = Column( table, '%s_col_%s' % (col_type.__name__.lower(), col_idx + 1), col_type) table.cols.append(col) return table
def parse_data_type(self, type_name, type_size): if type_name in ('DECIMAL', 'NUMERIC'): return get_decimal_class(*type_size) if type_name == 'CHAR': return get_char_class(*type_size) if type_name == 'VARCHAR': if type_size and type_size[0] <= VarChar.MAX: return get_varchar_class(*type_size) type_name = 'STRING' return self.TYPES_BY_NAME[type_name]