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
fun main(args: Array<String>) { | |
PropertyConfigurator.configure("src/main/resources/log4j.properties") | |
System.setProperty("hadoop.home.dir", "c:/winutil/") | |
Class.forName("com.dremio.jdbc.Driver") |
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 spark = SparkSession.builder() | |
.appName("Dremio-Spark example") | |
.master("local[*]") | |
.getOrCreate() |
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 dfRaw = spark.read() | |
.format("jdbc") | |
.option("url", "jdbc:dremio:direct=127.0.0.1:31010") | |
.option("dbtable", """"@admin"."logs"""") | |
.option("user", "admin") | |
.option("password", "admin123qwe") | |
.load() |
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
fun castDf(df: Dataset<Row>) = | |
df.withColumn("_tmp", split(col("request"), " ")).select( | |
col("host"), | |
unix_timestamp( | |
col("request_time"), "dd/MMM/yyyy:HH:mm:ss" | |
).cast("timestamp").alias("time"), | |
col("_tmp").getItem(0).alias("verb"), | |
col("_tmp").getItem(1).alias("resource"), | |
col("status").cast("short"), | |
col("bytes") |
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 = castDf(dfRaw) | |
df.printSchema() |
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
df.describe("bytes").show() |
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
df.groupBy("status") | |
.count() | |
.sort("status") | |
.show() |
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
df.groupBy("host") | |
.count() | |
.filter(col("count").gt(700)) | |
.sort(col("count").desc()) | |
.show() |
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
df.filter(col("status").equalTo(404)) | |
.groupBy("resource") | |
.count() | |
.sort(desc("count")) | |
.show(10) |
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
df.select("host") | |
.distinct() | |
.count() |
OlderNewer