1

我已将mysql表复制到hdfs使用中,然后使用“ ”命令sqoop创建了同名的表。impalacreate external table

现在我有更多数据要使用Impala插入到impala表中,即。请帮我在表格中插入数据。java apiImpalaService.jarjava api

谢谢。

4

1 回答 1

1

使用 ImpalaService.jar 您可以发送一个插入语句,例如:

# java -cp ../deps/libthrift-0.9.1.jar:../deps/slf4j.api-1.6.1.jar:./deps/slf4j-simple-.6.1.jar:../jar/ImpalaService.jar:./jar/ImpalaConnectTest.jar org.ImpalaConnectTest.ImpalaConnectTest localhost  21050 "insert into foo values (1,'message 1')"
Result size = 0
#

然后,您可以通过以下方式使用 ImpalaService.jar 检查结果:

# java -cp ../deps/libthrift-0.9.1.jar:../deps/slf4j.api-1.6.1.jar:./deps/slf4j-simple-.6.1.jar:../jar/ImpalaService.jar:./jar/ImpalaConnectTest.jar org.ImpalaConnectTest.ImpalaConnectTest localhost  21050 "select * from foo"
Result size = 1
TRow(colVals:[<TColumnValue i32Val:TI32Value(value:1)>, <TColumnValue stringVal:TStringValue(value:message 1)>])
# 

或使用 Impala-shell:

[root@dub-vcd-vms165 ~]# impala-shell
Starting Impala Shell without Kerberos authentication
Connected to XXXXXX
Server version: impalad version cdh5-1.3.0 RELEASE (build 40e1b62cf0b97f666d084d9509bf9639c575068c)
Welcome to the Impala shell. Press TAB twice to see a list of available commands.

Copyright (c) 2012 Cloudera, Inc. All rights reserved.

(Shell build version: Impala Shell vcdh5-1.3.0 (40e1b62) built on Tue Mar 25 13:46:44 PDT 2014)
[XXXXXX:21000] > select * from foo;
Query: select * from foo
+----+-----------+
| id | msg       |
+----+-----------+
| 1  | message 1 |
+----+-----------+
Returned 3 row(s) in 0.62s
[XXXXXX:21000] >

注意:如果要插入多个数据,则可以将 ImpalaService.jar 修改为更精细的解决方案,通过使用参数指定包含要插入的所有记录的数据源来执行多个插入语句。

于 2014-06-16T10:27:26.020 回答