library(RJDBC)
cp
= c(list.files(
"/usr/lib/hive/lib"
, pattern =
"[.]jar"
, full.names=TRUE, recursive=TRUE),
list.files(
"/usr/lib/hadoop"
, pattern =
"[.]jar"
, full.names=TRUE, recursive=TRUE),
list.files(
"/etc/hadoop/conf"
, full.names=TRUE, recursive=TRUE),
recursive=TRUE
)
drv = JDBC(driverClass =
"org.apache.hive.jdbc.HiveDriver"
, classPath =
cp
)
hiveconnection = dbConnect(drv,
"jdbc:hive2://hadoop-jy-backupserver:10000/default;principal=hive/[email protected]"
,user=
"*******"
, password=
"*******"
)
count = dbGetQuery(hiveconnection,
"SELECT count(*) FROM cpr.baidu_index"
)
sqlCreateTbl = "CREATE TABLE IF NOT EXISTS cpr.person_correlation_graph_temp(rownames STRING,ibao_person_id_x STRING, ibao_person_id_y STRING,
cor_index DOUBLE,start_date STRING,end_date STRING)"
result=dbSendUpdate(hiveconnection,sqlCreateTbl)
dfToLoad = data.frame(rownames=c(
'1'
,
'2'
),ibao_person_id_x=c(
'盗墓笔记'
,
'盗墓笔记'
),
ibao_person_id_y=c(
'李易峰'
,
'杨洋'
),cor_index=c(0.8900,0.5100))
dbWriteTable(hiveconnection,
"cpr.person_correlation_graph"
, dfToLoad, overwrite=TRUE)
dbListTables(hiveconnection,
"%qiyu%"
)
df = dbReadTable(hiveConn,
"iris"
)
请发表评论