`sort | take` before an aggregation should enforce the sort in the CTE

Đang mở
#5,401 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust, sql
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start by tracing how PRQL lowers the sort and take steps into SQL when they precede a group, then find the related compiler tests for this input. Run the relevant test suite and add a regression case showing the CTE preserves ORDER BY "Total" DESC before LIMIT 7; done means the generated SQL matches the expected ordering and existing tests pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug
What happened?

Having a sort | take before a group should not erase the sort step in the resulting CTE, as the result of the SQL query is not equal: With the given input, the expected result should be an aggregation by network of the 7 highest values in the Total column. The actual result we get is an aggregation of the 7 first values

PRQL input
from my_table
sort {-this.`Total`} | take 7
group { this.`network` } ( aggregate { `total_sum_by_network` = sum this.`Total` } )
sort {-this.`total_sum_by_network`}
SQL output
WITH table_0 AS (
  SELECT
    network,
    "Total"
  FROM
    my_table
  LIMIT
    7
)
SELECT
  network,
  COALESCE(SUM("Total"), 0) AS total_sum_by_network
FROM
  table_0
GROUP BY
  network
ORDER BY
  total_sum_by_network DESC
Expected SQL output
WITH table_0 AS (
  SELECT
    network,
    "Total"
  FROM
    my_table
  ORDER BY "Total" DESC # This should be added
  LIMIT
    7
)
SELECT
  network,
  COALESCE(SUM("Total"), 0) AS total_sum_by_network
FROM
  table_0
GROUP BY
  network
ORDER BY
  total_sum_by_network DESC
MVCE confirmation
  • Minimal example
  • New issue
Anything else?

No response

Ngôn ngữ chính
Rust
Star
10.9k
Fork
261
Merge trung bình
3 ngày 21 giờ
Pull request đã merge (30 ngày)
84

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PRQL/prql

Tất cả issue của PRQL/prql

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.