Presto/Trino的explain和system catalog的使用、各种数据类型(基础、集合、日期时间)

1. explain

查看查询执行计划,简单例子是检查查询在语法上是否正确

trino>
trino> explain (type validate) select name from tpch.tiny.region;
 Valid 
-------
 true  
(1 row)

Query 20220106_183905_00013_b26ia, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.26 [0 rows, 0B] [0 rows/s, 0B/s]

trino> 

2. system catalog

2.1 system.runtime数据库

trino>
trino> show tables from system.runtime;
        Table         
----------------------
 nodes                
 optimizer_rule_stats 
 queries              
 tasks                
 transactions         
(5 rows)

Query 20220106_184602_00014_b26ia, FINISHED, 3 nodes
Splits: 6 total, 6 done (100.00%)
0.82 [5 rows, 134B] [6 rows/s, 164B/s]

trino> 
  • 查看queries和tasks表对性能优化最重要。queries表提供了当前和历史查询。tasks表则提供了task运行时的底层细节

可以使用下面的方法,来终结某个查询

trino>
trino> call system.runtime.kill_query(query_id  => '20220106_185627_00018_b26ia', message => 'killed');
CALL
trino>
  • nodes表可以查看集群中的节点信息

2.2 system.information_schema数据库

每个catalog都有自己的information_schema数据库,其中的表是基于视图实现的

每个information_schema数据库都有9个视图,如果某个连接器不支持某个功能,查询对应的视图会报错

trino>
trino> show tables from system.information_schema;
             Table              
--------------------------------
 applicable_roles               
 columns                        
 enabled_roles                  
 role_authorization_descriptors 
 roles                          
 schemata                       
 table_privileges               
 tables                         
 views                          
(9 rows)

Query 20220107_031226_00015_b26ia, FINISHED, 3 nodes
Splits: 6 total, 6 done (100.00%)
0.34 [9 rows, 358B] [26 rows/s, 1.04KB/s]

trino>

3. 数据类型

Trino中的数据类型不是所有的连接器都支持,数据源中的数据类型可能Trino也不支持

可以使用cast (value as data_type)try_cast(value as data_type)进行数据类型转换,但try_cast转换失败则返回NULL

3.1 基础数据类型

  1. 布尔类型
类型描述示例
booleantrue或falsetrue
  1. 整数类型
类型描述示例
tinyint8位有符号整数,最小值 − 2 7 -2^7 27,最大值 2 7 − 1 2^{7-1} 27142
smallint16位有符号整数,最小值 − 2 15 -2^{15} 215,最大值 2 15 − 1 2^{15-1} 215142
integer、int32位有符号整数,最小值 − 2 31 -2^{31} 231,最大值 2 31 − 1 2^{31-1} 231142
bigint64位有符号整数,最小值 − 2 63 -2^{63} 263,最大值 2 63 − 1 2^{63-1} 263142
  1. 浮点数类型
类型描述示例
real32位浮点数,遵循IEEE 754二进制浮点数运算标准2.71828
double64位浮点数,遵循IEEE 754二进制浮点数运算标准2.71828
decimal固定精度小数123456.7890
  1. 字符串类型
类型描述示例
varchar、varchar(n)可变长度字符串。字符长度为m(m < n),则分配m个字符“hello world”
char、char(n)固定长度字符串。总是分配n个字符,不管字符长度是多少。char表示char(1)“hello world”
  • 当字符串cast为char(n),不足的字符用空格填充,多的字符被截断
  • 当插入字符串到类型为char(n)的列,不足的字符用空格填充,多了就报错
  • 当插入字符串到类型为varchar(n)的列,多了就报错
trino> 
trino> select length(cast('hello world' as char(100)));
 _col0 
-------
   100 
(1 row)

Query 20220108_132257_00002_b26ia, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.29 [0 rows, 0B] [0 rows/s, 0B/s]

trino> 

下面的应该是一个bug,结果应该为false

trino>
trino> select cast('hello world' as char(14)) = cast('hello world' as char(15));
 _col0 
-------
 true  
(1 row)

Query 20220108_133452_00040_b26ia, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.23 [0 rows, 0B] [0 rows/s, 0B/s]

trino>

3.2 集合数据类型

类型示例
arrayarray[‘apples’, ‘oranges’, ‘pears’]
mapmap(array[‘a’, ‘b’, ‘c’], array[1, 2, 3])
json{‘a’:1, ‘b’:2, ‘c’:3}
rowrow(1, 2, 3)

