Created
September 22, 2016 19:53
-
-
Save timvw/33460a39534809a59894fad800676b40 to your computer and use it in GitHub Desktop.
SparkSQL and CTE for increased readability
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
val df = spark.read.text(inputFile) | |
df.createOrReplaceTempView("data") | |
val query = | |
""" | |
| WITH loglevel AS (SELECT SPLIT(value, ' ')[0] AS level FROM data WHERE LENGTH(value) > 0), | |
| levelcount AS (SELECT level, COUNT(*) as count FROM loglevel GROUP BY level) | |
| SELECT level, count FROM levelcount ORDER BY count DESC | |
""".stripMargin | |
val result = spark.sql(query) | |
println(result.rdd.toDebugString) | |
result.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment