Skip to content

Templates support - #551

Open
john-sanchez31 wants to merge 11 commits into
mainfrom
John/templates
Open

Templates support#551
john-sanchez31 wants to merge 11 commits into
mainfrom
John/templates

Conversation

@john-sanchez31

@john-sanchez31 john-sanchez31 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Linked ticket

Closes #173

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Docs / config

What changed and why?

Adds support for PyDough templates — reusable, parametrized PyDough/Python snippets registered in metadata, so common query patterns can be defined once and reused. This PR adds:

  • A new templates metadata object, with attributes (labeled values usable as template arguments) and definitions (the templates themselves).
  • Support for calling a loaded template directly, as an ordinary PyDough function, or via the new pydough.call_template(name, labels=...) API using human-facing labels.
  • Support for recursive templates, templates returning plain literals, and templates that build a user-generated collection from an input pd.DataFrame.

How I tested this?

  • New test file test_templates.py, covering end-to-end template calls (direct and via call_template), metadata parsing/validation error cases, and call_template runtime error cases (unknown template, unknown/missing labels, type mismatches, disallowed usage).

Notes for reviewers

Minor from_string refactor as part of this: from_string and call_template now share a common _execute_source helper, with a return_unqualified flag (True requires the source to produce an UnqualifiedNode; False allows any return type, needed for literal-returning templates).

@john-sanchez31
john-sanchez31 marked this pull request as ready for review September 8, 2026 19:13
@john-sanchez31
john-sanchez31 requested review from a team, hadia206, juankx-bodo and knassre-bodo and removed request for a team September 8, 2026 19:13
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.

Support parameters in executed SQL queries

1 participant