-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
5 changed files
with
72 additions
and
4 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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/lovecws/mumu/spark/sql/AtdSparkAnalyze.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,30 @@ | ||
package com.lovecws.mumu.spark.sql; | ||
|
||
import com.lovecws.mumu.spark.MumuSparkConfiguration; | ||
import org.apache.spark.sql.*; | ||
|
||
/** | ||
* @program: mumu-spark | ||
* @description: ${description} | ||
* @author: 甘亮 | ||
* @create: 2019-12-12 20:00 | ||
**/ | ||
public class AtdSparkAnalyze { | ||
|
||
public void analyze() { | ||
String filePath = "E:\\data\\industrydataprocessing\\atd\\storage\\20191212"; | ||
SQLContext sqlContext = new MumuSparkConfiguration().sqlContext(); | ||
Dataset<Row> rowDataset = sqlContext.read().parquet(filePath); | ||
|
||
rowDataset.show(10); | ||
try { | ||
rowDataset.createTempView("atd"); | ||
rowDataset.sqlContext().sql("select count(1) as counter from atd").show(100); | ||
rowDataset.sqlContext().sql("select count(1) as counter from atd where corp_name is not null or src_corp_name is not null").show(100); | ||
rowDataset.sqlContext().sql("select count(1) as counter from atd where corp_name is null and src_corp_name is null").show(100); | ||
rowDataset.sqlContext().sql("select distinct dst_ip from atd where corp_name is null and src_corp_name is null and dst_ip_province='湖南省' union select distinct src_ip from atd where corp_name is null and src_corp_name is null and src_ip_province='湖南省'").coalesce(1).write().mode(SaveMode.Overwrite).csv("E:\\data\\industrydataprocessing\\atd\\corpiphunan"); | ||
} catch (AnalysisException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/test/java/com/lovecws/mumu/spark/sql/AtdSparkAnalyzeTest.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,17 @@ | ||
package com.lovecws.mumu.spark.sql; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* @program: mumu-spark | ||
* @description: ${description} | ||
* @author: 甘亮 | ||
* @create: 2019-12-12 20:02 | ||
**/ | ||
public class AtdSparkAnalyzeTest { | ||
|
||
@Test | ||
public void analyze() { | ||
new AtdSparkAnalyze().analyze(); | ||
} | ||
} |