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

相关推荐
慢慢雨夜18 分钟前
uniapp 苹果安全域适配
java·前端·uni-app
敲代码不忘补水24 分钟前
二十种编程语言庆祝中秋节
java·javascript·python·golang·html
玖石书26 分钟前
etcd 集群搭建与测试指南
数据库·etcd·集群
南叔先生28 分钟前
Linux 性能优化 copy
网络·数据库·php
码农研究僧37 分钟前
Java或者前端 实现中文排序(调API的Demo)
java·前端·localecompare·中文排序·collator
Chase-Hart38 分钟前
【每日一题】LeetCode 7.整数反转(数学)
java·数据结构·算法·leetcode·eclipse
好记忆不如烂笔头abc41 分钟前
统计信息的导出导入
数据库
四角小裤儿儿44 分钟前
Java数据结构(十一)——归并排序、计数排序
java·数据结构·排序算法
guangzhi06331 小时前
JVM本地方法栈
java·jvm·面试
akhfuiigabv1 小时前
使用LangChain创建简单的语言模型应用程序【快速入门指南】
java·python·语言模型·langchain