赞
踩
将hive配置文件hive-site.xml放到spark的conf目录下
cp /etc/hive/conf/hive-site.xml /etc/spark/conf
在页面重启spark
spark-shell Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). Spark context Web UI available at http://agent01:4040 Spark context available as 'sc' (master = yarn, app id = application_1659692413492_0026). Spark session available as 'spark'. Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 2.4.0-cdh6.3.2 /_/ Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_191) Type in expressions to have them evaluated. Type :help for more information. scala> spark.sql("show databases").show(); +------------+ |databaseName| +------------+ | default| | kylin_hive| | testdb| +------------+ scala> scala> spark.sql("use testdb").show(); ++ || ++ ++ scala> spark.sql("show tables").show(); +--------+---------+-----------+ |database|tableName|isTemporary| +--------+---------+-----------+ | testdb| test| false| | testdb| test2| false| +--------+---------+-----------+ scala> spark.sql("select * from testdb.test").show(); +---+----+ | id|name| +---+----+ | 1|张三| +---+----+ scala>
spark-shell Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 22/08/09 14:39:52 WARN util.Utils: Service 'SparkUI' could not bind on port 4040. Attempting port 4041. Spark context Web UI available at http://agent02:4041 Spark context available as 'sc' (master = yarn, app id = application_1659692413492_0027). Spark session available as 'spark'. Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 2.4.0-cdh6.3.2 /_/ Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_191) Type in expressions to have them evaluated. Type :help for more information. scala> scala> import org.apache.spark.sql.hive.HiveContext import org.apache.spark.sql.hive.HiveContext scala> val hiveContext = new HiveContext(sc) warning: there was one deprecation warning; re-run with -deprecation for details hiveContext: org.apache.spark.sql.hive.HiveContext = org.apache.spark.sql.hive.HiveContext@6aa27145 scala> hiveContext.sql("show databases").show() +------------+ |databaseName| +------------+ | default| | kylin_hive| | testdb| +------------+ scala> hiveContext.sql("use testdb").show() ++ || ++ ++ scala> hiveContext.sql("show tables").show() +--------+---------+-----------+ |database|tableName|isTemporary| +--------+---------+-----------+ | testdb| test| false| | testdb| test2| false| +--------+---------+-----------+ scala> hiveContext.sql("select * from testdb.test").show() +---+----+ | id|name| +---+----+ | 1|张三| +---+----+ scala>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。