大数据-159 Apache Kylin 构建Cube 准备和测试数据(二)

本文涉及的产品
云原生大数据计算服务 MaxCompute,5000CU*H 100GB 3个月
云原生大数据计算服务MaxCompute,500CU*H 100GB 3个月
简介: 大数据-159 Apache Kylin 构建Cube 准备和测试数据(二)

接上篇:https://developer.aliyun.com/article/1623254?spm=a2c6h.13148508.setting.18.66e24f0etlssu8

dim_product_data

# 设置参数
output_file = 'dim_product_data.txt'

# 定义产品ID和产品名称
products = [
    ('P001', 'Smartphone'),
    ('P002', 'Laptop'),
    ('P003', 'Tablet'),
    ('P004', 'Smartwatch'),
    ('P005', 'Camera'),
    ('P006', 'Headphones'),
    ('P007', 'Monitor'),
    ('P008', 'Keyboard'),
    ('P009', 'Mouse'),
    ('P010', 'Printer')
]

# 生成数据
with open(output_file, 'w') as f:
    for product_id, product_name in products:
        line = f"{product_id},{product_name}\n"
        f.write(line)

print(f"Product data has been written to {output_file}")

生成数据如下图所示:

dim_region_data

# 设置参数
output_file = 'dim_region_data.txt'

# 定义区域ID和区域名称
regions = [
    ('R001', 'North America'),
    ('R002', 'Europe'),
    ('R003', 'Asia'),
    ('R004', 'South America'),
    ('R005', 'Africa'),
    ('R006', 'Australia'),
    ('R007', 'Antarctica')
]

# 生成数据
with open(output_file, 'w') as f:
    for region_id, region_name in regions:
        line = f"{region_id},{region_name}\n"
        f.write(line)

print(f"Region data has been written to {output_file}")

生成的数据如下图所示:

kylin_examples.sql

-- 创建订单数据库、表结构
create database if not exists `wzk_kylin`;
-- 1、销售表:dw_sales
-- id 唯一标识
-- date1 日期
-- channelId 渠道ID
-- productId 产品ID
-- regionId 区域ID
-- amount 数量
-- price 金额
create table wzk_kylin.dw_sales(
  id string,
  date1 string,
  channelId string,
  productId string,
  regionId string,
  amount int,
  price double
)ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
-- 2、渠道表:dim_channel
-- channelId 渠道ID
-- channelName 渠道名称
create table wzk_kylin.dim_channel(
  channelId string,
  channelName string
)ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
-- 3、产品表:dim_product
create table wzk_kylin.dim_product(
  productId string,
  productName string
)ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
--4、区域表:dim_region
create table wzk_kylin.dim_region(
  regionId string,
  regionName string
)ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

-- 导入数据
LOAD DATA LOCAL INPATH '/opt/wzk/kylin_test/dw_sales_data.txt'
OVERWRITE INTO TABLE wzk_kylin.dw_sales;
LOAD DATA LOCAL INPATH '/opt/wzk/kylin_test/dim_channel_data.txt'
OVERWRITE INTO TABLE wzk_kylin.dim_channel;
LOAD DATA LOCAL INPATH '/opt/wzk/kylin_test/dim_product_data.txt'
OVERWRITE INTO TABLE wzk_kylin.dim_product;
LOAD DATA LOCAL INPATH '/opt/wzk/kylin_test/dim_region_data.txt'
OVERWRITE INTO TABLE wzk_kylin.dim_region;

运行数据

我们需要把刚才的数据上传到指定目录上,/opt/wzk/目录下。

cd /opt/wzk/kylin_test
• 1

我已经上传到服务器上了:

SQL文件也记得上传上去

执行Hive:

hive -f kylin_examples.sql
• 1

执行结果如下图所示:

测试数据

我们需要启动Hive

hive
• 1

执行结果如下图所示:

执行如下的指令:

use wzk_kylin;
select date1, sum(price) as total_money, sum(amount) as
total_amount
from dw_sales
group by date1;

执行结果如下图所示:

