Databases and big data · A level · AQA 7517 4.11.1, Eduqas A500QS 2.5 · about 60 min
Volume, velocity and variety; why one server is not enough; distributed processing with map and reduce; the fact-based model and graph schema.
[1 mark]Which are the three Vs usually used to describe big data?
Tick every answer that is true.
[1 mark]Camera images, voice clips and free text arrive alongside sensor tables. Which V does this show?
[1 mark]Why does functional programming suit distributed processing of big data?
[1 mark]Which describes the fact-based model?
[1 mark]In a graph schema, what does an edge represent?
[1 mark]What does this print?
from functools import reduce
log = ["Ada,bump", "Bolt,bump", "Ada,bump", "Ada,stall"]
pairs = [(line.split(",")[0], 1) for line in log if line.endswith("bump")]
groups = {}
for key, value in pairs:
groups.setdefault(key, []).append(value)
for key in sorted(groups):
print(key, reduce(lambda a, b: a + b, groups[key]))Ada 2 Bolt 1
The map keeps only bumps as (robot, 1), the shuffle groups them, and the reduce adds each group.
Three servers each hold part of the robots' event log. servers is a list of three lists; every item is a string "<robot>,<event>", where event is bump or stall.
1. Write mapper(line): it takes one line and returns a list of *(key, value)* pairs, [(robot, 1)] if the event is bump, or [] otherwise.
2. Call mapper on every line of every server, and shuffle: group the values by key.
3. Write reducer(key, values): it takes a robot name and the list of its values, and returns (key, total).
4. Call reducer once for each robot, in name order, and print each result as <robot> <bumps>, such as Cog 2.
The robot does not move.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# each server holds part of the event log: "robot,event"
servers = [
["Ada,bump", "Bolt,bump", "Ada,stall"],
["Cog,bump", "Ada,bump", "Bolt,stall", "Bolt,bump"],
["Ada,bump", "Cog,bump"],
]The hint students can ask for: The mapper sees one line and knows nothing else: it gives back a list of key and value pairs, empty for a line that is not a bump. The shuffle gathers every value with the same key. The reducer then sees one key and all its values.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# each server holds part of the event log: "robot,event"
servers = [
["Ada,bump", "Bolt,bump", "Ada,stall"],
["Cog,bump", "Ada,bump", "Bolt,stall", "Bolt,bump"],
["Ada,bump", "Cog,bump"],
]
def mapper(line):
robot, event = line.split(",")
return [(robot, 1)] if event == "bump" else []
def reducer(key, values):
return (key, sum(values))
mapped = [pair for server in servers for line in server for pair in mapper(line)]
groups = {}
for key, value in mapped:
groups.setdefault(key, []).append(value)
for key in sorted(groups):
robot, total = reducer(key, groups[key])
print(robot, total)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.