Created
March 22, 2012 14:50
-
-
Save tf0054/2158755 to your computer and use it in GitHub Desktop.
Hack#38
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.hadoophacks.hive; | |
import org.apache.hadoop.hive.ql.exec.UDF; | |
import org.apache.hadoop.hive.serde2.io.DoubleWritable; | |
import java.util.*; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.io.IntWritable; | |
public class Multiply extends UDF{ | |
private DoubleWritable doubleResult = new DoubleWritable(0); | |
private Text textResult = new Text(""); | |
/* | |
public DoubleWritable evaluate(DoubleWritable a , DoubleWritable b){ | |
doubleResult.set(a.get() * b.get()); | |
return doubleResult; | |
} | |
*/ | |
public DoubleWritable evaluate(DoubleWritable... values){ | |
double result = 1; | |
for(DoubleWritable value : values){ | |
result *= value.get(); | |
} | |
doubleResult.set(result); | |
return doubleResult; | |
} | |
public Text evaluate(Text orig , IntWritable num){ | |
int counter = num.get(); | |
StringBuilder builder = new StringBuilder(); | |
String str = orig.toString(); | |
for(int i = 0;i < counter;i++){ | |
builder.append(str); | |
} | |
textResult.set(builder.toString()); | |
return textResult; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment