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

相关推荐
逸Y 仙X1 小时前
文章三:Elasticsearch 集群恢复和索引分布
java·大数据·linux·服务器·elasticsearch·搜索引擎·全文检索
还是鼠鼠1 小时前
AI掘金头条新闻系统 (Toutiao News)-用户注册-生成Token
后端·python·mysql·fastapi·web
奋斗的小乌龟8 小时前
动态创建Agent02
java
ZFSS8 小时前
Localization Translate API 集成与使用指南
java·服务器·数据库·人工智能·mysql·ai编程
摇滚侠8 小时前
Java 零基础全套教程,集合框架,笔记 153-163
java·开发语言·笔记
nannan12328 小时前
后端技术栈梳理
java
L、2189 小时前
CANN算子开发调试实战:从“Segmentation Fault“到定位根因的完整流程
java·开发语言
东风破1379 小时前
达梦DMDRS搭建、以及DMDRS双向同步
数据库·oracle·dm达梦数据库
索木木10 小时前
NCCL SHARP 和 TREE算法
java·服务器·算法
KaMeidebaby10 小时前
卡梅德生物技术快报|抗独特型抗体开发:半抗原检测技术瓶颈拆解,抗独特型抗体开发工程化实践
前端·数据库·人工智能·其他·百度·新浪微博