1

请考虑以下设置。

hadoop 版本 2.6.4

火花版本 2.1.0

操作系统 CentOS Linux 版本 7.2.1511(核心)

所有软件作为单节点集群安装在单台机器上,spark 以独立模式安装。我正在尝试使用Spark Thrift Server。要启动 spark thrift 服务器,我运行 shell 脚本 start-thriftserver.sh

运行 thrift 服务器后,我可以运行 beeline 命令行工具并发出以下命令: 命令运行成功:

!connect jdbc:hive2://localhost:10000 user_name '' org.apache.hive.jdbc.HiveDriver
create database testdb;
use testdb;
create table names_tab(a int, name string) row format delimited fields terminated by ' ';

我的第一个问题是在 haddop 上为这个表/数据库创建的基础文件/文件夹在哪里?问题是即使使用 stop-all.sh 停止了 hadoop,create table/database 命令仍然成功,这让我觉得表根本不是在 hadoop 上创建的。

我的第二个问题是如何告诉 spark 世界上安装了 hadoop 的位置?并要求 spark 使用 hadoop 作为从直线运行的所有查询的底层数据存储。

我应该以其他模式安装火花吗?

提前致谢。

4

1 回答 1

0

我的目标是通过 Spark Thrift Server 使用 hadoop 作为底层数据存储,让 beeline 命令行实用程序工作,我让它工作。我的设置是这样的:

Hadoop  <-->  Spark  <-->  SparkThriftServer  <--> beeline

我想以这样一种方式配置 spark,它使用 hadoop 来处理在 beeline 命令行实用程序上运行的所有查询。诀窍是在 spark-defaults.xml 中指定以下属性。

spark.sql.warehouse.dir hdfs://localhost:9000/user/hive/warehouse

默认情况下,spark 将 derby 用于元数据和数据本身(在 spark 中称为仓库)为了让 spark 使用 hadoop 作为仓库,我必须添加此属性。

这是一个示例输出

./beeline
Beeline version 1.0.1 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000 abbasbutt '' org.apache.hive.jdbc.HiveDriver
Connecting to jdbc:hive2://localhost:10000
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/abbasbutt/Projects/hadoop_fdw/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/abbasbutt/Projects/hadoop_fdw/apache-hive-1.0.1-bin/lib/hive-jdbc-1.0.1-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Connected to: Spark SQL (version 2.1.0)
Driver: Hive JDBC (version 1.0.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10000>
0: jdbc:hive2://localhost:10000>
0: jdbc:hive2://localhost:10000>
0: jdbc:hive2://localhost:10000> create database my_test_db;
+---------+--+
| Result  |
+---------+--+
+---------+--+
No rows selected (0.379 seconds)
0: jdbc:hive2://localhost:10000> use my_test_db;
+---------+--+
| Result  |
+---------+--+
+---------+--+
No rows selected (0.03 seconds)
0: jdbc:hive2://localhost:10000> create table my_names_tab(a int, b string) row format delimited fields terminated by ' ';
+---------+--+
| Result  |
+---------+--+
+---------+--+
No rows selected (0.11 seconds)
0: jdbc:hive2://localhost:10000>

下面是hadoop中对应的文件

[abbasbutt@localhost test]$ hadoop fs -ls /user/hive/warehouse/
17/01/19 10:48:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 4 items
drwxrwxr-x   - abbasbutt supergroup          0 2017-01-18 23:45 /user/hive/warehouse/fdw_db.db
drwxrwxr-x   - abbasbutt supergroup          0 2017-01-18 23:23 /user/hive/warehouse/my_spark_db.db
drwxrwxr-x   - abbasbutt supergroup          0 2017-01-19 10:47 /user/hive/warehouse/my_test_db.db
drwxrwxr-x   - abbasbutt supergroup          0 2017-01-18 23:45 /user/hive/warehouse/testdb.db

[abbasbutt@localhost test]$ hadoop fs -ls /user/hive/warehouse/my_test_db.db/
17/01/19 10:50:52 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 1 items
drwxrwxr-x   - abbasbutt supergroup          0 2017-01-19 10:50 /user/hive/warehouse/my_test_db.db/my_names_tab
[abbasbutt@localhost test]$ 
于 2017-01-19T05:59:13.907 回答