datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Doc attribution: make `user_doc` to work with predefined consts.

Open comphead opened this issue 1 year ago • 7 comments

          I'll file a ticket to make `user_doc` to work with predefined consts.

Currently the doc_section attribute must match fully the predefined DocSection consts, for example

    pub const DOC_SECTION_REGEX: DocSection = DocSection {
        include: true,
        label: "Regular Expression Functions",
        description: Some(
            r#"Apache DataFusion uses a [PCRE-like](https://en.wikibooks.org/wiki/Regular_Expressions/Perl-Compatible_Regular_Expressions)
regular expression [syntax](https://docs.rs/regex/latest/regex/#syntax)
(minus support for several features including look-around and backreferences).
The following regular expression functions are supported:"#,
        ),
    };

In case of doc_section attribute contains any mismatches such function will be silently ignored. Example

    doc_section(
        label = "Regular Expression Functions"

In the example the description doesn't match causing the function documentation to be ignored

I believe we can make doc macros more smart like:

  • the doc_section can be just a string
  • using the string find correspondent const from scalar_doc_sections.doc_sections()
  • in datafusion/macros/src/user_doc.rs when constructing the builder use the const instead of building DocSection manually

Originally posted by @comphead in https://github.com/apache/datafusion/pull/13919#discussion_r1902030922

comphead avatar Jan 03 '25 17:01 comphead

take

ding-young avatar Jan 04 '25 11:01 ding-young

Hi @ding-young are you still planning to work on this issue?

comphead avatar Jan 08 '25 22:01 comphead

@comphead Yes, I've taken a brief look at scalar_doc_sections and the user_doc macro, and I plan to make the necessary code changes this weekend. If you need this change earlier, please tell me.

ding-young avatar Jan 09 '25 01:01 ding-young

@comphead if the doc_section is a string, user_doc macro syntax will change for all functions?

Before

#[user_doc(
    doc_section(label = "String Functions"),
    description = "...",
    syntax_example = "...",
    ...
)]

After

#[user_doc(
    doc_section = "String Functions",
    description = "...",
    syntax_example = "...",
    ...
)]

Chen-Yuan-Lai avatar Jan 09 '25 03:01 Chen-Yuan-Lai

I think we can make the parser to try both, (1) try to find all these attributes

#[user_doc(
    doc_section(include=true, label = "String Functions", description: None),
    description = "...",
    syntax_example = "...",
    ...
)]

(2) if it fails look for single string like doc_section = "String Functions"

#[user_doc(
    doc_section = "String Functions",
    description = "...",
    syntax_example = "...",
    ...
)]

Thereby we can keep original syntax. However, I'm curious whether we should replace (1) with (2), or make parser try both.

ding-young avatar Jan 09 '25 08:01 ding-young

I think folks lets keep it just

doc_section(label = "String Functions"),

where label corresponds to label in predefined doc sections in this case we avoid massive changes for all builtin functions again.

I understand that we slightly overcomplicate the doc section so it looks like a complex object but in fact it is just a string but if we want to improve it we can do it later

comphead avatar Jan 09 '25 16:01 comphead

Agree, thanks @comphead @ding-young

Chen-Yuan-Lai avatar Jan 10 '25 01:01 Chen-Yuan-Lai