Skip to content

Commit 1fc256e

Browse files
committed
Update CLAUDE.md with generator authoring rules and session learnings
1 parent c6a7945 commit 1fc256e

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

CLAUDE.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ The dialect is registered as a plugin in `pyproject.toml` under `[project.entry-
4242

4343
## Implementation Status
4444

45-
The dialect is partially implemented. Current state:
46-
- **Parser**: ~50 functions mapped across date/time, string, aggregate, array, and map categories.
47-
- **Generator**: Partially implemented — `TRANSFORMS`, `PROPERTIES_LOCATION`, and `property_sql` override for LIFECYCLE; inherits Hive's generator for everything else.
48-
- **Tests**: `tests/test_maxcompute.py` covers all Parser mappings (parse assertions + cross-dialect transpilation).
45+
The dialect is largely complete. Current state:
46+
- **Parser**: ~65 functions mapped across date/time, string, aggregate, array, and map categories.
47+
- **Generator**: `TRANSFORMS` entries + named `_sql` methods for all major expression types; inherits Hive for the rest.
48+
- **Tests**: `tests/test_maxcompute.py` covers Parser (parse + cross-dialect) and Generator (round-trip + cross-dialect).
4949
- **Reference**: Full implementation checklist is in `docs/superpowers/specs/2026-03-13-maxcompute-dialect-design.md`.
5050

5151
## Key sqlglot patterns
@@ -67,7 +67,9 @@ uv run python -c "from sqlglot import parse_one; e = parse_one('FUNC(...)', read
6767

6868
## Debugging with probe scripts
6969

70-
For multi-step debugging (AST inspection, tracing transforms, etc.), write a temporary script to `local/probe.py` and run it with `uv run python local/probe.py`. The `local/` directory is gitignored, so probe scripts won't pollute the repo. Delete when done.
70+
For multi-step debugging (AST inspection, tracing transforms, etc.), write a temporary script to `local/probe.py` and run it with `uv run python local/probe.py`. The `local/` directory is gitignored, so probe scripts won't pollute the repo. **Always delete when done** — subagents consistently forget to clean up.
71+
72+
When instructing subagents to debug, explicitly include: "write probe scripts to `local/probe.py`, run with `uv run python local/probe.py`, delete when done."
7173

7274
## Plugin contract — do not break sqlglot internals
7375

@@ -88,3 +90,11 @@ Note: snapshots exceed token limits; grep the saved file for the button ref inst
8890
- **Never use `exp.Anonymous`** — check `expressions.py` for a proper class first; use formula-based expressions as fallback.
8991
- **Inherit, don't re-implement** — omit functions from `Parser.FUNCTIONS` if MaxCompute and Hive have identical semantics.
9092
- **Type-dispatch builders**`_build_dateadd` / `_build_datetrunc` dispatch to typed nodes via `is_type()`, with an untyped fallback.
93+
94+
## Generator authoring rules
95+
96+
- **`self.func` drops `None` args silently** — guard optional args before passing to avoid emitting invalid SQL (e.g. `groupconcat_sql` defaults `separator` to `','`).
97+
- **`unit_to_str` on `WeekStart` returns the raw name, not a string literal** — reconstruct as `exp.Literal.string(f"week({day})")` manually.
98+
- **Named `_sql` methods vs TRANSFORMS** — use a named method when the base class already defines one (e.g. `extract_sql`, `groupconcat_sql`); both work but the method is cleaner and avoids surprise overrides.
99+
- **Don't add empty `PROPERTIES_LOCATION = {**Hive.Generator.PROPERTIES_LOCATION}`** — pure boilerplate; only add the dict when you have new entries to include.
100+
- **DateSub string-literal delta (BigQuery quirk)** — BigQuery's `DATE_SUB` stores the magnitude as a string literal; normalize before negating: `exp.Literal.number(delta.this)` so you emit `-3` not `-'3'`.

0 commit comments

Comments
 (0)