Skip to content

Commit

Permalink
新增SparkStreaming读取Kafka数据写入HBase示例
Browse files Browse the repository at this point in the history
  • Loading branch information
peach committed May 28, 2018
1 parent 61081c4 commit 019cd2b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions sparkdemo/src/main/java/com.cloudera/hive/ReadHiveSample.java
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();
}
}

0 comments on commit 019cd2b

Please sign in to comment.