Skip to content

Commit 0b3636c

Browse files
committed
core/seed: make dialect.json a plain JSON object
The file holds one record, so a line-oriented format bought nothing and read oddly next to the lists it sits with. It is now an ordinary JSON document, indented and diffable. The lists stay JSONL, which is where streaming a record at a time pays. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011MnoUabwBWW9gaEn2Nj7eG
1 parent 1036996 commit 0b3636c

11 files changed

Lines changed: 91 additions & 26 deletions

File tree

‎internal/core/seed/seed.go‎

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
// description of its type system: the types it defines, the operators and
33
// casts between them, and the functions it ships with.
44
//
5-
// A dialect is a directory of JSONL files — one record per line — which each
6-
// engine package embeds and hands to Dialect:
5+
// A dialect is a directory which each engine package embeds and hands to
6+
// Dialect:
77
//
8-
// dialect.jsonl a single record naming the dialect and its rules
8+
// dialect.json what the dialect is called and the rules it is built by
99
// types.jsonl the types it defines
1010
// operators.jsonl operator overloads beyond the ones the rules generate
1111
// casts.jsonl casts beyond the ones the rules generate
1212
// functions.jsonl the functions it ships with
1313
//
14-
// Records are applied as they are read, so a dialect whose function list runs
15-
// to thousands of entries is never held in memory as a whole. Any file may be
16-
// left out.
14+
// The lists are JSONL — one record per line — and are applied as they are
15+
// read, so a dialect whose function list runs to thousands of entries is never
16+
// held in memory as a whole. Any of the lists may be left out.
1717
package seed
1818

1919
import (
@@ -33,15 +33,15 @@ import (
3333

3434
// The files a dialect directory is made of.
3535
const (
36-
SettingsFile = "dialect.jsonl"
36+
SettingsFile = "dialect.json"
3737
TypesFile = "types.jsonl"
3838
OperatorsFile = "operators.jsonl"
3939
CastsFile = "casts.jsonl"
4040
FunctionsFile = "functions.jsonl"
4141
)
4242

43-
// Settings is the single record in dialect.jsonl: what the dialect is called
44-
// and the rules that generate its operators and casts.
43+
// Settings is dialect.json: what the dialect is called and the rules that
44+
// generate its operators and casts.
4545
type Settings struct {
4646
// Dialect is the name recorded in the catalog, e.g. "postgresql".
4747
Dialect string `json:"dialect"`
@@ -164,20 +164,17 @@ func apply(cat *core.Catalog, fsys fs.FS) error {
164164
}
165165

166166
func loadSettings(fsys fs.FS) (Settings, error) {
167-
var settings Settings
168-
found := false
169-
err := stream(fsys, SettingsFile, func(s Settings) error {
170-
if found {
171-
return errors.New("more than one record")
172-
}
173-
settings, found = s, true
174-
return nil
175-
})
167+
f, err := fsys.Open(SettingsFile)
176168
if err != nil {
177-
return Settings{}, err
169+
return Settings{}, fmt.Errorf("seed: %w", err)
178170
}
179-
if !found {
180-
return Settings{}, fmt.Errorf("seed: %s is missing or empty", SettingsFile)
171+
defer f.Close()
172+
173+
dec := json.NewDecoder(bufio.NewReader(f))
174+
dec.DisallowUnknownFields()
175+
var settings Settings
176+
if err := dec.Decode(&settings); err != nil {
177+
return Settings{}, fmt.Errorf("seed: %s: %w", SettingsFile, err)
181178
}
182179
if settings.Dialect == "" {
183180
return Settings{}, fmt.Errorf("seed: %s: dialect has no name", SettingsFile)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"dialect": "clickhouse",
3+
"const": {
4+
"integer": "Int64",
5+
"float": "Float64",
6+
"string": "String",
7+
"bool": "Bool"
8+
},
9+
"bool": "Bool",
10+
"comparison": ["=", "<>", "!=", "<", "<=", ">", ">="],
11+
"comparison_categories": "NBSD",
12+
"arithmetic": ["+", "-", "*", "/"],
13+
"arithmetic_categories": "N"
14+
}

‎internal/engine/clickhouse/dialect/dialect.jsonl‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"dialect": "mysql",
3+
"const": {
4+
"integer": "int",
5+
"float": "decimal",
6+
"string": "text",
7+
"bool": "bool"
8+
},
9+
"bool": "bool",
10+
"comparison": ["=", "<>", "!=", "<", "<=", ">", ">=", "<=>"],
11+
"comparison_categories": "BNSDU",
12+
"arithmetic": ["+", "-", "*", "/", "%", "DIV"],
13+
"arithmetic_categories": "N",
14+
"cast_categories": "NSD"
15+
}

‎internal/engine/dolphin/dialect/dialect.jsonl‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"dialect": "googlesql",
3+
"const": {
4+
"integer": "int64",
5+
"float": "float64",
6+
"string": "string",
7+
"bool": "bool"
8+
},
9+
"bool": "bool",
10+
"comparison": ["=", "<>", "!=", "<", "<=", ">", ">="],
11+
"comparison_categories": "BNSDTU",
12+
"arithmetic": ["+", "-", "*", "/"],
13+
"arithmetic_categories": "N"
14+
}

‎internal/engine/googlesql/dialect/dialect.jsonl‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"dialect": "postgresql",
3+
"const": {
4+
"integer": "int4",
5+
"float": "numeric",
6+
"string": "text",
7+
"bool": "bool"
8+
},
9+
"bool": "bool",
10+
"comparison": ["=", "<>", "!=", "<", "<=", ">", ">=", "IS DISTINCT FROM", "IS NOT DISTINCT FROM"],
11+
"comparison_categories": "BNSDTU",
12+
"arithmetic": ["+", "-", "*", "/", "%"],
13+
"arithmetic_categories": "N",
14+
"cast_categories": "NSD"
15+
}

‎internal/engine/postgresql/dialect/dialect.jsonl‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"dialect": "sqlite",
3+
"const": {
4+
"integer": "integer",
5+
"float": "real",
6+
"string": "text",
7+
"bool": "boolean"
8+
},
9+
"bool": "boolean",
10+
"comparison": ["=", "==", "<>", "!=", "<", "<=", ">", ">=", "IS", "IS NOT"],
11+
"comparison_categories": "BNSDU",
12+
"arithmetic": ["+", "-", "*", "/", "%"],
13+
"arithmetic_categories": "N",
14+
"cast_categories": "*"
15+
}

0 commit comments

Comments
 (0)