Skip to content

docs: Add docstring examples to the unparser module - #1692

Draft
ting-hong-shieh wants to merge 1 commit into
apache:mainfrom
ting-hong-shieh:unparser-docstring-examples
Draft

docs: Add docstring examples to the unparser module#1692
ting-hong-shieh wants to merge 1 commit into
apache:mainfrom
ting-hong-shieh:unparser-docstring-examples

Conversation

@ting-hong-shieh

Copy link
Copy Markdown

Which issue does this PR close?

Closes #1691.

Rationale for this change

AGENTS.md requires every public Python function to carry a usage example, and
no public function in python/datafusion/unparser.py had one. The omission is
most costly in this module: the reason Dialect exists is that dialects render
the same plan differently, and nothing in the documentation showed that.

What changes are included in this PR?

  • Docstring examples for Dialect.default, Dialect.mysql, Dialect.postgres,
    Dialect.sqlite, Dialect.duckdb, Unparser.plan_to_sql and
    Unparser.with_pretty. All build the same input table so the examples differ
    only in the behaviour being demonstrated, and each shows the actual quoting a
    dialect produces:

    >>> Unparser(Dialect.default()).plan_to_sql(plan)
    'SELECT t.a FROM t'
    >>> Unparser(Dialect.mysql()).plan_to_sql(plan)
    'SELECT `t`.`a` FROM `t`'
    >>> Unparser(Dialect.postgres()).plan_to_sql(plan)
    'SELECT "t"."a" FROM "t"'
    
  • Corrected the Dialect class summary, which read "DataFusion data catalog."

  • Described what with_pretty does — it drops redundant parentheses and returns
    the same unparser so the call can be chained — instead of restating its name.

No behaviour is changed; the diff is docstrings only.

Are there any user-facing changes?

Documentation only. The new examples run as doctests under the existing
--doctest-modules setting, so they are checked in CI.

Every public function in `Dialect` and `Unparser` lacked the usage example
required by AGENTS.md. Each now carries a doctest built on the same input
table, so the examples run under pytest's --doctest-modules.

The examples show what actually differs between dialects: the default dialect
leaves identifiers unquoted, MySQL and SQLite quote with backticks, PostgreSQL
and DuckDB quote with double quotes.

Also correct the `Dialect` class summary, which described it as "DataFusion
data catalog", and describe what `with_pretty` does rather than restating its
name.
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.

Missing docstring examples in the unparser module

1 participant