To_iso8601函数比较

【TDengine 使用环境】
生产环境 /测试/ Poc/预生产环境

【TDengine 版本】

3.3.8.1

【操作系统以及版本】

centos7

【部署方式】容器/非容器部署

容器单机

【集群节点数】

【集群副本数】

【描述业务影响】

create stream if not exists lute_iot_device.t31_daily_stats_stream_min_max_avg interval(1d) sliding (1d)

from

lute_iot_device.product_property_3yhuya partition by tbname stream_options (watermark (5 m) | fill_history (1))

into

lute_iot_device.t31_daily_stats output_subtable (concat('t31_daily\_', **lower**(tbname))) ( ts,

uid composite **key**,

calculate_time,

window_end,

avg_temperature,

max_temperature,

min_temperature ) tags ( device_name **varchar**(64) **as** replace (tbname,

'device_property\_',

'') ) **as**

select

\_twstart **as** ts,

uid **as** uid,

**cast**(\_tlocaltime / 1000000 **as** **timestamp**) **as** calculate_time,

\_twend **as** window_end,

round(**avg**(temperature), 2) **as** avg_temperature,

**max**( **case** **when** identifier = 'high_temperature_alarm' **then** temperature **else** **null** **end** ) **as** max_temperature,

**min**( **case** **when** identifier = 'low_temperature_alarm' **then** temperature **else** **null** **end** ) **as** min_temperature

from

%%tbname

where

TO_ISO8601(ts,time_offset) >= \_twstart

**and** TO_ISO8601(ts,time_offset) <= \_twend **partition** **by** device_name,

uid;

这个是我的流计算,time_offset是我的时区字段,请问一下如果我需要时区转换可以用TO_ISO8601函数转换后去和窗口的开始时间和结束时间比较吗

【问题复现路径/shan】做过哪些操作出现的问题

【遇到的问题:问题现象及影响】

【资源配置】

【报错完整截图】(不要大段的粘贴报错代码,论坛直接看报错代码不直观)

sql截图如下


TO_ISO8601 返回类型是 VARCHAR,窗口的开始时间和结束时间是时间戳类型,可通过函数 TO_UNIXTIMESTAMP 转化后进行比较

这样转换我可以跨时区统计吗 ,服务器部署都是基于utc0时区的,流计算一天统计一次的话就会导致统计的数据不准,比如北京时间上午7点的数据就会被统计到上一天去。因此我在计算的时候我需要把上面的ts字段根据存入的时区进行转换,比如东八区 我需要加8个小时,然后和流计算的开始时间和结束时间进行比较

但是我看这里加8和减8返回的时间戳是一样的

+8 -8 仅改变时间在不同时区的信息,不改变原始绝对时间戳。目前还没有直接支持时区替换函数 CONVERT_TZ,如果想改变时间戳数值,可根据需要进行算术运算。

好的 明白了

大佬 还有一个问题 在时间戳上面使用函数 然后比较不会影响查询的性能吧

函数调用需要一定的开销,尽量减少不必要函数的调用,尽量在搭建环境时使用相同的配置,如:同一时区,避免处理时转换