matrixorigin / matrixorigin/matrixone

[Compatibility]: TIME_FORMAT emits specifier letters for missing date fields

Open
#28,567 1 comment 0 reactions 1 assignee Claimed by @jiangxinmeng1 View on GitHub
area/compatibility kind/bug needs-triage
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

## 现象

MatrixOne `main`(`ac660ae56ecd37bab3dd8c61193617a323377029`)的 `TIME_FORMAT()` 对日期类 format specifier 直接去掉 `%` 并输出字母,和 MySQL 的零日期/`NULL` 语义不同。

```sql
SELECT TIME_FORMAT(CAST('12:34:56.123456' AS TIME(6)),
'%Y-%m-%d %H:%i:%s.%f');
SELECT TIME_FORMAT(CAST('12:34:56.123456' AS TIME(6)), '%W');
SELECT TIME_FORMAT(CAST('12:34:56.123456' AS TIME(6)), '%M');
SELECT TIME_FORMAT(CAST('12:34:56.123456' AS TIME(6)), '%X-%V');
```

MatrixOne:

```text
Y-m-d 12:34:56.123456
W
M
X-V
```

MySQL 8.0.46:

```text
0000-00-00 12:34:56.123456
NULL
NULL
NULL
```

`%Y`、`%m`、`%d` 在 MySQL 中分别得到 `0000`、`00`、`00`,MatrixOne 则分别得到 `Y`、`m`、`d`。时间类 `%H:%i:%s.%f`、`%%` 和未知 `%q` 控制组在两端一致。

## 期望

`TIME_FORMAT()` 应按 MySQL 语义处理缺失的日期部分:数值日期字段输出零值,需要日期名称或周历上下文的字段返回 `NULL`;不能将 format specifier 的字母误当成普通文本。

## 代码定位

`pkg/sql/plan/function/func_binary.go` 的 `makeTimeFormat` 仅实现时间类 specifier;`default` 分支直接执行 `buf.WriteRune(b)`。代码注释认为这与 MySQL 的“忽略非时间 specifier”行为一致,但 MySQL 实际会对数字日期字段输出零值,并对日期名称/周历字段返回 `NULL`。

## 复现信息

- MatrixOne main:`ac660ae56ecd37bab3dd8c61193617a323377029`
- MySQL:8.0.46
- 代表性 specifier 和控制组重复执行 3 次,结果一致

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.