Skip to content
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

SanityCheckPlan Error during planning: ... does not satisfy parent order requirements: ... #11492

Closed
alamb opened this issue Jul 16, 2024 · 1 comment · Fixed by #11506
Closed
Labels
bug Something isn't working

Comments

@alamb
Copy link
Contributor

alamb commented Jul 16, 2024

Describe the bug

When run this query I get an error

> SELECT (SELECT cpu from t2 ORDER BY cpu) UNION ALL (SELECT 'bar' as cpu from t2) ORDER BY cpu;

SanityCheckPlan
caused by
Error during planning: Child: ["UnionExec", "  SortExec: expr=[cpu@0 ASC NULLS LAST], preserve_partitioning=[true]", "    ProjectionExec: expr=[CAST(cpu@0 AS Utf8) as cpu]", "      RepartitionExec: partitioning=RoundRobinBatch(16), input_partitions=1", "        CsvExec: file_groups={1 group: [[tmp/table.csv]]}, projection=[cpu], output_ordering=[cpu@0 ASC NULLS LAST], has_header=true", "  ProjectionExec: expr=[bar as cpu]", "    CsvExec: file_groups={1 group: [[tmp/table.csv]]}, has_header=true"] does not satisfy parent order requirements: [PhysicalSortRequirement { expr: Column { name: "cpu", index: 0 }, options: Some(SortOptions { descending: false, nulls_first: false }) }]
>

To Reproduce

# Make 1 row csv file:
echo "cpu" > /tmp/table.csv
echo "1" >> /tmp/table.csv
# run datafusion-cli
datafusion-cli
-- define table with existing order
create external table t1(cpu int)
stored as csv location '/tmp/table.csv'
with order (cpu)
OPTIONS (format.has_header true);

--- Union a query with the actual data and one with a constant
SELECT (SELECT cpu from t2 ORDER BY cpu) UNION ALL (SELECT 'bar' as cpu from t2) ORDER BY cpu;

Expected behavior

I expect the query to run successfully and produce a two column table

+-----+
| cpu |
+-----+
| 1 |
| foo |
+-----+

Additional context

@appletreeisyellow found this while upgrading DataFusion in InfluxDB 3.0 with the change from #11196

We also tried applying the patch from @suremarc in #11363 but the query still fails

Interestingly, a very similar query that uses 2 constants works fine:

> SELECT (SELECT 'foo' as cpu from t2 ORDER BY cpu) UNION ALL (SELECT 'bar' as cpu from t2) ORDER BY cpu;

+-----+
| cpu |
+-----+
| bar |
| foo |
+-----+
2 row(s) fetched.
Elapsed 0.003 seconds.
@alamb alamb added the bug Something isn't working label Jul 16, 2024
@alamb
Copy link
Contributor Author

alamb commented Jul 16, 2024

When I was debugging this in our environment, I think the bug seems to be that the UnionExec is not correctly computing its output sort order when only one of the inputs has a constant output but not all of them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant