Hue 访问 Impala 时间格式问题
# 一、修复后的效果展示
在完成代码修复并重启 Hue 服务后,JobBrowser 中的 Impala 查询历史页面 已可正常展示,查询列表、时间列及筛选条件均恢复正常。

可以看到:
- 查询记录可正常加载
- 提交时间字段格式正确
- 页面不再出现异常提示
# 二、问题回溯:异常是如何出现的
在修复之前,访问 JobBrowser 页面时,Hue 前端资源请求均返回 200,但页面数据无法正确渲染。
Hue 后端日志中可以看到明确的异常堆栈:
[05/Dec/2025 00:50:20 -0800] access INFO 192.168.3.116 admin - "POST /api/editor/autocomplete/default/test3/ HTTP/1.1" returned in 3835ms 200 296
[05/Dec/2025 00:50:28 -0800] access INFO 192.168.3.116 admin - "GET /metastore/tables/default HTTP/1.1" returned in 37ms 200 42125
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "GET /static/desktop/ext/css/bootstrap-editable.0a3786b979c5.css HTTP/1.1" returned in 13ms 200 -
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "GET /static/notebook/css/notebook.14874d94c040.css HTTP/1.1" returned in 22ms 200 -
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "GET /static/beeswax/js/stats.utils.8505e7dd1d22.js HTTP/1.1" returned in 8ms 200 -
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "GET /static/metastore/css/metastore.02ebb811e438.css HTTP/1.1" returned in 17ms 200 -
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "GET /static/desktop/js/bundles/hue/tableBrowser-bundle-8c66a54b3bdb5f6ef684.25a2b4fd8225.js HTTP/1.1" returned in 13ms 200 -
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "GET /static/metastore/art/icon_metastore_48.a6dee13a6698.png HTTP/1.1" returned in 10ms 200 -
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "GET /static/beeswax/js/stats.utils.8505e7dd1d22.js HTTP/1.1" returned in 2ms 200 -
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "GET /static/desktop/js/bundles/hue/tableBrowser-bundle-8c66a54b3bdb5f6ef684.25a2b4fd8225.js HTTP/1.1" returned in 2ms 200 -
[05/Dec/2025 00:50:29 -0800] api2 ERROR Error running <function jobs at 0x7fc1cca2f940>
Traceback (most recent call last):
File "/usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/api2.py", line 48, in decorator
return func(*args, **kwargs)
File "/usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/api2.py", line 73, in jobs
jobs = get_api(request.user, interface, cluster=cluster).apps(filters)
File "/usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/apis/query_api.py", line 83, in apps
'apps': sorted([{
File "/usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/apis/query_api.py", line 99, in <listcomp>
'submitted': datetime.strptime(job['start_time'][:-3], "%Y-%m-%d %H:%M:%S.%f").
File "/usr/bigtop/current/hue/build/env/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/bigtop/current/hue/build/env/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2025-12-05 16:50:16.' does not match format '%Y-%m-%d %H:%M:%S.%f'
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "POST /jobbrowser/api/jobs/queries-impala HTTP/1.1" returned in 13ms 200 106
[05/Dec/2025 00:50:29 -0800] api2 ERROR Error running <function jobs at 0x7fc1cca2f940>
Traceback (most recent call last):
File "/usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/api2.py", line 48, in decorator
return func(*args, **kwargs)
File "/usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/api2.py", line 73, in jobs
jobs = get_api(request.user, interface, cluster=cluster).apps(filters)
File "/usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/apis/query_api.py", line 83, in apps
'apps': sorted([{
File "/usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/apis/query_api.py", line 99, in <listcomp>
'submitted': datetime.strptime(job['start_time'][:-3], "%Y-%m-%d %H:%M:%S.%f").
File "/usr/bigtop/current/hue/build/env/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/bigtop/current/hue/build/env/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2025-12-05 16:50:16.' does not match format '%Y-%m-%d %H:%M:%S.%f'
[05/Dec/2025 00:50:29 -0800] access INFO 192.168.3.116 admin - "POST /jobbrowser/api/jobs/queries-impala HTTP/1.1" returned in 12ms 200 106
[05/Dec/2025 00:50:39 -0800] access INFO 192.168.3.116 admin - "POST /jobbrowser/jobs/ HTTP/1.1" returned in 7ms 200 12
[root@dev1 logs]# vim /usr/bigtop/current/hue/apps/jobbrowser/src/jobbrowser/apis/query_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
关键特征
time data '2025-12-05 16:50:16.' does not match format '%Y-%m-%d %H:%M:%S.%f'
# 三、问题根因分析:时间格式假设失效
从异常可以直接定位到问题本质:
- Hue JobBrowser 代码中 假定 Impala 返回的 start_time 一定包含毫秒
- 实际 Impala 返回的时间字符串为:
2025-12-05 16:50:16.
1
该字符串具备以下特征:
| 项目 | 实际情况 |
|---|---|
| 时间精度 | 秒级 |
| 毫秒部分 | 缺失,仅保留 . |
| Hue 预期 | %Y-%m-%d %H:%M:%S.%f |
在这种情况下,datetime.strptime 必然抛出 ValueError,导致 JobBrowser 接口直接异常返回。
# 四、定位修改点:query_api.py
通过异常堆栈可以明确定位到问题文件:
apps/jobbrowser/src/jobbrowser/apis/query_api.py
1
对应代码位置如下图所示(时间解析相关逻辑):

# 五、修复补丁
Subject: [PATCH] [fixed] 处理日期格式错乱问题,适配 4.11 impala
---
Index: apps/jobbrowser/src/jobbrowser/apis/query_api.py
===================================================================
diff --git a/apps/jobbrowser/src/jobbrowser/apis/query_api.py b/apps/jobbrowser/src/jobbrowser/apis/query_api.py
--- a/apps/jobbrowser/src/jobbrowser/apis/query_api.py
+++ b/apps/jobbrowser/src/jobbrowser/apis/query_api.py
@@ -96,8 +96,10 @@
- 'submitted': datetime.strptime(job['start_time'][:-3], "%Y-%m-%d %H:%M:%S.%f").
- replace(tzinfo=pytz.utc).astimezone(localtime._get_localzone()).strftime("%Y-%m-%d %H:%M:%S.%f"),
+ 'submitted': datetime.strptime(job['start_time'].split('.')[0], "%Y-%m-%d %H:%M:%S") \
+ .replace(tzinfo=pytz.utc).astimezone(localtime._get_localzone()) \
+ .strftime("%Y-%m-%d %H:%M:%S.%f"),
@@ -321,8 +323,10 @@
- lambda app: current_ms - (time.mktime(datetime.strptime(app['start_time'][:26], '%Y-%m-%d %H:%M:%S.%f').timetuple()) * 1000)
- < period_ms
+ lambda app: current_ms - (time.mktime(datetime.strptime(
+ app['start_time'].split('.')[0], '%Y-%m-%d %H:%M:%S'
+ ).timetuple()) * 1000)
+ < period_ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
修改要点
- 统一使用
split('.')处理毫秒缺失场景 - 消除对字符串长度与固定格式的隐式依赖
- 对现有逻辑影响最小,风险可控
也可以参考: 👉 生产环境下解决方案——Hue/query_api.py