-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Make file_row_number
a virtual column, and support per-file virtual columns in the MultiFileReader
#16979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+112
−31
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…use this to make file_row_number a virtual column
…umber in conjunction with schema
So in iceberg/delta we can set |
There are two ways to refer to the
Which option is best depends on where this is used in the code. |
Mytherin
added a commit
that referenced
this pull request
May 2, 2025
…(*)` directly in the multi file reader (#17325) This PR generalizes the late materialization optimizer introduced in #15692 - allowing it to be used for the Parquet reader. In particular, the `TableFunction` is extended with an extra callback that allows specifying the relevant row-id columns: ```cpp typedef vector<column_t> (*table_function_get_row_id_columns)(ClientContext &context, optional_ptr<FunctionData> bind_data); ``` This is then used by the Parquet reader to specify the two row-id columns: `file_index` (#17144) and `file_row_number` (#16979). Top-N , sample and limit/offset queries are then transformed into a join on the relevant row-id columns. For example: ```sql SELECT * FROM lineitem.parquet ORDER BY l_extendedprice DESC LIMIT 5; -- becomes SELECT * FROM lineitem.parquet WHERE (file_index, file_row_number) IN ( SELECT file_index, file_row_number FROM lineitem.parquet ORDER BY l_extendedprice DESC LIMIT 5) ORDER BY l_extendedprice DESC; ``` ### Performance ```sql SELECT * FROM lineitem.parquet ORDER BY l_extendedprice DESC LIMIT 5; ``` | v1.2.1 | main | new | |--------|--------|--------| | 0.19s | 0.14s | 0.06s | ```sql SELECT * FROM lineitem.parquet ORDER BY l_orderkey DESC LIMIT 5; ``` | v1.2.1 | main | new | |--------|-------|-------| | 0.73s | 0.53s | 0.06s | ```sql SELECT * FROM lineitem.parquet LIMIT 1000000 OFFSET 10000000; ``` | v1.2.1 | main | new | |--------|-------|-------| | 1.6s | 1.2s | 0.14s | ### Refactor I've also moved the `ParquetMultiFileInfo` to a separate file as part of this PR - which is most of the changes here.
krlmlr
added a commit
to duckdb/duckdb-r
that referenced
this pull request
May 15, 2025
Make `file_row_number` a virtual column, and support per-file virtual columns in the MultiFileReader (duckdb/duckdb#16979)
krlmlr
added a commit
to duckdb/duckdb-r
that referenced
this pull request
May 15, 2025
Make `file_row_number` a virtual column, and support per-file virtual columns in the MultiFileReader (duckdb/duckdb#16979)
krlmlr
added a commit
to duckdb/duckdb-r
that referenced
this pull request
May 16, 2025
Make `file_row_number` a virtual column, and support per-file virtual columns in the MultiFileReader (duckdb/duckdb#16979)
krlmlr
added a commit
to duckdb/duckdb-r
that referenced
this pull request
May 16, 2025
Make `file_row_number` a virtual column, and support per-file virtual columns in the MultiFileReader (duckdb/duckdb#16979)
krlmlr
added a commit
to duckdb/duckdb-r
that referenced
this pull request
May 17, 2025
Make `file_row_number` a virtual column, and support per-file virtual columns in the MultiFileReader (duckdb/duckdb#16979)
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow-up from #16248
This PR reworks the
file_row_number
to be a virtual column in the Parquet reader, so the following query now works:This PR also implements the necessary infrastructure for allowing arbitrary virtual columns to be defined by readers, so in the future adding new virtual columns to readers will be much simpler.
This rework allows for the removal of a bunch of hacky special-case code around the
file_row_number
column - this can now all live in the Parquet reader itself. Emitting the file row number is as simple as adding the special code (MultiFileReader::COLUMN_IDENTIFIER_FILE_ROW_NUMBER
) to the set of projected column ids.