Skip to content

Commit 64581f3

Browse files
committed
Add a bool argument value to testgen type expressions
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y6XkyWnx7iJFEb8q3AnYps
1 parent 8720b1a commit 64581f3

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

internal/engine/clickhouse/testgen/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ query is explained and then executed, and the process exits.
4242
The output has the shape of `sqlc analyze`, except that each column's type is
4343
one expression rather than a name and flags. A type is a call: a lowercased
4444
`name` applied to `args`, each of which carries an optional `label` and
45-
exactly one of `type`, `int` or `string`. `Nullable`, `Array` and
45+
exactly one of `type`, `int`, `bool` or `string`. `Nullable`, `Array` and
4646
`LowCardinality` are ordinary names in that grammar, so nothing about nesting
4747
is lost, and there is no separate nullability flag: a nullable column is one
4848
whose type is `nullable(...)`.

internal/engine/clickhouse/testgen/types.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77

88
// A type is a call expression, the way ClickHouse itself models one: a
99
// lowercased name applied to an ordered argument list. Each argument is
10-
// another type, an integer or a quoted string, optionally labelled, so
10+
// another type, an integer, a boolean or a quoted string, optionally
11+
// labelled, so
1112
// Nullable, Array and LowCardinality are ordinary names and nothing about a
1213
// nested type is lost. The shape maps one to one onto a protobuf message
1314
// with a oneof for the argument value:
@@ -41,6 +42,7 @@ type typeArg struct {
4142
Label string `json:"label,omitempty"`
4243
Type *typeExpr `json:"type,omitempty"`
4344
Int *int64 `json:"int,omitempty"`
45+
Bool *bool `json:"bool,omitempty"`
4446
String *string `json:"string,omitempty"`
4547
}
4648

@@ -58,8 +60,9 @@ func parseType(t string) *typeExpr {
5860
return expr
5961
}
6062

61-
// parseArg parses one argument: a quoted string, an integer, a labelled
62-
// argument (`lat Float64` in a Tuple, `'a' = 1` in an Enum), or a type.
63+
// parseArg parses one argument: a quoted string, an integer, a boolean, a
64+
// labelled argument (`lat Float64` in a Tuple, `'a' = 1` in an Enum), or a
65+
// type.
6366
func parseArg(a string) typeArg {
6467
a = strings.TrimSpace(a)
6568
if strings.HasPrefix(a, "'") {
@@ -75,6 +78,11 @@ func parseArg(a string) typeArg {
7578
if n, err := strconv.ParseInt(a, 10, 64); err == nil {
7679
return typeArg{Int: &n}
7780
}
81+
switch strings.ToLower(a) {
82+
case "true", "false":
83+
b := strings.EqualFold(a, "true")
84+
return typeArg{Bool: &b}
85+
}
7886
if i := labelEnd(a); i > 0 {
7987
arg := parseArg(a[i+1:])
8088
arg.Label = a[:i]

0 commit comments

Comments
 (0)