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 | |

相关推荐
QuZero1 分钟前
JDK7 ConcurrentHashMap principle
java·哈希算法
2301_8145902513 分钟前
Python深度学习入门:TensorFlow 2.0/Keras实战
jvm·数据库·python
独断万古他化18 分钟前
【Java 实战项目】多用户网页版聊天室:消息传输模块 —— 基于 WebSocket 实现实时通信
java·spring boot·后端·websocket·ajax·mybatis
VALENIAN瓦伦尼安教学设备23 分钟前
设备对中不良的危害
数据库·嵌入式硬件·算法
yyt36304584125 分钟前
spring单例bean线程安全问题讨论
java·spring
小兔崽子去哪了35 分钟前
Docker 安装 PostgreSQL
数据库·后端·postgresql
野犬寒鸦39 分钟前
Redis热点key问题解析与实战解决方案(附大厂实际方案讲解)
服务器·数据库·redis·后端·缓存·bootstrap
我是大猴子1 小时前
事务失效的几种情况以及是为什么(详解)
java·开发语言
mldlds1 小时前
Windows安装Redis图文教程
数据库·windows·redis
wertyuytrewm1 小时前
Java面试——Java基础
java·jvm·面试