我在本地安装了 Apache Hive,并尝试通过 Rstudio/sparklyr 读取表。
我使用 Hive 创建了一个数据库:
hive> CREATE DATABASE test;
我尝试使用以下 R 脚本读取该数据库:
library(sparklyr)
library(dplyr)
library(DBI)
spark_disconnect_all()
Sys.setenv(SPARK_HOME = "/home/alessandro/spark-2.1.0-bin-hadoop2.7")
config <- spark_config()
config$spark.executor.instances <- 4
config$spark.executor.cores <- 4
config$spark.executor.memory <- "4G"
config$spark.sql.hive.metastore <- "/home/alessandro/spark-warehouse"
config$hive.metastore.warehouse.dir <- "/home/alessandro/spark-warehouse"
sc <- spark_connect(master="local", config=config, version="2.1.0")
dbGetQuery(sc, "show databases")
Still, dbGetQuery(sc, "show databases")
不显示创建的数据库,这很尴尬,因为数据库文件夹 test.db 正确放置在指定的位置hive.metastore.warehouse.dir
.
同样,如果我使用 dbGetQuery(sc, "CREATE DATABASE test2") 创建数据库,则会在中创建数据库文件夹hive.metastore.warehouse.dir
,但我无法使用以下命令通过 Hive 查看它:
hive> show databases;
基本上,即使所有数据库文件夹都放置在正确的路径中,从 Hive 中我只能看到通过 Hive 创建的数据库,而从 R 中我只能看到通过 R 创建的数据库。
我解决了在文件 hive-site.xml 中添加与 hive 连接的配置的问题:
<property>
<name>hive.metastore.uris</name>
<value>thrift://localhost:9083</value>
</property>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)