问题描述
我使用 rjdbc
,
<$>成功连接了本地的R3.1.2(win7 64bit rstudio)和远程hive服务器(l在list.files中)
>
library(RJDBC)
.jinit()
dir =E:/ xxx / jars / hive / (dir)){
.jaddClassPath(paste(dir,l,sep =))}
options(java.parameters =-Xmx8g)
drv< - JDBC org.apache.hadoop.hive.jdbc.HiveDriver,
E:/xxx/jars/hive/hive-jdbc-0.11.0.jar)
conn< - dbConnect(drv,jdbc:hive://10.127.130.162:10002 / default,,)
dbGetQuery(conn,select * from test.test limit 10)
成功从配置单元读取数据,但无法使用
<$ c $写入R数据帧c> dbWriteTable :
data(iris)
dbWriteTable(conn,iris, test.dc_test)
错误返回:
方法d getTables带签名(Ljava / lang / String; Ljava / lang / String; [Ljava / lang / String;)Ljava / sql / ResultSet;找不到
我的滥用或其他方法需要吗?
我有一个部分答案。您的参数dbWriteTable颠倒过来。模式是dbWriteTable(connection,tableName,data),文档读取 dbWriteTable(conn,name,value,...)
。这就是说,我没有发现'正确的'形式或者产生以下错误信息:
错误在.local(conn,statement,...)中:
在dbSendUpdate([Simba] [HiveJDBCDriver](500051)错误处理查询/语句中执行JDBC更新查询失败。错误代码:40000,SQL state:TStatus statusCode:ERROR_STATUS,sqlState:42000,errorCode:40000,errorMessage:编译语句时出错:FAILED:ParseException行1:41不匹配输入'PRECISION'期待)在创建表语句中'DOUBLE'附近),查询:CREATE TABLE iris(` Sepal.Length` DOUBLE PRECISION,`Sepal.Width` DOUBLE PRECISION,`Petal.Length` DOUBLE PRECISION,`Petal.Width` DOUBLE PRECISION,Species VARCHAR(255))。)
(至少在Hive中使用Amazon的JDBC驱动程序时)。这个错误至少看起来很明显,生成的查询使得数据插入表在HiveQL中没有正确解析。修复,除了手动做,我不确定。
I have successfully connected local R3.1.2( win7 64bit rstudio) and remote hive server using rjdbc
,
library(RJDBC)
.jinit()
dir = "E:/xxx/jars/hive/"
for(l in list.files(dir)) {
.jaddClassPath(paste( dir ,l,sep="")) }
options( java.parameters = "-Xmx8g" )
drv <- JDBC("org.apache.hadoop.hive.jdbc.HiveDriver",
"E:/xxx/jars/hive/hive-jdbc-0.11.0.jar")
conn <- dbConnect(drv, "jdbc:hive://10.127.130.162:10002/default", "", "" )
dbGetQuery(conn, "select * from test.test limit 10 ")
successfully read data from hive ,but I cannot write R data frame usingdbWriteTable
:
data(iris)
dbWriteTable(conn, iris , "test.dc_test")
Error return:
Error in .jcall(md, "Ljava/sql/ResultSet;", "getTables", .jnull("java/lang/String"), : method getTables with signature (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/sql/ResultSet; not found
Either my misuse or other methods needed?
I have a partial answer. Your arguments to dbWriteTable are reversed. The pattern is dbWriteTable(connection, tableName, data), the docs read dbWriteTable(conn, name, value, ...)
. That being said, I don't find that the 'correct' form works either, instead yielding the following error message:
Error in .local(conn, statement, ...) :
execute JDBC update query failed in dbSendUpdate ([Simba][HiveJDBCDriver](500051) ERROR processing query/statement. Error Code: 40000, SQL state: TStatus(statusCode:ERROR_STATUS, sqlState:42000, errorCode:40000, errorMessage:Error while compiling statement: FAILED: ParseException line 1:41 mismatched input 'PRECISION' expecting ) near 'DOUBLE' in create table statement), Query: CREATE TABLE iris (`Sepal.Length` DOUBLE PRECISION,`Sepal.Width` DOUBLE PRECISION,`Petal.Length` DOUBLE PRECISION,`Petal.Width` DOUBLE PRECISION,Species VARCHAR(255)).)
(at least when using Amazon's JDBC driver for Hive). That error at least seems self apparent, the query generated to make the table for data insertion didn't parse correctly in HiveQL. The fix, other than doing it manually, I'm not sure about.
这篇关于R使用RJDBC将表写入Hive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!