# Frog
本项目为示例程序,还有很多需要完善的地方。
## 使用
转换、清洗开发主要分为 3 部分:
1. 定义数据源,即后续操作的基础数据源;
2. 定义清洗逻辑,即基于基础数据的处理,得到我们需要的结果;
3. 定义数据持久化,即我们最终的结果数据存储持久化。
## 转换清洗开发示例 - transform.xml
```xml
<?xml version="1.0" encoding="UTF-8"?>
<logic>
<!-- 替换参数定义,可用于后面开发进行简单参数化定义 -->
<parameters>
<parameter name="path" value="/Users/mars/Desktop/Data/tools" />
<parameter name="path1" value="file:///Users/mars/Desktop/Data/bank/bank/people" />
<parameter name="path2" value="file:///Users/mars/Desktop/Data/bank/bank/people_append" />
<parameter name="path3" value="file:///Users/mars/Desktop/Data/bank/bank/people_out1" />
<parameter name="path4" value="file:///Users/mars/Desktop/Data/bank/bank/people_out2" />
<parameter name="path5" value="file:///Users/mars/Desktop/Data/bank/bank/people_out3" />
</parameters>
<base>
<!-- ${path}: 上述paramters定义的替换参数 -->
<logPath>${path}/logs</logPath>
<metaPath>${path}/metapath</metaPath>
<tempPath>${path}/tmp</tempPath>
<schemaPath>${path}/schemapath</schemaPath>
<database>test</database>
</base>
<!-- 用于后续转换、清洗等操作的基础数据 -->
<sources>
<source tableName="people1" type="parquet" partitions="1" cache="true" dataPath="${path1}"/>
<source tableName="people2" type="parquet" partitions="1" cache="true" dataPath="${path2}"/>
</sources>
<!-- 基于 sources 中定义的基础数据进行的转换、清洗操作;
支持向上依赖 -->
<transforms>
<transform tableName="people_t" cache="true" save="true" type="sql">
<![CDATA[
select job, day, age, education from people1
union all
select job, day, age, education from people2
]]>
</transform>
<transform tableName="people_t2" cache="true" save="true" type="sql">
<![CDATA[
select job, day, age, education from people1
union all
select job, day, age, education from people2
union all
select job, day, age, education from people_t
]]>
</transform>
<transform tableName="people_t3" cache="true" save="true" type="sql">
<![CDATA[
select job, day, age, education from people1
union all
select job, day, age, education from people_t2
]]>
</transform>
</transforms>
<!-- 基于基础数据转换、清洗完成后,需要最终落地的数据 -->
<sinks>
<sink tableName="people_t" type="parquet" saveMode="overwrite" savePath="${path3}"/>
<sink tableName="people_t2" type="txt" partitions="1" delimiter=" || " saveMode="overwrite" savePath="${path4}"/>
<sink tableName="people_t3" type="txt" coalesce="2" delimiter=" || " saveMode="overwrite" savePath="${path5}"/>
</sinks>
</logic>
```
### 数据源定义
部分参数说明:
**tableName:** 数据源读取后在 Spark-SQL 中的注册表名
**type:** 数据源的类别,csv、txt、parquet等
**partitions:** 数据读取后重新分区的数量
**cache:** 是否缓存表
**dataPath:** 数据存放路径,默认使用 HDFS 路径
**schemaPath:** 当数据源为 txt 类的文本文件时,需要指定数据的 schema,比如:列分隔符、列名、列值类型等定义
```xml
<!-- 用于后续转换、清洗等操作的基础数据 -->
<sources>
<source tableName="people1" type="csv" partitions="1" cache="true" dataPath="${path1}" schemaPath="/path/to/people.meta"/>
<source tableName="people2" type="parquet" partitions="1" cache="true" dataPath="${path2}"/>
</sources>
```
**people.meta**
> 文本类数据源的结构映射定义,主要定义有数据的编码格式、列分隔符、每列的列名、列值类型等
```xml
<?xml version="1.0" encoding="UTF-8"?>
<source charset="UTF-8" delimiter="\|\|" isHeaderFirst="true">
<columns>
<column type="STRING" nullable="true" index="1"> age </column>
<column type="STRING" nullable="true" index="2"> job </column>
<column type="STRING" nullable="true" index="3"> marital </column>
<column type="STRING" nullable="true" index="4"> education </column>
<column type="STRING" nullable="true" index="5"> default </column>
<column type="STRING" nullable="true" index="6"> balance </column>
<column type="STRING" nullable="true" index="7"> housing </column>
<column type="STRING" nullable="true" index="8"> loan </column>
<column type="STRING" nullable="true" index="9"> contact </column>
<column type="STRING" nullable="true" index="10"> day </column>
<column type="STRING" nullable="true" index="11"> month </column>
<column type="STRING" nullable="true" index="12"> duration </column>
<column type="STRING" nullable="true" index="13"> campaign </column>
<column type="STRING" nullable="true" index="14"> pdays </column>
<column type="STRING" nullable="true" index="15"> previous </column>
<column type="STRING" nullable="true" index="16"> poutcome </column>
<column type="STRING" nullable="true" index="17"> y </column>
</columns>
</source>
```
### 清洗定义
> 基于上面来源数据表定义,进行我们期望的数据转换、清洗操作。
部分参数说明:
**tableName:** SQL执行完成后的数据注册成的表名
**cache:** 是否缓存表
**save:** 是否对此中间表存储
**type**: 当前只支持sql
```xml
<!-- 基于 sources 中定义的基础数据进行的转换、清洗操作;
支持向上依赖 -->
<transforms>
<transform tableName="people_t" cache="true" save="true" type="sql">
<![CDATA[
select job, day, age, education from people1
union all
select job, day, age, education from people2
]]>
</transform>
<transform tableName="people_t2" cache="true" save="true" type="sql">
<![CDATA[
select job, day, age, education from people1
union all
select job, day, age, education from people2
union all
select job, day, age, education from people_t
]]>
</transform>
<transform tableName="people_t3" cache="true" save="true" type="sql">
<![CDATA[
select job, day, age, education from people1
union all
select job, day, age, education from people_t2
]]>
</transform>
</transforms>
```
### 数据持久化
> 对于基于 sources 层和 transforms 层得到的表中最终需要持久化的表进行持久化操作,也就是整个逻辑的结果持久化。
部分参数说明:
**tableName:** sources和transforms中需要持久化的表
**type:** 持久化时数据类型,csv、txt、parquet 等
**saveMode:** 持久化动作,append、overwrite 等
**partitions:** 分区数,即生成的文件数
**partitionBy:** 分区字段
```xml
<!-- 基于基础数据转换、清洗完成后,需要最终落地的数据 -->
<sinks>
<sink tableName="people_t" type="parquet" saveMode="overwrite" savePath="${path3}"/>
<sink tableName="people_t2" type="txt" partitions="1" delimiter=" || " saveMode="overwrite" savePath="${path4}"/>
<sink tableName="people_t3" type="txt" coalesce="2" delimiter=" || " saveMode="overwrite" savePath="${path5}"/>
</sinks>
```
### 执行
通过 spark-submit 执行进行提交即可
```shell
spark-submit \
--jars ... \
--class com.moon.Run frog.jar \
--transform-file ./transform.xml
```
## 开发待完善
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1、资源内容:Scala实现的基于熟悉的XML与SQL实现快速开发基于Spark的大数据ETL程序+源代码+文档说明 2、代码特点:内含运行结果,不会运行可私信,参数化编程、参数可方便更改、代码编程思路清晰、注释明细,都经过测试运行成功,功能ok的情况下才上传的。 3、适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 4、作者介绍:某大厂资深算法工程师,从事Matlab、Python、C/C++、Java、YOLO算法仿真工作10年;擅长计算机视觉、 目标检测模型、智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、智能控制、路径规划、无人机等多种领域的算法仿真实验,更多源码,请上博主主页搜索。 -------------------------------------------------------------------------- -
资源推荐
资源详情
资源评论
收起资源包目录
foxifrog-master.zip (27个子文件)
foxifrog-master
pom.xml 2KB
src
main
resources
chains.xml 799B
transform.xml 2KB
people.meta 1KB
scala
com
moon
validate
ArgumentsCheck.scala 2KB
tools
GenerateMetaInfo.scala 7KB
foxi
CasesType.scala 682B
cache
CacheManage.scala 3KB
core
Frog.scala 12KB
impl
FrogImpl.scala 23KB
FrogToTravel.scala 9KB
utils
DataFrameUtil.scala 607B
FileUtil.scala 970B
spark
SystemType.scala 137B
SparkDemo.scala 3KB
BaseInfo.scala 63B
Run.scala 1KB
parser
ChainsFileParser.scala 2KB
TransformFileParser.scala 8KB
SchemaFileParser.scala 3KB
StructTypeParser.scala 474B
models
RunStructType.scala 127B
TransformInfo.scala 5KB
SchemaInfo.scala 805B
Chain.scala 813B
.gitignore 75B
README.md 8KB
共 27 条
- 1
资源评论
机器学习的喵
- 粉丝: 486
- 资源: 1252
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
- Surfer,线性函数
- MyBatis 的动态 SQL 是其核心特性之一.txt
- 时代的sdddsddsddsd
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功