Spark SQL ---分布式SQL引擎
4.分布式SQL引擎
Spark SQL可以作为JDBC/ODBC或者命令行工具的分布式查询引擎。在这种模式下,终端用户或应用程序,无需写任何代码,就可以直接在Spark SQL中运行SQL查询。
4.1 运行Thrift JDBC/ODBC server
此处实现的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可以查看完整的选项列表。默认情况下,启动的server将会在localhost:10000端口上监听。要改变监听主机名或端口,可以用以下环境变量:
export HIVE_SERVER2_THRIFT_PORT=<listening-port>
export HIVE_SERVER2_THRIFT_BIND_HOST=<listening-host>
./sbin/start-thriftserver.sh \
--master <master-uri> \
...
或Hive系统属性:
./sbin/start-thriftserver.sh \
--hiveconf hive.server2.thrift.port=<listening-port> \
--hiveconf hive.server2.thrift.bind.host=<listening-host> \
--master <master-uri>
...
现在,可以使用beeline测试Thrift JDBC / ODBC服务器:
./bin/beeline
通过以下方式可以连接到JDBC / ODBC服务器:
beeline> !connect jdbc:hive2://localhost:10000
Beeline会要求您提供用户名和密码。在非安全模式下,只需在计算机上输入用户名和空白密码即可。对于安全模式,请遵循beeline文档中给出的 说明。
Hive的配置是在conf/目录下的hive-site.xml,core-site.xml,hdfs-site.xml中指定的。
还可以使用Hive随附的beeline脚本。
Thrift JDBC server也支持通过HTTP传输Thrift RPC消息。以下配置(在conf/hive-site.xml中)将启用HTTP模式:
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 server:
beeline> !connect jdbc:hive2://<host>:<port>/<database>?hive.server2.transport.mode=http;hive.server2.thrift.http.path=<http_endpoint>
4.2 运行Spark SQL命令行工具
Spark SQL CLI是一个很方便的工具,它可以用local mode运行hive metastore service,并且在命令行中执行输入的查询。注意Spark SQL CLI目前还不支持和Thrift JDBC server通信。
要启动Spark SQL CLI,在Spark目录中运行以下命令:
./bin/spark-sql
Hive配置在conf目录下hive-site.xml,core-site.xml,hdfs-site.xml中设置。你可以用这个命令查看完整的选项列表:./bin/spark-sql –help
参考
https://spark.apache.org/docs/latest/sql-programming-guide.html
1218

被折叠的 条评论
为什么被折叠?



