浏览代码

添加导入,清理mysql脚本

wudianlong 2 年之前
父节点
当前提交
e8184937ec
共有 4 个文件被更改,包括 85 次插入2 次删除
  1. 11 0
      energy/clean_mysql.sh
  2. 2 2
      energy/energy_hive.sql
  3. 43 0
      energy/energy_mysql.sql
  4. 29 0
      energy/mysql_to_hdfs.sh

+ 11 - 0
energy/clean_mysql.sh

@@ -0,0 +1,11 @@
+#! /bin/bash
+
+. ./config.sh
+
+url=$MYSQL_URL
+username=$MYSQL_USER
+password=$MYSQL_PASSWORD
+
+export_tmp_station_detail(){
+mysql -h${url}  -P3306  -u${username} -p${password} ${result_database} -e  "${del_rebate_company_station}"
+}

+ 2 - 2
energy/energy_hive.sql

@@ -1,4 +1,4 @@
-/** 能源原始数据15min历史数据 */
+/** 能源原始数据 15min 历史数据 */
 create table ods_energy_15_min_history
 create table ods_energy_15_min_history
 (
 (
     building   string,
     building   string,
@@ -16,7 +16,7 @@ create table ods_energy_15_min_history
     TBLPROPERTIES (
     TBLPROPERTIES (
         'orc.compress'='lzo');
         'orc.compress'='lzo');
 
 
-/** 能源原始数据15min历史数据 */
+/** 能源原始数据 5min 历史数据 */
 create table ods_energy_5_min_history
 create table ods_energy_5_min_history
 (
 (
     building   string,
     building   string,

+ 43 - 0
energy/energy_mysql.sql

@@ -0,0 +1,43 @@
+/** 能源 15 分钟数据-历史 */
+create table energy_15_min_history
+(
+    building   varchar(128)    null,
+    func_id    varchar(128)    null,
+    meter      varchar(128)    null,
+    data_time  datetime        null,
+    data_value decimal(20, 15) null,
+    dt         varchar(64)     null
+);
+
+/** 能源 15 分钟数据 */
+create table energy_15_min
+(
+    building   varchar(128)    null,
+    func_id    varchar(128)    null,
+    meter      varchar(128)    null,
+    data_time  datetime        null,
+    data_value decimal(20, 15) null,
+    dt         varchar(64)     null
+);
+
+/** 能源 5 分钟数据-历史 */
+create table energy_5_min_history
+(
+    building   varchar(128)    null,
+    func_id    varchar(128)    null,
+    meter      varchar(128)    null,
+    data_time  datetime        null,
+    data_value decimal(20, 15) null,
+    dt         varchar(64)     null
+);
+
+/** 能源 5 分钟数据 */
+create table energy_5_min
+(
+    building   varchar(128)    null,
+    func_id    varchar(128)    null,
+    meter      varchar(128)    null,
+    data_time  datetime        null,
+    data_value decimal(20, 15) null,
+    dt         varchar(64)     null
+);

+ 29 - 0
energy/mysql_to_hdfs.sh

@@ -0,0 +1,29 @@
+#!/bin/bash
+
+. ./config.sh
+
+url=$MYSQL_URL
+username=$MYSQL_USER
+password=$MYSQL_PASSWORD
+
+## 无分区
+collect_data_np() {
+sqoop import -D mapred.job.queue.name=hive  \
+--connect $1 \
+--username $2 \
+--password $3 \
+--target-dir /warehouse/saga_dw/ods/$2  \
+--delete-target-dir \
+--query "$5 and \$CONDITIONS" \
+--num-mappers 1 \
+--hive-drop-import-delims \
+--fields-terminated-by '\001' \
+--compress \
+--compression-codec lzo \
+--hive-import \
+--hive-database saga_dw \
+--hive-table $4 \
+--hive-overwrite \
+--null-string '\\N' \
+--null-non-string '\\N'
+}