reduce

HADOOP - Reduce Phase Hangs on Simple MR Job

流过昼夜 提交于 2019-12-11 11:22:22
问题 Here is a simple map reduce job. Initially this is just a simple way of copying files in an input directory to an output directory. The Map phase completes, but the reduce phase just hangs. What am I doing wrong? It is a small amount of code, here is the whole job: import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.*; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org

Reverse list using map/reduce

北城余情 提交于 2019-12-11 10:50:06
问题 I am learning concepts of functional programming and trying out problem exercises. An exercise, Reverse a list using map/reduce. My solution: lists = [ 1, 2, 3, 5 ,6] def tree_reverse(lists): return reduce(lambda a, x: a + [a.insert(0,x)], lists, []) print tree_reverse(lists) Output: [6, 5, 3, 2, 1, None, None, None, None, None] I don't understand why there are Nones equal to number of elements in list. EDIT: Extending question for case of nested lists. lists = [ 1 ,2 ,3 , [5,6,7], 8, [9, 0,

JS (ES6): Reduce array based on object attribute

青春壹個敷衍的年華 提交于 2019-12-11 08:45:55
问题 I have an array like this: const fruits = [ { fruit: 'apple', year: 2018 }, { fruit: 'apple', year: 2018 }, { fruit: 'banana', year: 2018 }, { fruit: 'orange', year: 2018 }, { fruit: 'apple', year: 2017 }, { fruit: 'apple', year: 2016 } ]; Now I want to reduce this array to see how many fruits there are each year and how much the total is. So that the result looks like this: const result = [ { year: 2018, apple: 2, banana: 1, orange: 1 total: 4 }, { year: 2017, apple: 1, total: 1 }, { year:

How to use media queries correctly to reduce font size?

戏子无情 提交于 2019-12-11 06:47:29
问题 I'm trying to set my CSS so that font sizes decease when viewed on mobile devices. I've spent all day trying to figure this out, but am now stumped. I found media query code that I think should solve the issue, however it's not happening for me, font size remains standard size when viewing on mobile (Galaxy Nexus). html { font-size: 62.5%; } body { font-family:Arial,Helvetica,sans-serif; font-size: 1em; } @media (max-width: 300px) { html { font-size: 70%; } } @media (min-width: 500px) { html

Iterate through an Array of Objects and output custom object

我是研究僧i 提交于 2019-12-11 06:10:10
问题 I am needing to build a custom object from an array of objects in Typescript. In the giving example below, How do I count how many times the salesman_1_name is in the Array, Add the gross for each Salesman_1_name, and count if warranty is not null for each salesman_1_name? So if I have: [ {salesman_1_name:Brian, gross:100, warranty: Easycare}, {salesman_1_name:Brian, gross:100, warranty: Easycare}, {salesman_1_name:Brian, gross:100, warranty: null}, {salesman_1_name:Kreso, gross:100, warranty

How to use Reduce() function in R parallel computing?

*爱你&永不变心* 提交于 2019-12-11 05:32:29
问题 I want to run a Reduce code to out1 a list of 66000 list elements: trialStep1_done <- Reduce(rbind, out1) However, it takes too long to run. I wonder whether I can run this code with help of a parallel computing package. I know there is mclapply , mcMap , but I don't see any function like mcReduce in parallel computing package. Is there a function like mcReduce available for doing Reduce with parallel in R to complete the task I wanted to do? Thanks a lot @BrodieG and @zheYuan Li, your

Merge objects with the same id but sum values of the objects

夙愿已清 提交于 2019-12-11 05:26:11
问题 I want to reduce my array of objects by comparing previous and current object from the array, if the id of previous object is different then current object, then I write the previous object to my result list and override it with the current object else I sum the values of both objects. In the end it should be a reduced array, no duplicates. I have data like this: [{ Clicks: 210, Company: "A", _id: { CompanyID: 5 } }, { Clicks: 35, Company: "C", _id: { CompanyID: 3 } }, { Clicks: 15, Company:

TypeError: Cannot read property 'reduce' of undefined in react

狂风中的少年 提交于 2019-12-11 04:59:30
问题 I have a form in which I am asking the user to input field values for a couple of fields, storing the field values in an state and displaying the state values in a customised format. So, I have a couple of input fields and a submit button: <button onClick={this.handleSubmit}>Submit</button> { this.state.credentials && //<Credentials value={this.state}/> <Credentials value={JSON.stringify(this.state, undefined, 2)} /> } The Credentials function convert the state of the component in JSON format

Defining Parameters in JavaScript reduce

冷暖自知 提交于 2019-12-11 03:43:53
问题 I am looking at this reduce function in JavaScript . . . var colors = ['red', 'red', 'green', 'blue', 'green']; var distinctColors = colors.reduce( (distinct, color) => (distinct.indexOf(color) != -1) ? distinct : [...distinct, color], [] ) I understand that the callback function is called once for each item in the colors array, searching for the color string in distinct and simply returning the array if it is found, and adding color to distinct if not found. What I do not understand is how

Why python reduce() skip over the None element?

青春壹個敷衍的年華 提交于 2019-12-11 01:38:20
问题 I tried to get the home site of a url. Firstly I used a for loop and achieve the goal. home = '' my_url = 'http://www.mysite.com/subdir/subdir2/index.html' for item in my_url.split('/')[:3]: home += item + '/' print home and I can get 'http://www.mysite.com/' Then I come across reduce() which I had never used before. So I get it a shot,here is the code: my_url = 'http://www.mysite.com/subdir/subdir2/index.html' home = '' home = reduce(lambda x,y : x + y + '/',my_url.split('/')[:3]) print home