Skip to content

test: use WITH ORDER tables for date_bin/date_trunc ordering plan tests - #26332

Merged
alamb merged 1 commit into
apache:mainfrom
viirya:timestamps-slt-with-order
Oct 15, 2026
Merged

alamb merged 1 commit into
apache:mainfrom
viirya:timestamps-slt-with-order

Conversation

@viirya

@viirya viirya commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

In #25815, @alamb asked why a plan still had a SortExec when ordering propagation should remove it. That sort was the TopK(fetch=n) from the ORDER BY ... LIMIT n subquery used to produce ordered input. The outer sort, the one the test was about, had already been removed. Reading the input from a table declared sorted makes the plans show this directly: no sort at all when the ordering propagates, and only the final sort when it does not.

What changes are included in this PR?

Test-only. In datetime/timestamps.slt, the seven ordering-propagation EXPLAIN tests through date_bin, date_trunc and from_unixtime (plus the result queries next to them) now read from CSV files written with COPY ... TO and registered with CREATE EXTERNAL TABLE ... WITH ORDER. This follows the pattern in order.slt. Each DataSourceExec reports the declared output_ordering.

  • The five cases where the sort is removed (timezone-free from_unixtime, timezone-free date_bin, coarse-precision values outside the nanosecond range, positive month stride, nested date_trunc) now have no SortExec.
  • The America/Goose_Bay case keeps exactly one SortExec, the required final sort.
  • The data is unchanged: Timestamp(Second) columns come from TIMESTAMP(0), the coarse-precision case still uses ±10,000,000,000 seconds, and every query result is unchanged. The Goose Bay result query moved next to its EXPLAIN.

I did not find any other date_bin/date_trunc ordering plan tests that use the ORDER BY ... LIMIT subquery pattern. The related tests in group_by.slt and sort_pushdown.slt already use WITH ORDER.

What is the testing strategy for this PR?

This PR only changes tests. datetime/timestamps.slt passes.

Are there any user-facing changes?

No.

Read the sorted input of the ordering propagation EXPLAIN tests in
timestamps.slt from CSV tables declared with `WITH ORDER`, instead of an
`ORDER BY ... LIMIT n` subquery. The subquery left a TopK in every plan,
so a plan where the outer sort was removed still showed a SortExec.

Positive cases now have no SortExec at all, and the named-timezone case
keeps exactly the one required sort.
@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Oct 14, 2026
@viirya
viirya requested a review from alamb October 14, 2026 22:11
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.80%. Comparing base (6023600) to head (af23616).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #26332    +/-   ##
========================================
  Coverage   82.79%   82.80%            
========================================
  Files        1149     1149            
  Lines      454146   454480   +334     
  Branches   454146   454480   +334     
========================================
+ Hits       376032   376330   +298     
- Misses      55262    55280    +18     
- Partials    22852    22870    +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- thank you @viirya

562129259 562129200
# The ordering propagation tests below read from tables declared sorted with
# `WITH ORDER`, so a plan has no sort at all when the ordering propagates, and
# exactly the final sort when it must not. Each file is written in its

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

01)ProjectionExec: expr=[date_trunc(hour, from_unixtime(column1@0)) as truncated]
02)--SortExec: TopK(fetch=2), expr=[column1@0 ASC NULLS LAST], preserve_partitioning=[false]
03)----DataSourceExec: partitions=1, partition_sizes=[1]
01)SortPreservingMergeExec: [truncated@0 ASC NULLS LAST]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@alamb
alamb added this pull request to the merge queue Oct 15, 2026
@viirya

viirya commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Thank you @alamb !

Merged via the queue into apache:main with commit db425eb Oct 15, 2026
43 checks passed
@viirya
viirya deleted the timestamps-slt-with-order branch October 15, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqllogictest SQL Logic Tests (.slt) v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants