SQL API: ORDER BY throws NullPointerException when the sort column contains NULL

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

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

@AarushShetty346 đang làm issue này rồi.

Từ ngày 18/11/2026.

  • #892 của @AarushShetty346 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, sql

Hướng nghiên cứu

Start with SortKeyExtractor.java at the comparison on line 50 and WayangSortVisitor.java at lines 60–61, which maps the sort direction. Trace how Calcite’s null direction reaches the comparator, then run the SQL API sorting tests with the provided CSV and queries. Done when ascending, descending, and explicit NULLS FIRST produce the expected row order without an exception.

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

Mô tả

ORDER BY in the SQL API fails with a NullPointerException as soon as the sort column has a NULL value.

The bug

SortKeyExtractor compares sort keys directly at SortKeyExtractor.java:50:

final int comparison = direction.isDescending() ? -thisField.compareTo(thatField) : thisField.compareTo(thatField);

An empty cell in a numeric CSV column is read as null, so thisField (or thatField) can be null here. The null direction of the collation (NULLS FIRST / NULLS LAST) is also never passed on: WayangSortVisitor.java:60-61 only maps getDirection().

To reproduce

A table with one empty value in an int column:

col1:int,col2:string
1;a
;b
3;c
SELECT col1, col2 FROM fs.exampleNull ORDER BY col1

on the Java platform gives:

Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "thisField" is null
    at org.apache.wayang.api.sql.calcite.converter.functions.SortKeyExtractor$1.compareTo(SortKeyExtractor.java:50)
    at org.apache.wayang.api.sql.calcite.converter.functions.SortKeyExtractor$1.compareTo(SortKeyExtractor.java:39)
    at org.apache.wayang.java.operators.JavaSortOperator.lambda$evaluate$0(JavaSortOperator.java:79)
Expected

The NULL row is sorted instead of crashing, using Calcite's default when no null direction is given (NULLS LAST for ASC, NULLS FIRST for DESC):

  • ORDER BY col1 → (1, a), (3, c), (null, b)
  • ORDER BY col1 DESC → (null, b), (3, c), (1, a)
  • ORDER BY col1 NULLS FIRST → (null, b), (1, a), (3, c)

Tested on main at 713faa7. I have a fix with tests and will open a PR for it.

Ngôn ngữ chính
Java
Star
284
Fork
147
Merge trung bình
3 ngày 17 giờ
Pull request đã merge (30 ngày)
15

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

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 apache/wayang

Tất cả issue của apache/wayang

Issue tương tự

Thêm issue về Java

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.