Esempio n. 1
0
 def _create_random_table(self, table_name, min_col_count, max_col_count,
                          allowed_storage_formats):
     '''Create and return a Table with a random number of cols.'''
     col_count = randint(min_col_count, max_col_count)
     storage_format = choice(allowed_storage_formats)
     table = Table(table_name)
     table.storage_format = storage_format
     allowed_types = list(TYPES)
     # Avro doesn't support timestamps yet.
     if table.storage_format == 'AVRO':
         allowed_types.remove(Timestamp)
     # TODO: 'table.cols' returns a copy of all scalar cols, so 'table.cols.append()'
     #       doesn't actually modify the table's columns. 'table.cols' should be changed
     #       to allow access to the real columns.
     cols = table.cols
     for col_idx in xrange(col_count):
         col_type = choice(allowed_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)
         cols.append(col)
     table.cols = cols
     return table
Esempio n. 2
0
 def _create_random_table(self,
     table_name,
     min_col_count,
     max_col_count,
     allowed_storage_formats):
   '''Create and return a Table with a random number of cols.'''
   col_count = randint(min_col_count, max_col_count)
   storage_format = choice(allowed_storage_formats)
   table = Table(table_name)
   table.storage_format = storage_format
   allowed_types = list(TYPES)
   # Avro doesn't support timestamps yet.
   if table.storage_format == 'AVRO':
     allowed_types.remove(Timestamp)
   # TODO: 'table.cols' returns a copy of all scalar cols, so 'table.cols.append()'
   #       doesn't actually modify the table's columns. 'table.cols' should be changed
   #       to allow access to the real columns.
   cols = table.cols
   for col_idx in xrange(col_count):
     col_type = choice(allowed_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)
     cols.append(col)
   table.cols = cols
   return table
Esempio n. 3
0
 def describe_table(self, table_name):
   '''Return a Table with table and col names always in lowercase.'''
   rows = self.conn.execute_and_fetchall(
       self.make_describe_table_sql(table_name))
   table = Table(table_name.lower())
   cols = table.cols   # This is a copy
   for row in rows:
     col_name, data_type = row[:2]
     if data_type == 'tinyint(1)':
       # Just assume this is a boolean...
       data_type = 'boolean'
     if 'decimal' not in data_type and '(' in data_type:
       # Strip the size of the data type
       data_type = data_type[:data_type.index('(')]
     cols.append(Column(table, col_name.lower(), self.parse_data_type(data_type)))
   table.cols = cols
   return table
Esempio n. 4
0
 def describe_table(self, table_name):
   '''Return a Table with table and col names always in lowercase.'''
   rows = self.conn.execute_and_fetchall(
       self.make_describe_table_sql(table_name))
   table = Table(table_name.lower())
   cols = table.cols   # This is a copy
   for row in rows:
     col_name, data_type = row[:2]
     if data_type == 'tinyint(1)':
       # Just assume this is a boolean...
       data_type = 'boolean'
     if 'decimal' not in data_type and '(' in data_type:
       # Strip the size of the data type
       data_type = data_type[:data_type.index('(')]
     cols.append(Column(table, col_name.lower(), self.parse_data_type(data_type)))
   table.cols = cols
   return table