3.3 日期时间数据类型

类型描述示例
date包含年、月、日的日期2022-01-10
time包含时、分、秒、毫秒的时间, 时区可选16:26:08.123 +08:00
timestamp包含日期和时间, 时区可选2022-01-10 16:26:08.123 Asia/Shanghai
interval year to month间隔时间跨度为年、月interval ‘1-2’ year to month
interval day to second间隔时间跨度为天、时、分、秒、毫秒interval ‘5’ day to second

查询示例如下:

trino> 
trino> select timestamp '2022-01-10 16:26:08.123 Asia/Shanghai';
                 _col0                 
---------------------------------------
 2022-01-10 16:26:08.123 Asia/Shanghai 
(1 row)

Query 20220109_020002_00037_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.51 [0 rows, 0B] [0 rows/s, 0B/s]

trino> 
trino> 
trino> select to_unixtime(timestamp '2022-01-10 16:26:08.123 Asia/Shanghai');
      _col0       
------------------
 1.641803168123E9 
(1 row)

Query 20220209_233903_00154_jx84g, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.25 [0 rows, 0B] [0 rows/s, 0B/s]

trino>
trino> select interval '2-3' year to month;
 _col0 
-------
 2-3   
(1 row)

Query 20220109_021402_00055_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.74 [0 rows, 0B] [0 rows/s, 0B/s]

trino> 
trino> select interval '2' year;
 _col0 
-------
 2-0   
(1 row)

Query 20220109_021900_00057_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.53 [0 rows, 0B] [0 rows/s, 0B/s]

trino>
trino> select interval '3' month;
 _col0 
-------
 0-3   
(1 row)

Query 20220109_021911_00058_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.33 [0 rows, 0B] [0 rows/s, 0B/s]

trino>
trino> select interval '2 08:06:18.888' day to second;
     _col0      
----------------
 2 08:06:18.888 
(1 row)

Query 20220109_021501_00056_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.39 [0 rows, 0B] [0 rows/s, 0B/s]

trino> 
trino> select interval '2' day;
     _col0      
----------------
 2 00:00:00.000 
(1 row)

Query 20220109_021928_00059_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.45 [0 rows, 0B] [0 rows/s, 0B/s]

trino>
trino> select interval '08' hour;
     _col0      
----------------
 0 08:00:00.000 
(1 row)

Query 20220109_021946_00060_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.34 [0 rows, 0B] [0 rows/s, 0B/s]

trino>
trino> select interval '06' minute;
     _col0      
----------------
 0 00:06:00.000 
(1 row)

Query 20220109_022007_00061_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.33 [0 rows, 0B] [0 rows/s, 0B/s]

trino>
trino> select interval '18.888' second;
     _col0      
----------------
 0 00:00:18.888 
(1 row)

Query 20220109_022019_00062_jiymz, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.31 [0 rows, 0B] [0 rows/s, 0B/s]

trino>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
impala是一种高性能分析数据库,它基于Hadoop生态系统,可以快速执行复杂的查询。它使用列式存储、编译器技术和并行查询执行来实现高性能。 druid是一个快速、实时的数据存储和分析引擎,它适用于大规模的实时数据处理和探索式分析。它支持实时数据摄取、查询和可视化,可用于数据仪表盘和实时报告等应用。 presto是一种开源的分布式SQL查询引擎,它可以快速查询多种数据源,包括Hadoop、MySQL等。它具有高度可伸缩性和灵活性,可用于快速进行复杂的数据分析和联机查询。 kylin是一种开源的分布式分析引擎,它可以快速处理大规模数据集。它支持多维分析和复杂的OLAP查询,并提供了数据立方体和预计算功能,用于加速查询速度。 clickhouse是一种列式数据库管理系统,专门用于高性能分析应用。它支持实时查询和高并发访问,并具有低延迟和高容量的优势,适用于大规模的数据分析和数据仪表盘等应用。 greenplum是一种高性能的并行关系数据库管理系统,适用于大规模数据仓库和分析应用。它具有高度可伸缩性、并行查询和优化的特性,用于高速查询和处理大规模数据。 总的来说,这些数据库和查询引擎都旨在提供高性能和灵活性,以满足大规模数据分析和查询的需求,但它们在技术架构、数据存储方式和查询优化等方面存在一些差异。选择适合特定需求的数据库和查询引擎取决于实际情况和使用场景。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值