-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change:1. 更新包名
- Loading branch information
Showing
15 changed files
with
169 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
2 changes: 2 additions & 0 deletions
2
...er/src/main/java/SparkHiveNewVersion.java → ...gui/sparkstarter/SparkHiveNewVersion.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
2 changes: 2 additions & 0 deletions
2
...er/src/main/java/SparkHiveOldVersion.java → ...gui/sparkstarter/SparkHiveOldVersion.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
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
2 changes: 2 additions & 0 deletions
2
...er/src/main/java/SparkSessionStarter.java → ...gui/sparkstarter/SparkSessionStarter.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
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
2 changes: 1 addition & 1 deletion
2
...er/src/main/java/demo1/AccessLogInfo.java → ...gui/sparkstarter/demo1/AccessLogInfo.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package demo1; | ||
package com.wugui.sparkstarter.demo1; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
2 changes: 1 addition & 1 deletion
2
...src/main/java/demo1/AccessLogSortKey.java → .../sparkstarter/demo1/AccessLogSortKey.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package demo1; | ||
package com.wugui.sparkstarter.demo1; | ||
|
||
import lombok.Data; | ||
import scala.math.Ordered; | ||
|
2 changes: 1 addition & 1 deletion
2
...in/java/demo1/AppLogSparkApplication.java → ...starter/demo1/AppLogSparkApplication.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
2 changes: 1 addition & 1 deletion
2
...starter/src/main/java/demo1/DBHelper.java → ...om/wugui/sparkstarter/demo1/DBHelper.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package demo1; | ||
package com.wugui.sparkstarter.demo1; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
|
2 changes: 1 addition & 1 deletion
2
...starter/src/main/java/demo1/MockData.java → ...om/wugui/sparkstarter/demo1/MockData.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
89 changes: 89 additions & 0 deletions
89
spark-starter/src/main/java/com/wugui/sparkstarter/es/EsSparkTest.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,89 @@ | ||
package com.wugui.sparkstarter.es; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.spark.SparkConf; | ||
import org.apache.spark.api.java.JavaRDD; | ||
import org.apache.spark.api.java.JavaSparkContext; | ||
import org.apache.spark.sql.SparkSession; | ||
import org.elasticsearch.spark.rdd.api.java.JavaEsSpark; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* spark 结合elasticsearch 例子 | ||
* 参考资料:https://www.elastic.co/guide/en/elasticsearch/hadoop/current/spark.html#spark-native | ||
*/ | ||
public class EsSparkTest { | ||
|
||
public static void main(String[] args) { | ||
// new EsSparkTest().writeEs(); | ||
// new EsSparkTest().readEs(); | ||
new EsSparkTest().writeBeanEs(); | ||
} | ||
|
||
/** | ||
* 以map方式存入es | ||
*/ | ||
public void writeEs() { | ||
String elasticIndex = "spark/docs"; | ||
SparkConf sparkConf = new SparkConf() | ||
.setAppName("writeEs") | ||
.setMaster("local[*]") | ||
.set("es.index.auto.create", "true") | ||
.set("es.nodes", "192.168.1.25") | ||
.set("es.port", "9200") | ||
.set("es.nodes.wan.only", "true"); | ||
|
||
SparkSession sparkSession = SparkSession.builder().config(sparkConf).getOrCreate(); | ||
JavaSparkContext jsc = new JavaSparkContext(sparkSession.sparkContext());//adapter | ||
Map<String, ?> numbers = ImmutableMap.of("one", 1, "two", 2); | ||
Map<String, ?> airports = ImmutableMap.of("city", "广州", "airportName", "广州白云机场"); | ||
JavaRDD<Map<String, ?>> javaRDD = jsc.parallelize(ImmutableList.of(numbers, airports)); | ||
JavaEsSpark.saveToEs(javaRDD, elasticIndex); | ||
} | ||
|
||
/** | ||
* 以对象存入es | ||
*/ | ||
public void writeBeanEs() { | ||
SparkConf sparkConf = new SparkConf() | ||
.setAppName("writeEs") | ||
.setMaster("local[*]") | ||
.set("es.index.auto.create", "true") | ||
.set("es.nodes", "192.168.1.25") | ||
.set("es.port", "9200") | ||
.set("es.nodes.wan.only", "true"); | ||
SparkSession sparkSession = SparkSession.builder().config(sparkConf).getOrCreate(); | ||
JavaSparkContext jsc = new JavaSparkContext(sparkSession.sparkContext());//adapter | ||
|
||
|
||
TripBean upcoming = new TripBean("广州白云机场", "昆明机场"); | ||
TripBean lastWeek = new TripBean("昆明机场", "广州白云机场"); | ||
|
||
JavaRDD<TripBean> javaRDD = jsc.parallelize( | ||
ImmutableList.of(upcoming, lastWeek)); | ||
JavaEsSpark.saveToEs(javaRDD, "spark/docs"); | ||
} | ||
|
||
public void readEs() { | ||
SparkConf sparkConf = new SparkConf() | ||
.setAppName("writeEs") | ||
.setMaster("local[*]") | ||
.set("es.index.auto.create", "true") | ||
.set("es.nodes", "192.168.1.25") | ||
.set("es.port", "9200") | ||
.set("es.nodes.wan.only", "true"); | ||
|
||
SparkSession sparkSession = SparkSession.builder().config(sparkConf).getOrCreate(); | ||
JavaSparkContext jsc = new JavaSparkContext(sparkSession.sparkContext());//adapter | ||
JavaRDD<Map<String, Object>> searchRdd = JavaEsSpark.esRDD(jsc, "spark/docs", "?q=广州").values(); | ||
for (Map<String, Object> item : searchRdd.collect()) { | ||
item.forEach((key, value) -> System.out.println("search key:" + key + ", search value:" + value)); | ||
} | ||
sparkSession.stop(); | ||
} | ||
|
||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
spark-starter/src/main/java/com/wugui/sparkstarter/es/TripBean.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,31 @@ | ||
package com.wugui.sparkstarter.es; | ||
|
||
import java.io.Serializable; | ||
|
||
public class TripBean implements Serializable { | ||
private String departure, arrival; | ||
|
||
public TripBean(String departure, String arrival) { | ||
setDeparture(departure); | ||
setArrival(arrival); | ||
} | ||
|
||
public TripBean() { | ||
} | ||
|
||
public String getDeparture() { | ||
return departure; | ||
} | ||
|
||
public String getArrival() { | ||
return arrival; | ||
} | ||
|
||
public void setDeparture(String dep) { | ||
departure = dep; | ||
} | ||
|
||
public void setArrival(String arr) { | ||
arrival = arr; | ||
} | ||
} |