-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allowing to expose sort order of parquet file to datafusion does not work #7036
Comments
This is currently supported for CSV files but not Parquet. I think this would be good first issue for new contributors. |
@ozankabak I'm new to datafusion - would love to work on this. |
Great! Happy to help with reviewing 🚀 |
It is supported for CSV, but there's a bit of loopy logic. The issue is that manually specifying the schema for a Parquet file will error and so does not specifying the scheme when there's an ordering - checkmate. The reason it works for CSV's is because we allow the specifying of schemas for them. Is there a reason behind disallowing schemas for Parquet files? In the docs it says "It is not necessary to provide schema information for Parquet files," but that makes it sound optional when it is disallowed by implementation. |
Interesting. @metesynnada can you take a quick look and offer a suggestion? |
I'm uncertain why providing a schema when creating a table is not possible. I believe @tustvold could shed some light on this matter. |
I don't see a reason why this isn't possible, being able to provide the schema for ListingTable is perfectly reasonable |
For some reason, it is restricted and there is no |
I am not sure about how this works internally, but to me (as end user) it makes more sense if it would be possible to only specify the sort order, without having to specify the already known schema. Having to specify the schema again as end user can only lead to inconsistencies (e.g. I specify the wrong type for a column that is present), but I am not sure if this would be allowed by how things are structured at the moment. Would it not be sufficient to check whether the column(s) relevant for sorting is/are present in the file? |
Currently schemas are always resolved for Parquet files, so there shouldn't be a need to specify the schema. I'm inclined to agree with @bmmeijers here, but you might have some context that says otherwise. During parsing, can we just ignore the fact that the schema is inferred later? I'm not familiar with the implementation of |
There are numerous scenarios where providing a schema becomes essential, such as specifying an integer type or a primary key. Given its extensive use, it's surprising that we don't currently offer a schema provision option. A significant number of end-users will find value in this feature, even if it's not universally needed. I believe it's crucial to support this highly utilized SQL pattern. However, providing a schema might not be a mandatory requirement for using the |
I agree -- I don't think there is any reason not to support defining a schema for parquet files. I think it was historically less useful than for CSF files, as the column type information is encoded directly in parquet files so for basic uses, it is more convenient if the user doesn't have to explicitly define the columns in the SQL I agree with @bmmeijers on the ideal end user behavior is #7036 (comment) However, in my opinion, if the initial implementation of |
FWIW I think after the work from @devinjdangelo in #7244 this feature should now be a matter of hooking up the code (or maybe even removing an error) and writing a test. So marking it as a good first issue. Here is a reproducer:
The goal is to make this work:
Possibly:
|
@alamb should we use this issue to track the fix or do we want to open a subissue ? I can start looking into this soon |
I double checked the current behavior on main. It is now possible to specify the sort order for the parquet file (and you can see the output _order is correctly reflected)
However, it is not possible to specify just the order without the schema:
Per @edmondop 's suggestion I think the clearest thing is to close this ticket as complete (the sort order can be specified) and I will open a new ticket to allow specifying order without setting the schema |
Filed #7317 to track |
Describe the bug
I am trying to perform a range join on two parquet files with datafusion-cli, but it makes an unrealistic query plan.
I try to express the sort order in both parquet files when registering the parquet files with datafusion-cli.
However, I am somehow stuck with expressing this sort order as the
with order (columnname ordering)
clause seems to be unusable together with parquet files.To Reproduce
The points table has 1 numeric column and the intervals table has two columns. With duckdb I generated parquet files for both:
(which I both ran through parquet-rewrite to add page level statistics).
I would expect that the sort order present in both files could help very much to query efficiently (I would pick a sort-merge-join, but without the sort of the files being necessary, as the data is already sorted, so just the merge part with scanning for the overlapping parts of the table).
Hence, I tried to register the parquet files with datafusion-cli and express that the files are already sorted.
This works:
But this does not:
It errors with:
If I try to specify the schema manually:
It errors with:
Which is not surprising.
Expected behavior
I would expect that the sort order can be expressed and that the query planner subsequently can execute a sort-merge-join, where the sort step would be unnecessary (as the data of both sides of the join is already sorted).
Additional context
No response
The text was updated successfully, but these errors were encountered: