Returns 'num_cols' column declarations, cycling through every column type, as a a list of strings.
(num_cols)
| 33 | parser.add_option("--num_rows", dest="num_rows", default=10) |
| 34 | |
| 35 | def get_columns(num_cols): |
| 36 | """Returns 'num_cols' column declarations, cycling through every column type, as a |
| 37 | a list of strings.""" |
| 38 | templates = [ |
| 39 | 'bool_col%i BOOLEAN', |
| 40 | 'tinyint_col%i TINYINT', |
| 41 | 'smallint_col%i SMALLINT', |
| 42 | 'int_col%i INT', |
| 43 | 'bigint_col%i BIGINT', |
| 44 | 'float_col%i FLOAT', |
| 45 | 'double_col%i DOUBLE', |
| 46 | 'string_col%i STRING', |
| 47 | ] |
| 48 | |
| 49 | iter = itertools.cycle(templates) |
| 50 | # Produces [bool_col1, tinyint_col1, ..., bool_col2, tinyint_col2, ...] |
| 51 | # The final list has 'num_cols' elements. |
| 52 | return [next(iter) % (i // len(templates) + 1) for i in range(num_cols)] |
| 53 | |
| 54 | # Data generators for different types. Each generator yields an infinite number of |
| 55 | # value strings suitable for writing to a CSV file. |
no test coverage detected