In this question don’t change code, just in python postgreSQL but solve the question and follow the instructions

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

In this question don’t change code, just in python postgreSQL but solve the question and follow the instructions

#!/usr/bin/env python
from operator import itemgetter
import sys
current_word = None
current_count = 0
word = None
# input comes from STDIN
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()
# parse the input we got from mapper.py
word, count = line.split('\t', 1)'
# print "DEBUG: "
# convert count (currently a string) to int
try:
count = int(count)
except ValueError:
# count was not a number, normally we would drop a log error
# but that is out of scope here, so continue
continue
word, " "
count
# this IF-switch only works because Hadoop sorts
# by key (here: word) before it is passed to the reducer
# hence the single-host example using streaming pipe must add in
# an explicit sort!
if current_word == word:
current_count += count
else:
if current_word:
output
# write result to STDOUT
print(f'{current_word}\t{current_count}')
current_count = count
current_word = word
# do not forget to output the last word if needed!
if current_word == word:
print(f'{current_word}\t{current_count}')
$ cat beach_day.csv I ./mapper.py | sort -k1,1 | ./reducer.py
"Accessory"
"Camping"
"Food"
"Toy"
1
2
Transcribed Image Text:#!/usr/bin/env python from operator import itemgetter import sys current_word = None current_count = 0 word = None # input comes from STDIN for line in sys.stdin: # remove leading and trailing whitespace line = line.strip() # parse the input we got from mapper.py word, count = line.split('\t', 1)' # print "DEBUG: " # convert count (currently a string) to int try: count = int(count) except ValueError: # count was not a number, normally we would drop a log error # but that is out of scope here, so continue continue word, " " count # this IF-switch only works because Hadoop sorts # by key (here: word) before it is passed to the reducer # hence the single-host example using streaming pipe must add in # an explicit sort! if current_word == word: current_count += count else: if current_word: output # write result to STDOUT print(f'{current_word}\t{current_count}') current_count = count current_word = word # do not forget to output the last word if needed! if current_word == word: print(f'{current_word}\t{current_count}') $ cat beach_day.csv I ./mapper.py | sort -k1,1 | ./reducer.py "Accessory" "Camping" "Food" "Toy" 1 2
Pseudo Code:
1. For each record in my data set:
a. Inspect the column listed in the group by statement, and determine if we have found it previously,
b. If we have not then put it into a data structure which keeps track of keys and can associate values with them, such as a "map" (also called a hash, or dictionary) and put the aggregate function target (price) value into the value spot.
c. If we have seen it before, then take the value from our aggregate function target (again, price) and apply the function to it before replacing the new value with the one curently in the value spot of our map.
Transcribed Image Text:Pseudo Code: 1. For each record in my data set: a. Inspect the column listed in the group by statement, and determine if we have found it previously, b. If we have not then put it into a data structure which keeps track of keys and can associate values with them, such as a "map" (also called a hash, or dictionary) and put the aggregate function target (price) value into the value spot. c. If we have seen it before, then take the value from our aggregate function target (again, price) and apply the function to it before replacing the new value with the one curently in the value spot of our map.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Structured English
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education