forked from fayson/cdhproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
peach
committed
May 28, 2018
1 parent
61081c4
commit 019cd2b
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
sparkdemo/src/main/java/com.cloudera/hive/ReadHiveSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.cloudera.hive; | ||
|
||
import org.apache.spark.SparkConf; | ||
import org.apache.spark.SparkContext; | ||
import org.apache.spark.sql.DataFrame; | ||
import org.apache.spark.sql.hive.HiveContext; | ||
|
||
/** | ||
* package: hive | ||
* describe: 使用Spark API访问Hive表 | ||
* creat_user: Fayson | ||
* email: [email protected] | ||
* creat_date: 2018/5/16 | ||
* creat_time: 下午11:51 | ||
* 公众号:Hadoop实操 | ||
*/ | ||
public class ReadHiveSample { | ||
|
||
public static void main(String[] args) { | ||
SparkConf sparkConf = new SparkConf() | ||
// .setMaster("local[2]") | ||
.setMaster("yarn-client") | ||
.setAppName("AccessHive"); | ||
|
||
SparkContext sparkContext = new SparkContext(sparkConf); | ||
HiveContext hiveContext = new HiveContext(sparkContext); | ||
DataFrame dataFrame = hiveContext.sql("show tables"); | ||
dataFrame.show(); | ||
|
||
dataFrame = hiveContext.sql("select * from test"); | ||
|
||
dataFrame.show(); | ||
} | ||
} |