Skip to content

refactor: share the internal name and split the long functions - #6

Merged
eddietejeda merged 2 commits into
mainfrom
refactor/tidy
Sep 24, 2026
Merged

eddietejeda merged 2 commits into
mainfrom
refactor/tidy

Conversation

@eddietejeda

Copy link
Copy Markdown
Contributor

Summary

Behaviour-preserving tidy-up. No public API, error message, or Cargo.lock change; the same 36 tests pass.

  • names.rs (new): one constant for the internal function name, the logical and physical "is this the call" predicates, and the single #[allow(deprecated)] accessor for AsyncFuncExec::async_exprs. Previously the name was a literal in four files and the predicate was written twice.
  • sql.rs: rewrite_statement split into parse_call and parse_batch_size; the entry point now reads find → parse → validate → replace, and builds the new argument list directly. criteria() reformatted to one statement per line.
  • udf.rs: plan_batches and a small Batches struct extracted from invoke_async_with_args; probabilities extracted from answer.
  • optimizer.rs / planner.rs: shared prologue for the two physical rules, the hoist_calls wrapper folded into one function, module docs rewritten to describe the current rules rather than their history.
  • Tests: tests/sql.rs (893 lines) split into tests/sql/{common,syntax,execution,planning}.rs with the mock and helpers shared from common. Test bodies are unchanged.

Verification

cargo fmt --check, cargo clippy --locked --all-targets -- -D warnings, cargo test --locked (36 pass), cargo doc --no-deps (0 warnings). git diff main -- Cargo.lock is empty.

No behaviour, error-message, or public API change.

- new src/names.rs: INTERNAL_FUNCTION plus the is_jev / is_jev_expr
  predicates and an async_exprs wrapper that carries the single
  #[allow(deprecated)]; sql.rs, udf.rs, planner.rs and optimizer.rs now
  use them instead of repeating the literal.
- optimizer.rs: both rules start from one async_node helper; module doc
  now describes both rules in code order.
- planner.rs: hoist_calls_named folded into hoist_calls with a prefix
  parameter; module doc rewritten as a description of the two rules.
- sql.rs: rewrite_statement split into parse_call and parse_batch_size;
  criteria() match arms reformatted.
- udf.rs: plan_batches (with a Batches struct) and probabilities()
  extracted from invoke_async_with_args and answer().
- tests/sql.rs split into tests/sql/{main,common,syntax,execution,
  planning}.rs; the same 36 tests, unchanged.
@eddietejeda
eddietejeda requested a review from a team as a code owner September 24, 2026 16:05
@eddietejeda
eddietejeda requested review from rohan-hotdata and removed request for a team September 24, 2026 16:05
Comment thread src/sql.rs
}
/// Read one `prompt_jev` call: the input expression and the question it asks.
/// The question is not validated here; the caller does that before rewriting.
fn parse_call(f: &mut ast::Function) -> Result<(Expr, Question)> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Take &ast::Function and match on &f.args at line 172 (not blocking).

parse_call only reads f. The caller now replaces f.args itself after the call returns. The &mut signature suggests that parse_call mutates the call, but it does not.

@eddietejeda
eddietejeda merged commit 93bf55b into main Sep 24, 2026
3 checks passed
@eddietejeda
eddietejeda deleted the refactor/tidy branch September 24, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant