Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
dab81a85
Commit
dab81a85
authored
12 years ago
by
Patrick Wendell
Browse files
Options
Downloads
Patches
Plain Diff
Fixing to match Spark styleguide
parent
cc37601e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/src/main/scala/spark/examples/LogQuery.scala
+8
-8
8 additions, 8 deletions
examples/src/main/scala/spark/examples/LogQuery.scala
with
8 additions
and
8 deletions
examples/src/main/scala/spark/examples/
OLAP
Query.scala
→
examples/src/main/scala/spark/examples/
Log
Query.scala
+
8
−
8
View file @
dab81a85
...
...
@@ -5,7 +5,7 @@ import spark.SparkContext._
/**
* Executes a roll up-style query against Apache logs.
*/
object
OLAP
Query
{
object
Log
Query
{
val
exampleApacheLogs
=
List
(
"""10.10.10.10 - "FRED" [18/Jan/2013:17:56:07 +1100] "GET http://images.com/2013/Generic.jpg
| HTTP/1.1" 304 315 "http://referall.com/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
...
...
@@ -23,16 +23,16 @@ object OLAPQuery {
def
main
(
args
:
Array
[
String
])
{
if
(
args
.
length
==
0
)
{
System
.
err
.
println
(
"Usage:
OLAP
Query <master> [logFile]"
)
System
.
err
.
println
(
"Usage:
Log
Query <master> [logFile]"
)
System
.
exit
(
1
)
}
val
sc
=
new
SparkContext
(
args
(
0
),
"
OLAP
Query"
)
val
sc
=
new
SparkContext
(
args
(
0
),
"
Log
Query"
)
val
dataSet
=
if
(
args
.
length
==
2
)
sc
.
textFile
(
args
(
1
))
else
sc
.
parallelize
(
exampleApacheLogs
)
val
apache
_log_r
egex
=
val
apache
LogR
egex
=
"""^([\d.]+) (\S+) (\S+) \[([\w\d:/]+\s[+\-]\d{4})\] "(.+?)" (\d{3}) ([\d\-]+) "([^"]+)" "([^"]+)".*"""
.
r
/** Tracks the total query count and number of aggregate bytes for a particular group. */
...
...
@@ -42,8 +42,8 @@ object OLAPQuery {
}
def
extractKey
(
line
:
String
)
:
(
String
,
String
,
String
)
=
{
apache
_log_r
egex
findFirstIn
line
match
{
case
Some
(
apache
_log_r
egex
(
ip
,
_
,
user
,
dateTime
,
query
,
status
,
bytes
,
referer
,
ua
))
=>
apache
LogR
egex
.
findFirstIn
(
line
)
match
{
case
Some
(
apache
LogR
egex
(
ip
,
_
,
user
,
dateTime
,
query
,
status
,
bytes
,
referer
,
ua
))
=>
if
(
user
!=
"\"-\""
)
(
ip
,
user
,
query
)
else
(
null
,
null
,
null
)
case
_
=>
(
null
,
null
,
null
)
...
...
@@ -51,8 +51,8 @@ object OLAPQuery {
}
def
extractStats
(
line
:
String
)
:
Stats
=
{
apache
_log_r
egex
findFirstIn
line
match
{
case
Some
(
apache
_log_r
egex
(
ip
,
_
,
user
,
dateTime
,
query
,
status
,
bytes
,
referer
,
ua
))
=>
apache
LogR
egex
.
findFirstIn
(
line
)
match
{
case
Some
(
apache
LogR
egex
(
ip
,
_
,
user
,
dateTime
,
query
,
status
,
bytes
,
referer
,
ua
))
=>
new
Stats
(
1
,
bytes
.
toInt
)
case
_
=>
new
Stats
(
1
,
0
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment