- Doris-常用脚本
- 前言
- 1.建表模板
- 2.调度脚本设置
- 3.行转列
- 4.加载HDFS数据
- 查看任务进度
- 5.获取数据字典并导出Excel
- 总结
这里是记录经常使用的一些脚本
1.建表模板
--*******************************************************************
-- 业务主题:
-- 创 建 人:
-- 创建日期: 2022-04-22
-- 脚本用途:
-- 执行引擎: doris
-- 执行周期: 天
-- 目 标 表: dws.
-- 变更记录:
-- 变更日期 变更人 变更描述
--*******************************************************************
CREATE TABLE dbname.tablename(
ts date comment '{"type"="0","comment"="分区字段"}'
,pick_code varchar(50) comment '{"type"="0","comment"="xxid"}'
PARTITION p20220429 VALUES [('2022-04-29'), ('2022-04-30')))
DISTRIBUTED BY HASH(`pick_store_code`) BUCKETS 2
PROPERTIES (
"replication_num" = "3",
"dynamic_partition.enable" = "true",
"dynamic_partition.time_unit" = "DAY",
"dynamic_partition.time_zone" = "UTC",
"dynamic_partition.start" = "-2147483648",
"dynamic_partition.end" = "3",
"dynamic_partition.prefix" = "p",
"dynamic_partition.buckets" = "2",
"in_memory" = "false",
"storage_format" = "DEFAULT"
);
2.调度脚本设置
set time_zone='Asia/Shanghai'; set query_timeout=1000; SET exec_mem_limit=20000000000;3.行转列
,group_concat(if(status=10,operate_time ,'') ,'') as wait_pay_time ,group_concat(if(status=20,operate_time,'') ,'') as paying_time ,group_concat(if(status=30,operate_time,'') ,'') as failed_pay_time ,group_concat(if(status=40,operate_time,'') ,'') as success_pay_time4.加载HDFS数据
LOAD LABEL 任务名称
(
DATA INFILE("hdfs://文件路径/ts=2022-05-23/*")
INTO TABLE 表名
format as "orc"
(
`field1`,`field2`,`field3`
)
COLUMNS FROM PATH AS (`ts`)
SET(ts=ts)
)
WITH BROKER hdfs_broker
(
"hadoop.security.authentication" = "kerberos",
"kerberos_principal" = "",
"kerberos_keytab" = "",
"dfs.nameservices" = "",
"dfs.ha.namenodes.cnprod1ha" = "nn1,nn2",
"dfs.namenode.rpc-address.cnprod1ha.nn1" = "",
"dfs.namenode.rpc-address.cnprod1ha.nn2" = "",
"dfs.client.failover.proxy.provider.cnprod1ha" = "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider"
)
PROPERTIES
(
"timezone" = "UTC"
)
查看任务进度
show load where label='任务名称'5.获取数据字典并导出Excel
MAVEN配制
mysql mysql-connector-java 5.1.49 org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-starter-jdbc com.alibaba easyexcel 3.1.0
MAIN
package com.example.ds.controller;
import com.alibaba.excel.EasyExcel;
import com.example.ds.bean.DSBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class DSCtroller implements CommandLineRunner {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public void run(String... args) throws Exception {
ArrayList dsBeans = new ArrayList<>();
List
BEAN
public class DSBean {
@ExcelProperty(value = "表名称")
private String tableName;
@ExcelProperty(value = "库名称")
private String tableSchema;
@ExcelProperty(value = "字段名称")
private String columnName;
@ExcelProperty(value = "字段类型")
private String dataType;
@ExcelProperty(value = "注释")
private String ColumnComment;
application.yml配制
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false spring.datasource.username= spring.datasource.password= spring.datasource.driver-class-name=com.mysql.jdbc.Driver总结



