本文共 4290 字,大约阅读时间需要 14 分钟。
\\\看新闻很累?看技术新闻更累?试试,每天上下班路上听新闻,有趣还有料!
\
CarbonData是一种新的高性能数据存储格式,已在20+企业生产环境上部署和使应用,企业数据规模达到万亿。针对当前大数据领域分析场景需求各异而导致的存储冗余问题,业务驱动下的数据分析灵活性要求越来越高,CarbonData提供了一种新的融合数据存储方案,以一份数据同时支持多种应用场景,并通过多级索引、字典编码、预聚合、动态Partition、准实时数据查询、列存等特性提升了IO扫描和计算性能,实现百亿数据级秒级响应。
\\我们来看下,CarbonData 1.3.0有哪些重大特性:
\\1. 支持与Spark 2.2.1集成
\\CarbonData 1.3.0支持与最新稳定的Spark 2.2.1版本集成。
\\2. 支持预聚合表特性
\\在1.3.0中,CarbonData的预聚合特性,与传统BI系统的CUBE方案最大区别是,用户不需要改任何SQL语句,既可加速group by的统计性能,又可查询明细数据,做到一份数据满足多种应用场景。具体的用法如下:
\\a) 创建主表:
\\\CREATE TABLE sales (\order_time TIMESTAMP,\user_id STRING,\sex STRING,\country STRING,\quantity INT,\price BIGINT)\STORED BY 'carbondata'\\
b) 基于上面主表sales创建预聚合表:
\\\CREATE DATAMAP agg_sales\ON TABLE sales\USING \"preaggregate\"\AS\SELECT country, sex, sum(quantity), avg(price)\FROM sales\GROUP BY country, sex\\\
c) 用户不需要改SQL语句,基于主表sales的查询语句如命中预聚合表agg_sales,可以显著提升查询性能:
\\\SELECT country, sex, sum(quantity), avg(price) FROM sales GROUP BY country, sex;// 命中,完全和聚合表一样\\SELECT sex, sum(quantity) FROM sales GROUP BY sex;//命中,聚合表的部分查询\\SELECT country, avg(price) FROM sales GROUP BY country;//命中,聚合表的部分查询\\SELECT country, sum(price) FROM sales GROUP BY country;//命中,因为聚合表里avg(price)是通过sum(price)/count(price)产生,所以sum(price)也命中\\SELECT sex, avg(quantity) FROM sales GROUP BY sex; //没命中,需要创建新的预聚合表\\SELECT max(price), country FROM sales GROUP BY country;//没命中,需要创建新的预聚合表\\SELECT user_id, country, sex, sum(quantity), avg(price) FROM sales GROUP BY user_id, country, sex; //没命中,需要创建新的预聚合表\\\
d) 在3.0版本中,支持的预聚合表达式有:SUM、AVG、MAX、MIN、COUNT
\\e) 实测性能可提升10+倍以上,大家可以参考例子,把测试数据调到1亿规模以上,跑下这个例子:/apache/carbondata/examples/PreAggregateTableExample.scala
\\ \\3. 支持时间维度的预聚合特性,并支持自动上卷
\\此特性为Alpha特性,当前时间粒度支持设置为1,比如:支持按1天聚合,暂不支持指定3天,5天的粒度进行聚合,下个版本将支持。支持自动上卷(Year,Month,Day,Hour,Minute),具体用法如下:
\\a) 创建主表:
\\\CREATE TABLE sales (\order_time TIMESTAMP,\user_id STRING,\sex STRING,\country STRING,\quantity INT,\price BIGINT)\STORED BY 'carbondata'\\
b) 分别创建Year、Month、Day、Hour、Minute粒度的聚合表:
\\\CREATE DATAMAP agg_year\ON TABLE sales\USING \"timeseries\"\DMPROPERTIES (\'event_time’=’order_time’,\'year_granualrity’=’1’,\) AS\SELECT order_time, country, sex, sum(quantity), max(quantity), count(user_id), sum(price),\ avg(price) FROM sales GROUP BY order_time, country, sex\\CREATE DATAMAP agg_month\ON TABLE sales\USING \"timeseries\"\DMPROPERTIES (\'event_time’=’order_time’,\'month_granualrity’=’1’,\) AS\SELECT order_time, country, sex, sum(quantity), max(quantity), count(user_id), sum(price),\ avg(price) FROM sales GROUP BY order_time, country, sex\\CREATE DATAMAP agg_day\ ON TABLE sales\ USING \"timeseries\"\ DMPROPERTIES (\ 'event_time’=’order_time’,\ 'day_granualrity’=’1’, //当前粒度只支持设置为1,\ ) AS\ SELECT order_time, country, sex, sum(quantity), max(quantity), count(user_id), sum(price),\ avg(price) FROM sales GROUP BY order_time, country, sex\\CREATE DATAMAP agg_sales_hour\ON TABLE sales\USING \"timeseries\"\DMPROPERTIES (\'event_time’=’order_time’,\'hour_granualrity’=’1’,\) AS\SELECT order_time, country, sex, sum(quantity), max(quantity), count(user_id), sum(price),\ avg(price) FROM sales GROUP BY order_time, country, sex\\CREATE DATAMAP agg_minute\ON TABLE sales\USING \"timeseries\"\DMPROPERTIES (\'event_time’=’order_time’,\'minute_granualrity’=’1’,\) AS\SELECT order_time, country, sex, sum(quantity), max(quantity), count(user_id), sum(price),\ avg(price) FROM sales GROUP BY order_time, country, sex\\\
c) 用户可不用创建所有时间粒度的聚合表,系统支持自动roll-up上卷,如:已创建了Day粒度的聚合表,当查询Year、Month粒度的group by聚合时,系统会基于已聚合好的Day粒度值推算出Year、Month粒度的聚合值:
\\\CREATE DATAMAP agg_day\ ON TABLE sales\ USING \"timeseries\"\ DMPROPERTIES (\ 'event_time’=’order_time’,\ 'day_granualrity’=’1’,\ ) AS\ SELECT order_time, country, sex, sum(quantity), max(quantity), count(user_id), sum(price),\ avg(price) FROM sales GROUP BY order_time, country, sex\\
(Year、Month粒度的聚合查询,可用上面创建的agg_day上卷)
\\\SELECT timeseries(order_time, ‘month’), sum(quantity) FROM sales group by timeseries(order_time,\ ’month’)\SELECT timeseries(order_time, ‘year’), sum(quantity) FROM sales group by timeseries(order_time,\ ’year’)\\
4. 支持实时入库,准实时查询
\\在1.3.0中,支持通过Structured Streaming实时导入数据到CarbonData表,并立即可查询这些fresh数据。
\\a) 实时获取数据:
\\\val readSocketDF = spark.readStream\ .format(\"socket\")\ .option(\"host\
转载地址:http://imtax.baihongyu.com/