datawind可视化查询-类型转换函数

飞书文档学习链接:https://www.volcengine.com/docs/4726/47275

1 常用函数快速入门

类型转换函数用于对字段进行类型转换,如文本与数字转换。

1.1 强制转换任意类型

格式:cast(xxx,'类型'),将 xxx 转化为特定类型

示例:

cast(字段A,'string')则将字段A 转化成了字符串格式

1.2 转换成字符串(文本)

格式:toString(xxx),将字段 xxx 转换为字符串格式,可以把数字、字符、日期等类型字段转换掉。

示例:

|-----------------|-----------------|
| 字段A | toString(字段A) |
| 143876768892010 | 143876768892010 |

转换前字段A 为数值格式,由于较长在分析时容易被科学计数;转换为字符串后则能稳定保存。

1.3 转换成整数值

格式:toInt64(xxx),将字段 xxx 转换为整数,xxx 中只能有数字。

|-----------------|-----------------|
| 字段A | toInt64(字段A) |
| 143876768892010 | 143876768892010 |
| 123a | 转换失败 |

2 功能详解

|-------------------------------|---------------------------------|-----------------------------------------------------------------------------------------------|---------------------------------------------------------------|
| 函数名称 | 函数格式 | 用途 | 示例 |
| cast | cast(X, 'Y') | 通用强转函数,将名称为X的任意类型数据,转化成 Y 格式 | 将 int 类型的 uid 转换为 String 类型 CAST (uid, 'String') |
| toString | toString(x) | 将数值型、字符型、日期等转化为字符型 | toString('2018-12-24') 返回 2018-12-24 |
| toInt64 | toInt64(x) | 将数据类型转化为 int 格式(64 个字节) | toInt64(123.883) 返回 123 |
| toUInt8OrZero | toUInt8OrZero(x) | 将无符号整数字符型转化为整数型,否则返回 0 | toUInt8OrZero('123.12') 返回 0 |
| toDateOrZero | toDateOrZero(x) | 将数据类型转化为 DATE 格式,否则返回 0 | toDateOrZero(toDateTime('2018-12-11 11:12:13')) 返回 2018-12-11 |
| toUInt16OrZero | toUInt16OrZero(x) | 将无符号整数字符型转化为整数型,否则返回 0 | toUInt8OrZero('123') 返回 123 |
| toUInt64OrZero | toUInt64OrZero(x) | 将数据类型转化为 int 格式(64 个字节),失败则为 0 | toUInt64OrZero('123') 返回 123 |
| toDateOrNull | toDateOrNull(a) | 将 a 的数据类型转成 date or null | |
| toUInt32OrZero | toUInt32OrZero(x) | 将数据类型转化为 int 格式(32 个字节),失败则为 0 | |
| toFloat32OrZero | toFloat32OrZero( ) | 将数值字符串型转化为数值型 | toFloat32OrZero('-123') 返回-123 |
| toIntervalMonth | toIntervalMonth( ) | 将数字类型参数转换为 Interval 类型(时间区间) | |
| toInt32 | toInt32(a) | 将 a 的数据类型转成 int32 | |
| toDateTimeOrNull | toDateTimeOrNull(a) | 将 a 的数据类型转成 datetime or null | |
| toFloat64 | toFloat64(a) | 将 a 的数据类型转成 float64 | |
| toUInt8 | toUInt8(a) | 将 a 的数据类型转成 Uint8 | |
| toFloat64OrZero | toFloat64OrZero(a) | 将 a 的数据类型转成 float or zero | |
| toUInt32 | toUInt32(a) | 将 a 的数据类型转成 Uint32 | |
| parseDateTimeBestEffort | parseDateTimeBestEffort() | 将数字类型参数解析为 Date 或 DateTime 类型。 与 toDate 和 toDateTime 不同,parseDateTimeBestEffort 可以进行更复杂的日期格式。 | |
| parseDateTimeBestEffortOrNull | parseDateTimeBestEffortOrNull() | 将数字类型参数解析为 Date 或 DateTime 类型,遇到无法处理的日期格式时返回 null | |
| parseDateTimeBestEffortOrZero | parseDateTimeBestEffortOrZero() | 将数字类型参数解析为 Date 或 DateTime 类型,遇到无法处理的日期格式时返回零 Date 或零 DateTime | |

相关推荐
on the way 12313 小时前
day10 - Spring 之配置类源码解析
java·后端·spring
A101693307114 小时前
QT数据库(三):QSqlQuery使用
数据库·qt·oracle
行者-全栈开发14 小时前
JDK 17 + Spring Boot 3.5.8:企业级开发技术栈全景
java·开发语言·spring boot·系统架构·技术栈·系统架构全景分析·springboot技术栈
码云数智-大飞14 小时前
分布式锁的三种实现方案:Redis、ZooKeeper与数据库的深度对比与选型指南
数据库·redis·分布式
WHS-_-202214 小时前
mCore: Achieving Sub-millisecond Scheduling for 5G MU-MIMO Systems
java·算法·5g
“抚琴”的人14 小时前
SqlSugar 文档
开发语言·数据库·c#·sqlsugar
Jin、yz14 小时前
黑马苍穹外卖项目收获
java
a***716314 小时前
IDEA连接SQL server数据库(保姆级详细且必坑,包括防火墙、 SQL Server 网络配置等问题解决)
网络·数据库·intellij-idea
木易 士心14 小时前
告别手写SQL?Cursor智能生成实战指南与避坑技巧
数据库·sql·ai编程
倔强的石头10614 小时前
KWDB 硬核实战:30ms 写入千条轨迹,用 SQL 打造物流车队“天眼”系统
数据库·sql·kwdb