|
1 | 1 | # ClickHouse testgen |
2 | 2 |
|
3 | 3 | `testgen` records what ClickHouse itself reports about a set of sqlc queries, |
4 | | -so the answer can be committed as a golden file and compared with what sqlc's |
| 4 | +so the answer can be committed as a golden file and held against what sqlc's |
5 | 5 | own analysis produces for the same schema and queries. |
6 | 6 |
|
7 | 7 | It is a nested Go module with no dependencies beyond the standard library. |
@@ -39,10 +39,25 @@ query is explained and then executed, and the process exits. |
39 | 39 | operand it is compared with. Parameters of `INSERT ... VALUES` map onto the |
40 | 40 | target columns reported by `DESCRIBE TABLE`. |
41 | 41 |
|
42 | | -The output has the same shape as `sqlc analyze`, with ClickHouse types lowered |
43 | | -the way sqlc's ClickHouse engine lowers them: the lowercased base name with |
44 | | -parameters dropped, `Nullable` and `Array` folded into `not_null` and |
45 | | -`is_array`, and `LowCardinality` discarded. |
| 42 | +The output has the shape of `sqlc analyze`, except that each column's type is |
| 43 | +one expression rather than a name and flags. A type is written as a call: a |
| 44 | +lowercased name applied to arguments that are numbers, quoted strings, |
| 45 | +identifiers, other calls, or any of those with a label. `Nullable`, `Array` |
| 46 | +and `LowCardinality` are ordinary names in that grammar, so nothing about |
| 47 | +nesting is lost: |
| 48 | + |
| 49 | +| ClickHouse | testgen | |
| 50 | +|-----------------------------------|------------------------------------| |
| 51 | +| `Array(Nullable(String))` | `array(nullable(string))` | |
| 52 | +| `Map(String, UInt32)` | `map(string, uint32)` | |
| 53 | +| `Tuple(lat Float64, lon Float64)` | `tuple(lat: float64, lon: float64)`| |
| 54 | +| `Enum8('a' = 1, 'b' = 2)` | `enum8('a': 1, 'b': 2)` | |
| 55 | +| `DateTime64(3, 'UTC')` | `datetime64(3, 'UTC')` | |
| 56 | +| `LowCardinality(Nullable(String))`| `lowcardinality(string)`, `not_null: false` | |
| 57 | + |
| 58 | +An outer `Nullable` is the column's nullability rather than part of its type, |
| 59 | +so it is lifted into `not_null`; a `Nullable` at any greater depth stays in |
| 60 | +the expression. Resolving the names is left to whoever reads the output. |
46 | 61 |
|
47 | 62 | ## Tests |
48 | 63 |
|
|
0 commit comments