使用Impala客户端 操作步骤 1. 以客户端安装用户,登录安装客户端的节点。 2. 执行以下命令,切换到客户端安装目录。 cd /opt/hadoopclient 3. 执行以下命令配置环境变量。 source bigdataenv 4. 运行Impala客户端命令,实现A业务。 直接执行Impala组件的客户端命令: impalashell 说明 默认情况下,impalashell尝试连接到localhost的21000端口上的Impala守护程序。如需连接到其他主机,请使用 i host:port 选项,例如:impalashell i xxx.xxx.xxx.xxx:21000。要自动连接到特定的Impala数据库,请使用 d 选项。例如,如果您的所有Kudu表都位于数据库“impalakudu”中,则d impalakudu可以使用此数据库。要退出ImpalaShell,请使用quit命令。 内部表的操作: 1. 根据表创建用户信息表userinfo并添加相关数据。 createtable userinfo(id string,name string,gender string,age int,addr string); insert into table userinfo(id,name,gender,age,addr)values("12005000201","A","男",19,"A城市"); ......(其他语句相同) 2. 在用户信息表userinfo中新增用户的学历、职称信息。 以增加编号为12005000201的用户的学历、职称信息为例,其他用户类似。 alter table userinfo add columns(education string,technical string); 3. 根据用户编号查询用户姓名和地址。 以查询编号为12005000201的用户姓名和地址为例,其他用户类似。 select name,addr from userinfo where id'12005000201'; 4. 删除用户信息表。 drop table userinfo; 外部分区表的操作: 创建外部分区表并导入数据 1. 创建外部表数据存储路径。 安全模式(集群开启了Kerberos认证): cd /opt/hadoopclient source bigdataenv kinit hive 说明 用户hive需要具有Hive管理员权限。 impalashell hdfs dfs mkdir /hive hdfs dfs mkdir /hive/userinfo 普通模式(集群关闭了Kerberos认证): su omm cd /opt/hadoopclient source bigdataenv impalashell hdfs dfs mkdir /hive hdfs dfs mkdir /hive/userinfo 2. 建表。 create external table userinfo(id string,name string,gender string,age int,addr string) partitioned by(year string) row format delimited fields terminated by ' ' lines terminated by 'n' stored as textfile location '/hive/userinfo'; 说明 fields terminated指明分隔的字符,如按空格分隔,' '。 lines terminated 指明分行的字符,如按换行分隔,'n'。 /hive/userinfo为数据文件的路径。 3. 导入数据。 a. 使用insert语句插入数据。 insert into userinfo partition(year"2018") values ("12005000201","A","男",19,"A城市"); b. 使用load data命令导入文件数据。 i.根据下表数据创建文件。如,文件名为txt.log,以空格拆分字段,以换行符作为行分隔符。 ii. 上传文件至hdfs。 hdfs dfs put txt.log /tmp iii. 加载数据到表中。 load data inpath '/tmp/txt.log' into table userinfo partition (year'2018'); 4. 查询导入数据。 select from userinfo; 5. 删除用户信息表。 drop table userinfo;