Skip to content

Commit

Permalink
fix: 更新时间类型数据转换逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhu92 committed Mar 4, 2024
1 parent b3da792 commit 83a117e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/log-service/common/format/prestoType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@ const ProcessorUtils = {
/** Presto类型与FieldType转化表
* @doc https://iwiki.woa.com/pages/viewpage.action?pageId=905584985 */
const PrestoAndFieldTypeMap: Omit<IAnalysisColumn, 'Name' | 'Type'>[] = [
/** 时间类型分为两类,包含日期和不包含日期 */
/** 时间类型分为两类,包含日期和不包含日期,不包含日期的转成字符类型 */
{
prestoTypeRegex: /^timestamp with time zone$/,
fieldType: FieldType.time,
// 包含时区的时间数据,可能带有额外的zone信息,这里进行清理。eg: 2021-11-26T18:41:24+08:00[Asia/Shanghai]
processor: (value: string) => {
const newValue = String(value).replace(ProcessorUtils.timestampWithTimeZoneRegex, '$1');
if (moment(newValue).isValid()) {
return newValue;
const time = moment(newValue);
if (time.isValid()) {
return time.valueOf();
}
return value;
},
},
{
prestoTypeRegex: /^timestamp$|^date$|^datetime$/,
fieldType: FieldType.time,
// processor: moment,
// 将所有时间类型转化为时间戳。
// 小问题:如果用户设置了数据转化,且将字段配置为普通维度,此时展示的不是后台返回的字符串,而是时间戳文本。方案:推荐用户使用 time_series 函数生成时间字符串
processor: (value: any): number | string => {
const time = moment(value);
if (time.isValid()) {
return time.valueOf();
}
return value;
},
},
{
prestoTypeRegex: /^time$/,
fieldType: FieldType.time,
prestoTypeRegex: /^time$|^time with time zone$/,
fieldType: FieldType.string,
// processor: null,
},
/** 数字类型。整数、浮点数、定点数 */
Expand Down

0 comments on commit 83a117e

Please sign in to comment.