相关实践学习
基于MaxCompute的热门话题分析
本实验围绕社交用户发布的文章做了详尽的分析,通过分析能得到用户群体年龄分布,性别分布,地理位置分布,以及热门话题的热度。
SaaS 模式云数据仓库必修课
本课程由阿里云开发者社区和阿里云大数据团队共同出品,是SaaS模式云原生数据仓库领导者MaxCompute核心课程。本课程由阿里云资深产品和技术专家们从概念到方法,从场景到实践,体系化的将阿里巴巴飞天大数据平台10多年的经过验证的方法与实践深入浅出的讲给开发者们。帮助大数据开发者快速了解并掌握SaaS模式的云原生的数据仓库,助力开发者学习了解先进的技术栈,并能在实际业务中敏捷的进行大数据分析,赋能企业业务。 通过本课程可以了解SaaS模式云原生数据仓库领导者MaxCompute核心功能及典型适用场景,可应用MaxCompute实现数仓搭建,快速进行大数据分析。适合大数据工程师、大数据分析师 大量数据需要处理、存储和管理,需要搭建数据仓库?学它! 没有足够人员和经验来运维大数据平台,不想自建IDC买机器,需要免运维的大数据平台?会SQL就等于会大数据?学它! 想知道大数据用得对不对,想用更少的钱得到持续演进的数仓能力?获得极致弹性的计算资源和更好的性能,以及持续保护数据安全的生产环境?学它! 想要获得灵活的分析能力,快速洞察数据规律特征?想要兼得数据湖的灵活性与数据仓库的成长性?学它! 出品人:阿里云大数据产品及研发团队专家 产品 MaxCompute 官网 https://www.aliyun.com/product/odps 
相关文章
|
3天前
|
消息中间件 分布式计算 大数据
大数据-166 Apache Kylin Cube 流式构建 整体流程详细记录
大数据-166 Apache Kylin Cube 流式构建 整体流程详细记录
18 5
|
3天前
|
存储 SQL 分布式计算
大数据-162 Apache Kylin 全量增量Cube的构建 Segment 超详细记录 多图
大数据-162 Apache Kylin 全量增量Cube的构建 Segment 超详细记录 多图
12 3
|
3天前
|
Java 大数据 数据库连接
大数据-163 Apache Kylin 全量增量Cube的构建 手动触发合并 JDBC 操作 Scala
大数据-163 Apache Kylin 全量增量Cube的构建 手动触发合并 JDBC 操作 Scala
9 2
大数据-163 Apache Kylin 全量增量Cube的构建 手动触发合并 JDBC 操作 Scala
|
3天前
|
SQL 分布式计算 NoSQL
大数据-164 Apache Kylin Cube优化 案例1 定义衍生维度与对比 超详细
大数据-164 Apache Kylin Cube优化 案例1 定义衍生维度与对比 超详细
7 1
大数据-164 Apache Kylin Cube优化 案例1 定义衍生维度与对比 超详细
|
3天前
|
SQL 分布式计算 NoSQL
大数据-170 Elasticsearch 云服务器三节点集群搭建 测试运行
大数据-170 Elasticsearch 云服务器三节点集群搭建 测试运行
15 4
|
3天前
|
运维 监控 数据可视化
大数据-171 Elasticsearch ES-Head 与 Kibana 配置 使用 测试
大数据-171 Elasticsearch ES-Head 与 Kibana 配置 使用 测试
10 1
|
3天前
|
存储 大数据 分布式数据库
大数据-165 Apache Kylin Cube优化 案例 2 定义衍生维度及对比 & 聚合组 & RowKeys
大数据-165 Apache Kylin Cube优化 案例 2 定义衍生维度及对比 & 聚合组 & RowKeys
9 1
|
2月前
|
存储 消息中间件 Java
Apache Flink 实践问题之原生TM UI日志问题如何解决
Apache Flink 实践问题之原生TM UI日志问题如何解决
41 1
|
1月前
|
SQL 消息中间件 关系型数据库
Apache Doris Flink Connector 24.0.0 版本正式发布
该版本新增了对 Flink 1.20 的支持,并支持通过 Arrow Flight SQL 高速读取 Doris 中数据。
|
2月前
|
消息中间件 监控 数据挖掘
基于RabbitMQ与Apache Flink构建实时分析系统
【8月更文第28天】本文将介绍如何利用RabbitMQ作为数据源,结合Apache Flink进行实时数据分析。我们将构建一个简单的实时分析系统,该系统能够接收来自不同来源的数据,对数据进行实时处理,并将结果输出到另一个队列或存储系统中。
132 2

推荐镜像

更多