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

相关推荐
天文家几秒前
深入理解装饰器与适配器:从设计模式到 Spring AOP 的工程实践
java·设计模式
zzz_23683 分钟前
【Redis】分布式锁完整演进
数据库·redis·分布式
贺国亚4 分钟前
Spring-AI与LangChain4j
java·人工智能·spring
野生技术架构师18 分钟前
2026 Java面试宝典(春招/社招/秋招通用):没有前言,只有答案,直接开背
java·开发语言·面试
mN9B2uk1724 分钟前
数据库的约束简介
java·数据库·sql
计算机安禾25 分钟前
【数据库系统原理】第4篇:关系数据结构的形式化定义:域、笛卡尔积与关系模式
数据结构·数据库·算法
Henry-SAP26 分钟前
SAP(ERP) BOM变更实时同步MRP方案
数据库·云原生
AI人工智能+电脑小能手27 分钟前
【大白话说Java面试题 第99题】【Mysql篇】第29题:如何选择合适的分布式主键方案?
java·数据库·分布式·mysql·面试
极光代码工作室32 分钟前
基于SpringBoot的任务管理系统
java·springboot·web开发·后端开发
人道领域1 小时前
【LeetCode刷题日记】131.分割回文串,动态规划优化
java·开发语言·leetcode