4paradigm / 4paradigm/OpenMLDB

SQL function: `FirstValue` and `LastValue`

Đang mở
#222 0 bình luận 0 reaction 1 người được giao Được giao cho @aceforeverd Xem trên GitHub
enhancement
Ngôn ngữ chính
C++
Star
1.7k
Fork
331
Merge trung bình
12 ngày 12 giờ
Pull request đã merge (30 ngày)
1

Mô tả

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

## first_value
`first_value(expr[, isIgnoreNull]) `
- Returns the first value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values.

### Examples:
```SQL

> SELECT first_value(col) FROM VALUES (10), (5), (20) AS tab(col);
10
> SELECT first_value(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
> SELECT first_value(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5
```

### Note:
The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

## last_value
l`ast_value(expr[, isIgnoreNull])`
- Returns the last value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values

### Examples:
```SQL
> SELECT last_value(col) FROM VALUES (10), (5), (20) AS tab(col);
20
> SELECT last_value(col) FROM VALUES (10), (5), (NULL) AS tab(col);
NULL
> SELECT last_value(col, true) FROM VALUES (10), (5), (NULL) AS tab(col);
5
```

### Note:

The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

目前HybridSE的在线数据是默认倒序的。在获取firstvalue和lastvalue需要特别关注这个问题
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

The issue is about implementing SQL window functions `first_value` and `last_value` in OpenMLDB, with an optional null-ignoring flag. Look for existing window function implementations in the codebase, likely in SQL parser and execution engine. Understand how online data ordering works (default reverse order). Start by examining the function registration and evaluation logic for aggregate/window functions. Write tests to verify behavior with and without the isIgnoreNull parameter.

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

Đánh giá

Công nghệ
sql
Lĩnh vực
databases, machine-learning
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

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.