From cdc89283237aa9cc4aa9bcc4ebbc9b549522df77 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Mon, 24 Aug 2026 10:44:03 -0400 Subject: [PATCH] docs: add runnable examples for input_file_name and file_row_index Both functions previously documented a placeholder example (`SELECT input_file_name() FROM t;`) that showed no output and did not illustrate that these functions are per-file metadata resolved during a file scan. Replace them with a complete, verified example that writes a small Parquet file and selects both functions alongside the data columns. --- .../functions/src/core/file_row_index.rs | 11 +++++++++- .../functions/src/core/input_file_name.rs | 11 +++++++++- .../source/user-guide/sql/scalar_functions.md | 22 +++++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/datafusion/functions/src/core/file_row_index.rs b/datafusion/functions/src/core/file_row_index.rs index 7b2667a8b8768..e76b57e147e33 100644 --- a/datafusion/functions/src/core/file_row_index.rs +++ b/datafusion/functions/src/core/file_row_index.rs @@ -45,7 +45,16 @@ evaluation returns an error. "#, syntax_example = "file_row_index()", sql_example = r#"```sql -SELECT file_row_index() FROM t; +> COPY (SELECT * from values (100), (200), (300)) to '/tmp/foo.parquet'; + +> select *, input_file_name(), file_row_index() from '/tmp/foo.parquet'; ++---------+-------------------+------------------+ +| column1 | input_file_name() | file_row_index() | ++---------+-------------------+------------------+ +| 100 | tmp/foo.parquet | 0 | +| 200 | tmp/foo.parquet | 1 | +| 300 | tmp/foo.parquet | 2 | ++---------+-------------------+------------------+ ```"# )] #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/datafusion/functions/src/core/input_file_name.rs b/datafusion/functions/src/core/input_file_name.rs index a47e9daaf8d3c..555c498e57c4c 100644 --- a/datafusion/functions/src/core/input_file_name.rs +++ b/datafusion/functions/src/core/input_file_name.rs @@ -38,7 +38,16 @@ evaluated outside a file scan, or was not pushed down into one), direct evaluati "#, syntax_example = "input_file_name()", sql_example = r#"```sql -SELECT input_file_name() FROM t; +> COPY (SELECT * from values (100), (200), (300)) to '/tmp/foo.parquet'; + +> select *, input_file_name(), file_row_index() from '/tmp/foo.parquet'; ++---------+-------------------+------------------+ +| column1 | input_file_name() | file_row_index() | ++---------+-------------------+------------------+ +| 100 | tmp/foo.parquet | 0 | +| 200 | tmp/foo.parquet | 1 | +| 300 | tmp/foo.parquet | 2 | ++---------+-------------------+------------------+ ```"# )] #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/docs/source/user-guide/sql/scalar_functions.md b/docs/source/user-guide/sql/scalar_functions.md index 44e697569a4ef..bdc8efb1bd15d 100644 --- a/docs/source/user-guide/sql/scalar_functions.md +++ b/docs/source/user-guide/sql/scalar_functions.md @@ -5960,7 +5960,16 @@ file_row_index() #### Example ```sql -SELECT file_row_index() FROM t; +> COPY (SELECT * from values (100), (200), (300)) to '/tmp/foo.parquet'; + +> select *, input_file_name(), file_row_index() from '/tmp/foo.parquet'; ++---------+-------------------+------------------+ +| column1 | input_file_name() | file_row_index() | ++---------+-------------------+------------------+ +| 100 | tmp/foo.parquet | 0 | +| 200 | tmp/foo.parquet | 1 | +| 300 | tmp/foo.parquet | 2 | ++---------+-------------------+------------------+ ``` ### `get_field` @@ -6032,7 +6041,16 @@ input_file_name() #### Example ```sql -SELECT input_file_name() FROM t; +> COPY (SELECT * from values (100), (200), (300)) to '/tmp/foo.parquet'; + +> select *, input_file_name(), file_row_index() from '/tmp/foo.parquet'; ++---------+-------------------+------------------+ +| column1 | input_file_name() | file_row_index() | ++---------+-------------------+------------------+ +| 100 | tmp/foo.parquet | 0 | +| 200 | tmp/foo.parquet | 1 | +| 300 | tmp/foo.parquet | 2 | ++---------+-------------------+------------------+ ``` ### `try_cast_to_type`