一、准备阶段
1、建表语句
create table student(id integer not null primary key,"cf"."name" varchar,"cf"."age" integer,"cf"."address" varchar);
2、数据准备
说明:这里准备600条测试数据
3、将student01.csv数据放入本地/home/test目录下
二、导入方式一
1、先手动建表
create table student(id integer not null primary key,"cf"."name" varchar,"cf"."age" integer,"cf"."address" varchar);
2、命令
[root@master bin]# ./psql.py -t STUDENT master,slaves1,slaves2:2181 /home/test/student01.csv
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/softWare/phoenix/apache-phoenix-4.12.0-HBase-1.2-bin/phoenix-4.12.0-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/softWare/hadoop/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
20/03/17 10:01:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
csv columns from database.
CSV Upsert complete. 600 rows upserted
Time: 0.506 sec(s)
3、效果
三、导入方式二
1、在/home/test/下创建创建表的aa.sql文件
create table stu(id integer not null primary key,"cf"."name" varchar,"cf"."age" integer,"cf"."address" varchar);
2、命令
[root@master bin]# ./psql.py -t STU 192.168.230.21 /home/test/aa.sql /home/test/student01.csv
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/softWare/phoenix/apache-phoenix-4.12.0-HBase-1.2-bin/phoenix-4.12.0-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/softWare/hadoop/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
20/03/17 10:37:15 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
no rows upserted
Time: 2.517 sec(s)
csv columns from database.
CSV Upsert complete. 600 rows upserted
Time: 0.372 sec(s)
注意:当数据的文件名为stu.csv时,不用指定-t STU参数;因为如果在不指定-t参数的情况下,会默认把.csv的文件名当作表明;
[root@master bin]# ./psql.py 192.168.230.21 /home/test/aa.sql /home/test/stu.csv
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/softWare/phoenix/apache-phoenix-4.12.0-HBase-1.2-bin/phoenix-4.12.0-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/softWare/hadoop/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
20/03/17 10:40:54 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
no rows upserted
Time: 2.536 sec(s)
csv columns from database.
CSV Upsert complete. 600 rows upserted
Time: 0.415 sec(s)
3、效果
扫描二维码关注公众号,回复:
10241909 查看本文章