参考:http://spark.apache.org/docs/2.2.0/sql-programming-guide.html#running-the-thrift-jdbcodbc-server
Spark SQL也可以使用其JDBC / ODBC或命令行界面作为分布式查询引擎。在这种模式下,最终用户或应用程序可以直接与Spark SQL交互以运行SQL查询,而无需编写任何代码。
运行Thrift JDBC / ODBC服务器
这里实现的Thrift JDBC / ODBC服务器对应于 HiveServer2 Hive 1.2.1中的您可以使用Spark或Hive 1.2.1附带的beeline脚本测试JDBC服务器。
要启动JDBC / ODBC服务器,请在Spark目录中运行以下命令:
./sbin/start-thriftserver.sh
该脚本接受所有bin/spark-submit命令行选项,并且还有一个–hiveconf选项来指定Hive属性。您可以运行./sbin/start-thriftserver.sh –help所有可用选项的完整列表。默认情况下,服务器在localhost:10000上侦听。你可以通过两个环境变量覆盖这个行为,即:
export HIVE_SERVER2_THRIFT_PORT=<listening-port>
export HIVE_SERVER2_THRIFT_BIND_HOST=<listening-host>
./sbin/start-thriftserver.sh \
--master <master-uri> \
...
或系统属性:
./sbin/start-thriftserver.sh \
--hiveconf hive.server2.thrift.port=<listening-port> \
--hiveconf hive.server2.thrift.bind.host=<listening-host> \
--master <master-uri>
...
…
现在,您可以使用直线来测试Thrift JDBC / ODBC服务器:
./bin/beeline
通过以下方式直接连接到JDBC / ODBC服务器:
beeline> !connect jdbc:hive2://localhost:10000
直线会要求您输入用户名和密码。在非安全模式下,只需在您的机器上输入用户名并输入一个空白密码即可。对于安全模式,请按照中的说明进行操作 直线文档说明进行操作。
蜂巢的结构是通过将您做hive-site.xml,core-site.xml和hdfs-site.xml文件conf/。
您也可以使用Hive附带的直线脚本。
Thrift JDBC服务器还支持通过HTTP传输发送节俭的RPC消息。使用以下设置启用HTTP模式作为系统属性或在hive-site.xml文件中conf/:
hive.server2.transport.mode - Set this to value: http
hive.server2.thrift.http.port - HTTP port number to listen on; default is 10001
hive.server2.http.endpoint - HTTP endpoint; default is cliservice
要测试,请使用beeline通过http模式连接到JDBC / ODBC服务器:
beeline> !connect jdbc:hive2://<host>:<port>/<database>?hive.server2.transport.mode=http;hive.server2.thrift.http.path=<http_endpoint>