Trafodion 的数据加载主要包括两种方法,即 Trickle Load(持续加载) 和 Bulk Load(批量加载)。
下表介绍了两种加载方法的区别:html
类型 | 描述 | 方法/工具 |
---|---|---|
Trickle Load | 数据量较小,当即插入 | ODB 工具(性能一般较第三方ETL工具更好); ETL 工具如kettle、Informatica等; 自主开发的ODBC/JDBC应用。 |
Bulk Load | 数据量较大;阶段性数据而且是批量加载的方式 | Bulk Loader |
从SQL插入语句实现方式来看,mysql
Trickle Load 又包括如下三种方式:sql
而Bulk Load主要的SQL命令为: LOAD数据库
以上4种SQL实现加载方式区别以下表:apache
特征 | INSERT | UPSERT | UPSERT USING LOAD | LOAD |
---|---|---|---|---|
事务 | 是 | 是 | 不是,使用HBase的WAL来恢复 | 不是,使用快照(SNAPSHOT)来恢复 |
操做方法 | 经过CheckAndPut调用走标准HBase写路径 | 经过Put调用走标准HBase写路径 | 经过Put调用走标准HBase写路径 | 使用HBase bulk load写路径并直接建立HFiles |
惟一性约束 | 强制 | 不强制,有相同键值的覆盖以前的行 | 不强制,有相同键值的覆盖以前的行 | 部分强制 |
索引 | 能够用在有索引的表上 | 能够用在有索引的表上 | 当用在有索引的表上时,会回到UPSERT | 能够用在有索引的表,索引会不起做用 |
最大Size | 10k*n 行,n表明节点数 | 10k*n 行,n表明节点数 | 5million*n 行,n表明节点数 | 2 billion*n行,n表明节点数 |
最小Size | 1行 | 1行 | 1行 | 1million*n行 |
速度 | 最慢 | 比INSERT快 | 比UPSERT快 | 最快 |
(注:如下只是初步介绍Trafodion odb工具的几个主要命令的基本用法,更多用法及适用场景请见下载官方文档点击打开连接查看详情)centos
语法ide
用例
(1)建立测试表工具
(2)建立测试文件并编辑数据oop
(3)Load文件到测试表性能
(4)检查Load是否成功
语法
用例
(1)继续使用上述测试表,当前测试表已经加载了5条数据。
(2)Extract上表数据到指定文件
[centos@cent-1 bin]$ ./odb64luo -u trafodion -p traf123 -d traf -l src=test.file:tgt=trafodion.seabase.test_tbl\ > :fs=\,:rows=5:loadcmd=IN:truncate:parallel=2 odb [main(1354)] - Unknow option :fs=,:rows=5:loadcmd=IN:truncate:parallel=2. Ignored odb [2016-09-26 09:15:51]: starting ODBC connection(s)... (1) 1 2 Connected to Trafodion [0.0.0]--- 0 row(s) deleted in 0.687s (prep 0.006s, exec 0.681s, fetch 0.000s/0.000s) [0] 5 records inserted [commit] [0] odb version 1.1.0 Load(2) statistics: [0] Target table: TRAFODION.SEABASE.TEST_TBL [0] Source: test.file [0] Pre-loading time: 0.327 s (00:00:00.327) [0] Loading time: 0.146 s(00:00:00.146) [0] Total records read: 5 [0] Total records inserted: 5 [0] Total number of columns: 2 [0] Total bytes read: 31 [0] Average input row size: 6.2 B [0] ODBC row size: 21 B (data) + 16 B (len ind) [0] Rowset size: 100 [0] Rowset buffer size: 3.61 KiB [0] Load throughput (real data): 0.207 KiB/s [0] Load throughput (ODBC): 0.702 KiB/s odb [2016-09-26 09:15:51]: exiting. Session Elapsed time 0.479 seconds (00:00:00.479)
(3)查询文件内容
语法
用例
(1)建立一个表和原测试结构一致
(2)利用COPY命令把原测试表数据复制到新表
[centos@cent-1 bin]$ ./odb64luo -u trafodion:trafodion -p traf123:traf123 -d traf:traf -cp src=trafodion.seabase.test_tbl:tgt=trafodion.seabase.test_tbl2:rows=m2:truncate Connected to Trafodion odb [2016-09-26 09:51:51]: starting ODBC connection(s)... 0 >1 >2 Connected to Trafodion [1.0.0]--- 0 row(s) deleted in 0.298s (prep 0.285s, exec 0.013s, fetch 0.000s/0.000s) [1] 5 records copied [commit] [0] odb version 1.1.0 Copy statistics: [0] Source: TRAFODION.SEABASE.TEST_TBL [0] Target: trafodion.seabase.test_tbl2 [0] Total number of columns: 2 [0] ODBC row size: 23 B (data) + 16 B (len ind) [0] Rowset size: 53,773 [0] Rowset buffer size: 2,048.00 KiB [0] Pre-copy time: 0.677 s (00:00:00.677) [0] Copy time: 0.037 s (00:00:00.037) [0] Total records copied: 5 (0.135 krec/s) [0] Copy throughput (ODBC): 0.003 MiB/s (0.010 GiB/h) [0] Total/Wait cycles: 1/0 [0>1] 5 records copied in 0.037 (00:00:00.037 s) [0>2] 0 records copied in 0.037 (00:00:00.037 s) odb [2016-09-26 09:51:52]: exiting. Session Elapsed time 0.733 seconds (00:00:00.733)
(3)检查数据是否复制成功
语法
Transform是Load的一种,Transform的意思是在Load的时候经过一个mapfile来实现一些功能,好比忽略输入文件的某些行、生产序列号、插入常量、日期格式转换、字符串截取和替换、生成随机数等等。
用例
(1)测试表继续用上述的test_tbl
(2)建立测试Input文件,内容以下:
(3)建立map文件,内容以下:
(4)根据map文件加载数据
[centos@cent-1 bin]$ ./odb64luo -u trafion -p traf123 -d traf -l src=test_transform.file:tgt=trafodion.seabase.test_tbl:map=m.map:fs=,:truncate odb [2016-09-26 10:28:49]: starting ODBC connection(s)... 0 Connected to Trafodion [0.0.0]--- 5 row(s) deleted in 0.042s (prep 0.001s, exec 0.041s, fetch 0.000s/0.000s) [0] 5 records inserted [commit] [0] odb version 1.1.0 Load statistics: [0] Target table: TRAFODION.SEABASE.TEST_TBL [0] Source: test_transform.file [0] Pre-loading time: 0.165 s (00:00:00.165) [0] Loading time: 0.023 s(00:00:00.023) [0] Total records read: 5 [0] Total records inserted: 5 [0] Total number of columns: 2 [0] Total bytes read: 75 [0] Average input row size: 15.0 B [0] ODBC row size: 21 B (data) + 16 B (len ind) [0] Rowset size: 100 [0] Rowset buffer size: 3.61 KiB [0] Load throughput (real data): 3.184 KiB/s [0] Load throughput (ODBC): 4.458 KiB/s odb [2016-09-26 10:28:49]: exiting. Session Elapsed time 0.195 seconds (00:00:00.195)
(5)检查数据是否转换成功
Bulk Load主要是针对大数据量的且通常是批量装载的方式。Bulk Load一般使用LOAD语句实现。
下面介绍几种Bulk Load方式,
(1)建立两个表结构相同的测试表
(2)表1有几条数据,表2没有数据
(3)从表1加载数据到表2
(1)建立测试文件并利用scp或者其余方式上传到Hadoop Cluster上,内容以下
(2)将测试文件导入HDFS中
(3)在Trafodion中建立测试表
(4)在Hive中建立Hive外部表,指向前面对应的HDFS文件
[hdfs@cent-1 ~]$ hive Logging initialized using configuration in jar:file:/opt/cloudera/parcels/CDH-5.4.8-1.cdh5.4.8.p0.4/jars/hive-common-1.1.0-cdh5.4.8.jar!/hive-log4j.properties WARNING: Hive CLI is deprecated and migration to Beeline is recommended. hive> create external table test_tbl (name string,age int,sex string) row format delimited fields terminated by ',' location '/hive/test/test_tbl'; OK Time taken: 0.085 seconds hive> show tables; OK test_tbl Time taken: 0.364 seconds, Fetched: 1 row(s)
(5)加载数据到Trafodion表
(1)在Hive中建立测试表并插入几条数据
(2)Trafodion中的表继续沿用上述测试表,先清空数据
(3)从Hive加载数据到Trafodion
(注:在作从hive到trafodion数据加载的时候有几个参数能够配置,用来提高加载性能,如HIVE_MAX_STRING_LENGTH、ALLOW_INCOMPATIBLE_ASSIGNMENT
典型的用法以下:
CQD HIVE_MAX_STRING_LENGTH '1000'; --用于当列的最大长度为1KB时 CQD ALLOW_INCOMPATIBLE_ASSIGNMENT 'ON'; --用于当有时间相关的列的时候
(1)在集群上安装并启动Sqoop,Sqoop安装步骤请参照其官方文档点击打开连接
(2)下载mysql connector Jar包,并放到/var/lib/sqoop目录下
(3)在某台机器上安装Mysql,安装Mysql步骤此处不做详细说明
(4)在mysql数据中建立测试表,并插入几条数据
(5)使用sqoop命令从mysql往hive导入数据
[hdfs@cent-2 ~]$ sqoop import --connect jdbc:mysql://localhost:3306/test --driver com.mysql.jdbc.Driver --username centos --table test_tbl --split-by name --hive-import --create-hive-table --hive-table test_tabl_hive Warning: /opt/cloudera/parcels/CDH-5.4.8-1.cdh5.4.8.p0.4/bin/../lib/sqoop/../accumulo does not exist! Accumulo imports will fail. ... Logging initialized using configuration in jar:file:/opt/cloudera/parcels/CDH-5.4.8-1.cdh5.4.8.p0.4/jars/hive-common-1.1.0-cdh5.4.8.jar!/hive-log4j.properties OK Time taken: 3.052 seconds Loading data to table default.test_tabl_hive Table default.test_tabl_hive stats: [numFiles=4, totalSize=27] OK Time taken: 0.748 seconds
(6)从Trafodion或Hive Shell中查看数据是否导入成功
做者:Post_yuan,易鲸捷资深交付工程师。