rjdbc可以很好地连接到hive,还可以从hive读取数据。但它没有使用-->dbwritetable将数据写入配置单元。
见下文-
options(java.parameters = "-Xmx8g")
library(DBI)
library(rJava)
library(RJDBC)
cp <- c(list.files("/tmp/R_hive_libs/cloudera_hive_jars", pattern = "[.]jar", full.names=TRUE, recursive=TRUE),list.files("/tmp/R_hive_libs/R_hadoop_libs", pattern = "[.]jar", full.names=TRUE, recursive=TRUE),list.files("/tmp/R_hive_libs/R_hadoop_libs/lib", pattern = "[.]jar", full.names=TRUE, recursive=TRUE), recursive=TRUE)
drv <- JDBC(driverClass = "com.cloudera.hive.jdbc4.HS2Driver", classPath=cp)
conn <- dbConnect(drv, "jdbc:hive2://XXXXXX:10000/default", "user", "password")
show_databases <- dbGetQuery(conn, "show databases")
List_of_Tables <- dbListTables(conn)
data1 <- dbGetQuery(conn, "select * from XXX.xxx limit 10000")
data_to_write_back_to_hive <- data.frame(aggregate(data1$xxx.xxx, by=list(Month=data1$xxx.cmp_created_timestamp_month), FUN=sum))
data_to_write_back_to_hive[[2]] <-c(10,20)
colnames(data_to_write_back_to_hive) <- c("Month", "Energy")
dbWriteTable(conn, "xxxx.checking",data_to_write_back_to_hive)
如何将数据写回配置单元?它给出了下面的错误-
.local(conn,statement,…)中出错:在dbsendupdate([simba]hivejdbcdriver error processing query/statement)中执行jdbc update query失败。错误代码:40000,sql状态:tstatustatuscode:error_status,infomessages:[*org.apache.hive.service.cli.hivesqlexception:error while 编译语句:失败:parseexception行1:36 create table中“double”附近有不匹配的输入(应为“precision”)statement:28:27,org.apache.hive.service.cli.operation。operation:tosqlexception:操作。java:326,org.apache.hive.service.cli.operation.sqloperation:prepare:sqloperation。java:102,org.apache.hive.service.cli.operation.sqloperation:runinternal:sqloperation。java:171,org.apache.hive.service.cli.operation。operation:run:操作。java:268,org.apache.hive.service.cli.session.hivesessionimpl:executestatementinternal:hivesessionimpl。java:410,org.apache.hive.service.cli.session.hivesessionimpl:executestatement:hivesessionimpl。java:391,sun.reflect.generatedmethodaccessor56:调用::-1,sun.reflect.delegatingmeth
1条答案
按热度按时间mi7gmzs61#
这个问题提得相当多。我认为简单的答案是你现在不能做你想做的事。dbi/jdbc驱动程序不会对语法正确的hiveql进行元编程。