Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How can we find tha maximum and minimum element of a column in a .csv.
What should we pass into context.write(key,value) of mapper.
Whether it is each column of that csv file?
Solution
This is a bit broad for an SO question but I'll bite.
Your mapper is for mapping values to keys. Lets say your CSV has 4 columns with numeric values:
42, 71, 45, 22
You map a key to each value; effectively what would be like the header in the CSV. Lets say column 4 represented "Number of widgets". You'd map "number_of_widgets" as the key to the value of column 4 in your mapper.
The reducer is going to get all the values for a given key. That's where you figure out your min/max. You just iterate though all the values for the key and keep track of the min and max.
Mapper should transpose the file - for each line read, emit the key as the column number and the value as the value of the column.
Reducer should min/max. For each input key, emit the min and max value found.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is there any Similarities between data type Dictionary and data type Array. If there are any what are them?
A dictionary maps strings to values.
An array maps integers to values.
That is about it!
So, seriously: in the end, both data structures map a "key set" to values. For dictionaries, the keys can of (almost) arbitrary type, without any constraint on them (besides being "hash able"). Whereas an array maps a consecutive range of ints to values.
From that point of view, arrays and dicts/maps are doing the same thing, but in the end, how you use them is very different.
And just for completeness: of course, the "underlying" similarity is that both are "containers": objects that "own" multiple other objects.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a text file that is in fixed width format, except each column has a different length. I have about 100 columns in all.
For example, the first few columns of text have the following width:
30
4
188
Let's assume I read in the first row from the file. How do I seperate/map the text into 100 different size columns?
We just dealt with this at work within the last few weeks. The way we went about solving the problem was to create an enum class with corresponding "indexes" to represent the start and end positions of the fields that needed to be extracted. This enum is loaded into a map of FIELD_NAME --> RANGE (i.e. 0:8) upon instantiation of the class that parses the message.
High-level, upon receipt of a message on the queue:
convert TextMessage to string
read line
for each field, get the corresponding range from the map
split the range on ":" to get the indexes
extract the values from the String using substring(index1,index2)
perform transformations (string to date, string to numbers, etc)
persist to database
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a column in a MySQL table calleddead_heat_flag which data type is smallint,
and I want to represent this column as one attribute in my Java class.
What data type should I use?
As per the comment below, for MySQL's smallint, java's short should cover that value range. Of course, you could also use an int, but keep in mind that it allows many values that the database column does not.
I believe the datatype equivalent would be a short based on what I found here for java and here for a db that uses smallint. They both address the same range of values.
Short in java is equivalent to small int as there range is same.It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive).
Refer this
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html for java
https://docs.oracle.com/cd/E19501-01/819-3659/gcmaz/ for database
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Suppose you have a string as input which has names separated by the underscore character. Write a program that outputs the same string after removing any duplicate names in it (retain first occurrence when multiple occurrences are present), and adds the number of times the name occurs, immediately after the name. For example, Tom_Dick_Harry_Joe_Dick_Chris becomes Tom1_Dick2_Harry1_Joe1_Chris1.
I will provide no code but the following might help :
Split the array with '_'
Maintain a Map<String,Integer> occurrences for counting the occurrences of each name and a List<String> apparitionOrder
For each word of the array :
if the word is in occurrences, increment the value associated to the key
else, put this name in the map associated with 0 and append it to apparitionOrder
Instantiate a new array of the size of apparitionOrder
Fill the new array accordingly to apparitionOrder and occurrences
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to write a function (logic) so that for a set say A{1,2,3,4,5} i generate a unique value .
and when i pass back the same value back to the function it should return me the set of values present in the set .
For example the unique value generated is say '5' then when i pass 5 as input to the function it should give me all the values of set A i.e 1,2,3,4,5.
So i need to know if it can be achieved using any statistical approach like mean median mode etc something like that .
Something like this?
$valSet = array(1, 2, 3, 4, 5);
$authNum = 5;
if($authNum == $someInputByUser)
{
print $varSet;
}
Is this what you mean?