You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by zs...@apache.org on 2010/01/21 11:38:15 UTC
svn commit: r901644 [27/37] - in /hadoop/hive/trunk: ./
ql/src/java/org/apache/hadoop/hive/ql/
ql/src/java/org/apache/hadoop/hive/ql/exec/
ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/
ql/src/java/org/apache/hadoop/hive/ql/history/ ql/src/jav...
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java Thu Jan 21 10:37:58 2010
@@ -28,73 +28,82 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
-@description(
- name = "%",
- value = "a _FUNC_ b - Returns the remainder when dividing a by b"
-)
+@description(name = "%", value = "a _FUNC_ b - Returns the remainder when dividing a by b")
public class UDFOPMod extends UDFBaseNumericOp {
- private static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.udf.UDFOPMod");
+ private static Log LOG = LogFactory
+ .getLog("org.apache.hadoop.hive.ql.udf.UDFOPMod");
public UDFOPMod() {
}
-
@Override
- public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- byteWritable.set((byte)(a.get() % b.get()));
+ byteWritable.set((byte) (a.get() % b.get()));
return byteWritable;
}
@Override
- public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- shortWritable.set((short)(a.get() % b.get()));
+ shortWritable.set((short) (a.get() % b.get()));
return shortWritable;
}
@Override
- public IntWritable evaluate(IntWritable a, IntWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public IntWritable evaluate(IntWritable a, IntWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- intWritable.set((int)(a.get() % b.get()));
+ intWritable.set((a.get() % b.get()));
return intWritable;
}
@Override
- public LongWritable evaluate(LongWritable a, LongWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public LongWritable evaluate(LongWritable a, LongWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
longWritable.set(a.get() % b.get());
return longWritable;
}
@Override
- public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
floatWritable.set(a.get() % b.get());
return floatWritable;
}
-
+
@Override
- public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
doubleWritable.set(a.get() % b.get());
return doubleWritable;
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java Thu Jan 21 10:37:58 2010
@@ -28,72 +28,82 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
-@description(
- name = "*",
- value = "a _FUNC_ b - Multiplies a by b"
-)
+@description(name = "*", value = "a _FUNC_ b - Multiplies a by b")
public class UDFOPMultiply extends UDFBaseNumericOp {
- private static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.udf.UDFOPMultiply");
+ private static Log LOG = LogFactory
+ .getLog("org.apache.hadoop.hive.ql.udf.UDFOPMultiply");
public UDFOPMultiply() {
}
@Override
- public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- byteWritable.set((byte)(a.get() * b.get()));
+ byteWritable.set((byte) (a.get() * b.get()));
return byteWritable;
}
@Override
- public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- shortWritable.set((short)(a.get() * b.get()));
+ shortWritable.set((short) (a.get() * b.get()));
return shortWritable;
}
@Override
- public IntWritable evaluate(IntWritable a, IntWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public IntWritable evaluate(IntWritable a, IntWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- intWritable.set((int)(a.get() * b.get()));
+ intWritable.set((a.get() * b.get()));
return intWritable;
}
@Override
- public LongWritable evaluate(LongWritable a, LongWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public LongWritable evaluate(LongWritable a, LongWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
longWritable.set(a.get() * b.get());
return longWritable;
}
@Override
- public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
floatWritable.set(a.get() * b.get());
return floatWritable;
}
-
+
@Override
- public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
doubleWritable.set(a.get() * b.get());
return doubleWritable;
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java Thu Jan 21 10:37:58 2010
@@ -20,7 +20,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.hive.serde2.io.ByteWritable;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
@@ -28,12 +27,8 @@
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
-import org.apache.hadoop.io.NullWritable;
-@description(
- name = "-",
- value = "_FUNC_ a - Returns -a"
-)
+@description(name = "-", value = "_FUNC_ a - Returns -a")
public class UDFOPNegative extends UDFBaseNumericUnaryOp {
private static Log LOG = LogFactory.getLog(UDFOPNegative.class.getName());
@@ -43,25 +38,25 @@
@Override
public ByteWritable evaluate(ByteWritable a) {
- if ( a == null ) {
+ if (a == null) {
return null;
}
- byteWritable.set((byte)-a.get());
+ byteWritable.set((byte) -a.get());
return byteWritable;
}
@Override
public ShortWritable evaluate(ShortWritable a) {
- if ( a == null ) {
+ if (a == null) {
return null;
}
- shortWritable.set((short)-a.get());
+ shortWritable.set((short) -a.get());
return shortWritable;
}
@Override
public IntWritable evaluate(IntWritable a) {
- if ( a == null ) {
+ if (a == null) {
return null;
}
intWritable.set(-a.get());
@@ -70,7 +65,7 @@
@Override
public LongWritable evaluate(LongWritable a) {
- if ( a == null ) {
+ if (a == null) {
return null;
}
longWritable.set(-a.get());
@@ -79,7 +74,7 @@
@Override
public FloatWritable evaluate(FloatWritable a) {
- if ( a == null ) {
+ if (a == null) {
return null;
}
floatWritable.set(-a.get());
@@ -88,12 +83,11 @@
@Override
public DoubleWritable evaluate(DoubleWritable a) {
- if ( a == null ) {
+ if (a == null) {
return null;
}
doubleWritable.set(-a.get());
return doubleWritable;
}
-
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNot.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNot.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNot.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNot.java Thu Jan 21 10:37:58 2010
@@ -24,20 +24,19 @@
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.io.BooleanWritable;
-@description(
- name = "not,!",
- value = "_FUNC_ a - Logical not"
-)
+@description(name = "not,!", value = "_FUNC_ a - Logical not")
public class UDFOPNot extends UDF {
- private static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.udf.UDFOPNot");
+ private static Log LOG = LogFactory
+ .getLog("org.apache.hadoop.hive.ql.udf.UDFOPNot");
BooleanWritable result = new BooleanWritable();
+
public UDFOPNot() {
}
// Three-value Boolean: NULL stands for unknown
- public BooleanWritable evaluate(BooleanWritable a) {
+ public BooleanWritable evaluate(BooleanWritable a) {
if (a == null) {
return null;
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNotEqual.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNotEqual.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNotEqual.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNotEqual.java Thu Jan 21 10:37:58 2010
@@ -30,21 +30,19 @@
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
-@description(
- name = "<>",
- value = "a _FUNC_ b - Returns TRUE if a is not equal to b"
-)
+@description(name = "<>", value = "a _FUNC_ b - Returns TRUE if a is not equal to b")
public class UDFOPNotEqual extends UDFBaseCompare {
private static Log LOG = LogFactory.getLog(UDFOPNotEqual.class.getName());
BooleanWritable resultCache;
+
public UDFOPNotEqual() {
resultCache = new BooleanWritable();
}
- public BooleanWritable evaluate(Text a, Text b) {
- BooleanWritable r = this.resultCache;
+ public BooleanWritable evaluate(Text a, Text b) {
+ BooleanWritable r = resultCache;
if ((a == null) || (b == null)) {
r = null;
} else {
@@ -54,8 +52,8 @@
return r;
}
- public BooleanWritable evaluate(ByteWritable a, ByteWritable b) {
- BooleanWritable r = this.resultCache;
+ public BooleanWritable evaluate(ByteWritable a, ByteWritable b) {
+ BooleanWritable r = resultCache;
if ((a == null) || (b == null)) {
r = null;
} else {
@@ -65,8 +63,8 @@
return r;
}
- public BooleanWritable evaluate(ShortWritable a, ShortWritable b) {
- BooleanWritable r = this.resultCache;
+ public BooleanWritable evaluate(ShortWritable a, ShortWritable b) {
+ BooleanWritable r = resultCache;
if ((a == null) || (b == null)) {
r = null;
} else {
@@ -76,8 +74,8 @@
return r;
}
- public BooleanWritable evaluate(IntWritable a, IntWritable b) {
- BooleanWritable r = this.resultCache;
+ public BooleanWritable evaluate(IntWritable a, IntWritable b) {
+ BooleanWritable r = resultCache;
if ((a == null) || (b == null)) {
r = null;
} else {
@@ -86,9 +84,9 @@
// LOG.info("evaluate(" + a + "," + b + ")=" + r);
return r;
}
-
- public BooleanWritable evaluate(LongWritable a, LongWritable b) {
- BooleanWritable r = this.resultCache;
+
+ public BooleanWritable evaluate(LongWritable a, LongWritable b) {
+ BooleanWritable r = resultCache;
if ((a == null) || (b == null)) {
r = null;
} else {
@@ -97,9 +95,9 @@
// LOG.info("evaluate(" + a + "," + b + ")=" + r);
return r;
}
-
- public BooleanWritable evaluate(FloatWritable a, FloatWritable b) {
- BooleanWritable r = this.resultCache;
+
+ public BooleanWritable evaluate(FloatWritable a, FloatWritable b) {
+ BooleanWritable r = resultCache;
if ((a == null) || (b == null)) {
r = null;
} else {
@@ -107,10 +105,11 @@
}
// LOG.info("evaluate(" + a + "," + b + ")=" + r);
return r;
- }
+ }
- public BooleanWritable evaluate(DoubleWritable a, DoubleWritable b) {
- BooleanWritable r = this.resultCache;
+ @Override
+ public BooleanWritable evaluate(DoubleWritable a, DoubleWritable b) {
+ BooleanWritable r = resultCache;
if ((a == null) || (b == null)) {
r = null;
} else {
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPOr.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPOr.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPOr.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPOr.java Thu Jan 21 10:37:58 2010
@@ -24,20 +24,18 @@
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.io.BooleanWritable;
-@description(
- name = "or",
- value = "a _FUNC_ b - Logical or"
-)
+@description(name = "or", value = "a _FUNC_ b - Logical or")
public class UDFOPOr extends UDF {
private static Log LOG = LogFactory.getLog(UDFOPOr.class.getName());
BooleanWritable result = new BooleanWritable();
+
public UDFOPOr() {
}
// Three-value Boolean: NULL stands for unknown
- public BooleanWritable evaluate(BooleanWritable a, BooleanWritable b) {
+ public BooleanWritable evaluate(BooleanWritable a, BooleanWritable b) {
if ((a != null && a.get() == true) || (b != null && b.get() == true)) {
result.set(true);
return result;
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java Thu Jan 21 10:37:58 2010
@@ -28,82 +28,91 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
-
/**
- * The reason that we list evaluate methods with all numeric types is for
- * both better performance and type checking (so we know int + int is still an int
- * instead of a double); otherwise a single method that takes (Number a, Number b)
- * and use a.doubleValue() == b.doubleValue() is enough.
+ * The reason that we list evaluate methods with all numeric types is for both
+ * better performance and type checking (so we know int + int is still an int
+ * instead of a double); otherwise a single method that takes (Number a, Number
+ * b) and use a.doubleValue() == b.doubleValue() is enough.
*
- * The case of int + double will be handled by implicit type casting using
- * UDFRegistry.implicitConvertable method.
+ * The case of int + double will be handled by implicit type casting using
+ * UDFRegistry.implicitConvertable method.
*/
-@description(
- name = "+",
- value = "a _FUNC_ b - Returns a+b"
-)
+@description(name = "+", value = "a _FUNC_ b - Returns a+b")
public class UDFOPPlus extends UDFBaseNumericOp {
- private static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.udf.UDFOPPlus");
+ private static Log LOG = LogFactory
+ .getLog("org.apache.hadoop.hive.ql.udf.UDFOPPlus");
public UDFOPPlus() {
}
@Override
- public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- byteWritable.set((byte)(a.get() + b.get()));
+ byteWritable.set((byte) (a.get() + b.get()));
return byteWritable;
}
@Override
- public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- shortWritable.set((short)(a.get() + b.get()));
+ shortWritable.set((short) (a.get() + b.get()));
return shortWritable;
}
@Override
- public IntWritable evaluate(IntWritable a, IntWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public IntWritable evaluate(IntWritable a, IntWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- intWritable.set((int)(a.get() + b.get()));
+ intWritable.set((a.get() + b.get()));
return intWritable;
}
@Override
- public LongWritable evaluate(LongWritable a, LongWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public LongWritable evaluate(LongWritable a, LongWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
longWritable.set(a.get() + b.get());
return longWritable;
}
@Override
- public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
floatWritable.set(a.get() + b.get());
return floatWritable;
}
-
+
@Override
- public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
doubleWritable.set(a.get() + b.get());
return doubleWritable;
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPositive.java Thu Jan 21 10:37:58 2010
@@ -20,7 +20,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.hive.serde2.io.ByteWritable;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
@@ -29,10 +28,7 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
-@description(
- name = "positive",
- value = "_FUNC_ a - Returns a"
-)
+@description(name = "positive", value = "_FUNC_ a - Returns a")
public class UDFOPPositive extends UDFBaseNumericUnaryOp {
private static Log LOG = LogFactory.getLog(UDFOPPositive.class.getName());
@@ -40,7 +36,6 @@
public UDFOPPositive() {
}
-
@Override
public ByteWritable evaluate(ByteWritable a) {
return a;
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFParseUrl.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFParseUrl.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFParseUrl.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFParseUrl.java Thu Jan 21 10:37:58 2010
@@ -27,10 +27,6 @@
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.exec.description;
-
-
-
-
/**
* UDF to extract specfic parts from URL For example,
* parse_url('http://facebook.com/path/p1.php?query=1', 'HOST') will return
@@ -44,22 +40,17 @@
* HOST,PATH,QUERY,REF,PROTOCOL,AUTHORITY,FILE,USERINFO Also you can get a value
* of particular key in QUERY, using syntax QUERY:<KEY_NAME> eg: QUERY:k1.
*/
-@description(
- name = "parse_url",
- value = "_FUNC_(url, partToExtract[, key]) - extracts a part from a URL",
- extended = "Parts: HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, " +
- "USERINFO\nkey specifies which query to extract\n" +
- "Example:\n" +
- " > SELECT _FUNC_('http://facebook.com/path/p1.php?query=1', " +
- "'HOST') FROM src LIMIT 1;\n" +
- " 'facebook.com'\n" +
- " > SELECT _FUNC_('http://facebook.com/path/p1.php?query=1', " +
- "'QUERY') FROM src LIMIT 1;\n" +
- " 'query=1'\n" +
- " > SELECT _FUNC_('http://facebook.com/path/p1.php?query=1', " +
- "'QUERY', 'query') FROM src LIMIT 1;\n" +
- " '1'"
- )
+@description(name = "parse_url", value = "_FUNC_(url, partToExtract[, key]) - extracts a part from a URL", extended = "Parts: HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, "
+ + "USERINFO\nkey specifies which query to extract\n"
+ + "Example:\n"
+ + " > SELECT _FUNC_('http://facebook.com/path/p1.php?query=1', "
+ + "'HOST') FROM src LIMIT 1;\n"
+ + " 'facebook.com'\n"
+ + " > SELECT _FUNC_('http://facebook.com/path/p1.php?query=1', "
+ + "'QUERY') FROM src LIMIT 1;\n"
+ + " 'query=1'\n"
+ + " > SELECT _FUNC_('http://facebook.com/path/p1.php?query=1', "
+ + "'QUERY', 'query') FROM src LIMIT 1;\n" + " '1'")
public class UDFParseUrl extends UDF {
private static Log LOG = LogFactory.getLog(UDFParseUrl.class.getName());
@@ -67,7 +58,6 @@
private URL url = null;
private Pattern p = null;
private String lastKey = null;
-
public UDFParseUrl() {
}
@@ -86,42 +76,51 @@
}
lastUrlStr = urlStr;
- if (partToExtract.equals("HOST"))
+ if (partToExtract.equals("HOST")) {
return url.getHost();
- if (partToExtract.equals("PATH"))
+ }
+ if (partToExtract.equals("PATH")) {
return url.getPath();
- if (partToExtract.equals("QUERY"))
+ }
+ if (partToExtract.equals("QUERY")) {
return url.getQuery();
- if (partToExtract.equals("REF"))
+ }
+ if (partToExtract.equals("REF")) {
return url.getRef();
- if (partToExtract.equals("PROTOCOL"))
+ }
+ if (partToExtract.equals("PROTOCOL")) {
return url.getProtocol();
- if (partToExtract.equals("FILE"))
+ }
+ if (partToExtract.equals("FILE")) {
return url.getFile();
- if (partToExtract.equals("AUTHORITY"))
+ }
+ if (partToExtract.equals("AUTHORITY")) {
return url.getAuthority();
- if (partToExtract.equals("USERINFO"))
+ }
+ if (partToExtract.equals("USERINFO")) {
return url.getUserInfo();
+ }
return null;
}
public String evaluate(String urlStr, String partToExtract, String key) {
- if (!partToExtract.equals("QUERY"))
+ if (!partToExtract.equals("QUERY")) {
return null;
+ }
String query = this.evaluate(urlStr, partToExtract);
- if (query == null)
+ if (query == null) {
return null;
+ }
-
- if (!key.equals(lastKey)){
- p = Pattern.compile("(&|^)"+key+"=([^&]*)");
+ if (!key.equals(lastKey)) {
+ p = Pattern.compile("(&|^)" + key + "=([^&]*)");
}
-
+
lastKey = key;
Matcher m = p.matcher(query);
- if (m.find()){
+ if (m.find()) {
return m.group(2);
}
return null;
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java Thu Jan 21 10:37:58 2010
@@ -28,80 +28,87 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
-
/**
- * class for computing positive modulo.
- * Used for positive_mod command in Cli
- * See {org.apache.hadoop.hive.ql.udf.UDFOPMod}
- * See {org.apache.hadoop.hive.ql.exec.FunctionRegistry}
+ * class for computing positive modulo. Used for positive_mod command in Cli See
+ * {org.apache.hadoop.hive.ql.udf.UDFOPMod} See
+ * {org.apache.hadoop.hive.ql.exec.FunctionRegistry}
*/
-@description(
- name = "pmod",
- value = "a _FUNC_ b - Compute the positive modulo"
-)
+@description(name = "pmod", value = "a _FUNC_ b - Compute the positive modulo")
public class UDFPosMod extends UDFBaseNumericOp {
- private static Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.udf.UDFPosMod");
+ private static Log LOG = LogFactory
+ .getLog("org.apache.hadoop.hive.ql.udf.UDFPosMod");
public UDFPosMod() {
}
-
@Override
- public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- byteWritable.set((byte)(((a.get() % b.get()) + b.get()) % b.get()));
+ byteWritable.set((byte) (((a.get() % b.get()) + b.get()) % b.get()));
return byteWritable;
}
@Override
- public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- shortWritable.set((short)(((a.get() % b.get()) + b.get()) % b.get()));
+ shortWritable.set((short) (((a.get() % b.get()) + b.get()) % b.get()));
return shortWritable;
}
@Override
- public IntWritable evaluate(IntWritable a, IntWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public IntWritable evaluate(IntWritable a, IntWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
- intWritable.set((int)(((a.get() % b.get()) + b.get()) % b.get()));
+ intWritable.set((((a.get() % b.get()) + b.get()) % b.get()));
return intWritable;
}
@Override
- public LongWritable evaluate(LongWritable a, LongWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public LongWritable evaluate(LongWritable a, LongWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
longWritable.set(((a.get() % b.get()) + b.get()) % b.get());
return longWritable;
}
@Override
- public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
floatWritable.set(((a.get() % b.get()) + b.get()) % b.get());
return floatWritable;
}
-
+
@Override
- public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
- // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b);
- if ((a == null) || (b == null))
+ public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
+ // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
+ // + b);
+ if ((a == null) || (b == null)) {
return null;
+ }
doubleWritable.set(((a.get() % b.get()) + b.get()) % b.get());
return doubleWritable;
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java Thu Jan 21 10:37:58 2010
@@ -24,25 +24,21 @@
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
-@description(
- name = "power,pow",
- value = "_FUNC_(x1, x2) - raise x1 to the power of x2",
- extended = "Example:\n" +
- " > SELECT _FUNC_(2, 3) FROM src LIMIT 1;\n" +
- " 8"
- )
+@description(name = "power,pow", value = "_FUNC_(x1, x2) - raise x1 to the power of x2", extended = "Example:\n"
+ + " > SELECT _FUNC_(2, 3) FROM src LIMIT 1;\n" + " 8")
public class UDFPower extends UDF {
private static Log LOG = LogFactory.getLog(UDFPower.class.getName());
DoubleWritable result = new DoubleWritable();
+
public UDFPower() {
}
/**
- * Raise a to the power of b.
+ * Raise a to the power of b.
*/
- public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
+ public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
if (a == null || b == null) {
return null;
} else {
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRTrim.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRTrim.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRTrim.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRTrim.java Thu Jan 21 10:37:58 2010
@@ -18,24 +18,17 @@
package org.apache.hadoop.hive.ql.udf;
+import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.io.Text;
-import org.apache.commons.lang.StringUtils;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-@description(
- name = "rtrim",
- value = "_FUNC_(str) - Removes the trailing space characters from str ",
- extended = "Example:\n" +
- " > SELECT _FUNC_('facebook ') FROM src LIMIT 1;\n" +
- " 'facebook'"
- )
+@description(name = "rtrim", value = "_FUNC_(str) - Removes the trailing space characters from str ", extended = "Example:\n"
+ + " > SELECT _FUNC_('facebook ') FROM src LIMIT 1;\n" + " 'facebook'")
public class UDFRTrim extends UDF {
Text result = new Text();
+
public UDFRTrim() {
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRand.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRand.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRand.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRand.java Thu Jan 21 10:37:58 2010
@@ -27,22 +27,20 @@
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
-@description(
- name = "rand",
- value = "_FUNC_([seed]) - Returns a pseudorandom number between 0 and 1"
-)
-@UDFType(deterministic=false)
+@description(name = "rand", value = "_FUNC_([seed]) - Returns a pseudorandom number between 0 and 1")
+@UDFType(deterministic = false)
public class UDFRand extends UDF {
private static Log LOG = LogFactory.getLog(UDFRand.class.getName());
private Random random;
-
+
DoubleWritable result = new DoubleWritable();
+
public UDFRand() {
}
- public DoubleWritable evaluate() {
+ public DoubleWritable evaluate() {
if (random == null) {
random = new Random();
}
@@ -50,7 +48,7 @@
return result;
}
- public DoubleWritable evaluate(LongWritable seed) {
+ public DoubleWritable evaluate(LongWritable seed) {
if (random == null) {
random = new Random(seed.get());
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExp.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExp.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExp.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExp.java Thu Jan 21 10:37:58 2010
@@ -18,6 +18,9 @@
package org.apache.hadoop.hive.ql.udf;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.UDF;
@@ -25,26 +28,19 @@
import org.apache.hadoop.io.BooleanWritable;
import org.apache.hadoop.io.Text;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-@description(
- name = "rlike,regexp",
- value = "str _FUNC_ regexp - Returns true if str matches regexp and " +
- "false otherwise",
- extended = "Example:\n" +
- " > SELECT 'fb' _FUNC_ '.*' FROM src LIMIT 1;\n" +
- " true"
- )
+@description(name = "rlike,regexp", value = "str _FUNC_ regexp - Returns true if str matches regexp and "
+ + "false otherwise", extended = "Example:\n"
+ + " > SELECT 'fb' _FUNC_ '.*' FROM src LIMIT 1;\n" + " true")
public class UDFRegExp extends UDF {
static final Log LOG = LogFactory.getLog(UDFRegExp.class.getName());
-
- private Text lastRegex = new Text();
+
+ private final Text lastRegex = new Text();
private Pattern p = null;
boolean warned = false;
BooleanWritable result = new BooleanWritable();
+
public UDFRegExp() {
}
@@ -52,11 +48,11 @@
if (s == null || regex == null) {
return null;
}
- if(regex.getLength()==0) {
- if(!warned) {
+ if (regex.getLength() == 0) {
+ if (!warned) {
warned = true;
- LOG.warn(getClass().getSimpleName() + " regex is empty. Additional " +
- "warnings for an empty regex will be suppressed.");
+ LOG.warn(getClass().getSimpleName() + " regex is empty. Additional "
+ + "warnings for an empty regex will be suppressed.");
}
result.set(false);
return result;
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExpExtract.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExpExtract.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExpExtract.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExpExtract.java Thu Jan 21 10:37:58 2010
@@ -28,25 +28,22 @@
import org.apache.hadoop.hive.ql.exec.description;
/**
- * UDF to extract a specific group identified by a java regex.
- * Note that if a regexp has a backslash ('\'), then need to specify '\\'
- * For example, regexp_extract('100-200', '(\\d+)-(\\d+)', 1) will return '100'
+ * UDF to extract a specific group identified by a java regex. Note that if a
+ * regexp has a backslash ('\'), then need to specify '\\' For example,
+ * regexp_extract('100-200', '(\\d+)-(\\d+)', 1) will return '100'
*/
-@description(
- name = "regexp_extract",
- value = "_FUNC_(str, regexp[, idx]) - extracts a group that matches regexp",
- extended = "Example:\n" +
- " > SELECT _FUNC_('100-200', '(\\d+)-(\\d+)', 1) FROM src LIMIT 1;\n" +
- " '100'"
- )
+@description(name = "regexp_extract", value = "_FUNC_(str, regexp[, idx]) - extracts a group that matches regexp", extended = "Example:\n"
+ + " > SELECT _FUNC_('100-200', '(\\d+)-(\\d+)', 1) FROM src LIMIT 1;\n"
+ + " '100'")
public class UDFRegExpExtract extends UDF {
private static Log LOG = LogFactory.getLog(UDFRegExpExtract.class.getName());
private String lastRegex = null;
private Pattern p = null;
+
public UDFRegExpExtract() {
}
-
+
public String evaluate(String s, String regex, Integer extractIndex) {
if (s == null || regex == null) {
return null;
@@ -67,5 +64,4 @@
return this.evaluate(s, regex, 1);
}
-
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExpReplace.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExpReplace.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExpReplace.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRegExpReplace.java Thu Jan 21 10:37:58 2010
@@ -18,30 +18,27 @@
package org.apache.hadoop.hive.ql.udf;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.io.Text;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-@description(
- name = "regexp_replace",
- value = "_FUNC_(str, regexp, rep) - replace all substrings of str that " +
- "match regexp with rep",
- extended = "Example:\n" +
- " > SELECT _FUNC_('100-200', '(\\d+)', 'num') FROM src LIMIT 1;\n" +
- " 'num-num'"
- )
+@description(name = "regexp_replace", value = "_FUNC_(str, regexp, rep) - replace all substrings of str that "
+ + "match regexp with rep", extended = "Example:\n"
+ + " > SELECT _FUNC_('100-200', '(\\d+)', 'num') FROM src LIMIT 1;\n"
+ + " 'num-num'")
public class UDFRegExpReplace extends UDF {
- private Text lastRegex = new Text();
+ private final Text lastRegex = new Text();
private Pattern p = null;
-
- private Text lastReplacement = new Text();
- private String replacementString = "";
+
+ private final Text lastReplacement = new Text();
+ private String replacementString = "";
Text result = new Text();
+
public UDFRegExpReplace() {
}
@@ -60,15 +57,15 @@
lastReplacement.set(replacement);
replacementString = replacement.toString();
}
-
+
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, replacementString);
}
m.appendTail(sb);
-
+
result.set(sb.toString());
- return result;
+ return result;
}
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRepeat.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRepeat.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRepeat.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRepeat.java Thu Jan 21 10:37:58 2010
@@ -18,45 +18,38 @@
package org.apache.hadoop.hive.ql.udf;
-import java.util.Arrays;
-
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
-@description(
- name = "repeat",
- value = "_FUNC_(str, n) - repeat str n times ",
- extended = "Example:\n" +
- " > SELECT _FUNC_('123', 2) FROM src LIMIT 1;\n" +
- " '123123'"
- )
-public class UDFRepeat extends UDF {
- private Text result = new Text();
-
+@description(name = "repeat", value = "_FUNC_(str, n) - repeat str n times ", extended = "Example:\n"
+ + " > SELECT _FUNC_('123', 2) FROM src LIMIT 1;\n" + " '123123'")
+public class UDFRepeat extends UDF {
+ private final Text result = new Text();
+
public Text evaluate(Text s, IntWritable n) {
if (n == null || s == null) {
return null;
}
-
- int len = n.get()*s.getLength();
- if(len < 0) {
+
+ int len = n.get() * s.getLength();
+ if (len < 0) {
len = 0;
}
-
+
byte[] data = result.getBytes();
-
- if(data.length < len) {
+
+ if (data.length < len) {
data = new byte[len];
}
-
- for(int i = 0; i < len; i += s.getLength()) {
- for(int j = 0; j < s.getLength(); j++) {
- data[i + j] = s.getBytes()[j];
+
+ for (int i = 0; i < len; i += s.getLength()) {
+ for (int j = 0; j < s.getLength(); j++) {
+ data[i + j] = s.getBytes()[j];
}
}
-
+
result.set(data, 0, len);
return result;
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFReverse.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFReverse.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFReverse.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFReverse.java Thu Jan 21 10:37:58 2010
@@ -23,53 +23,51 @@
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFUtils;
import org.apache.hadoop.io.Text;
-@description(
- name = "reverse",
- value = "_FUNC_(str) - reverse str",
- extended = "Example:\n" +
- " > SELECT _FUNC_('Facebook') FROM src LIMIT 1;\n" +
- " 'koobecaF'"
- )
-public class UDFReverse extends UDF {
- private Text result = new Text();
-
+@description(name = "reverse", value = "_FUNC_(str) - reverse str", extended = "Example:\n"
+ + " > SELECT _FUNC_('Facebook') FROM src LIMIT 1;\n" + " 'koobecaF'")
+public class UDFReverse extends UDF {
+ private final Text result = new Text();
+
/**
* Reverse a portion of an array in-place.
*
- * @param arr The array where the data will be reversed.
- * @param first The beginning of the portion (inclusive).
- * @param last The end of the portion (inclusive).
+ * @param arr
+ * The array where the data will be reversed.
+ * @param first
+ * The beginning of the portion (inclusive).
+ * @param last
+ * The end of the portion (inclusive).
*/
private void reverse(byte[] arr, int first, int last) {
- for(int i = 0; i < (last-first+1)/2; i++) {
+ for (int i = 0; i < (last - first + 1) / 2; i++) {
byte temp = arr[last - i];
arr[last - i] = arr[first + i];
arr[first + i] = temp;
}
}
-
+
public Text evaluate(Text s) {
if (s == null) {
return null;
}
-
+
// set() will only allocate memory if the buffer of result is smaller than
// s.getLength() and will never resize the buffer down.
result.set(s);
-
+
// Now do an in-place reversal in result.getBytes(). First, reverse every
// character, then reverse the whole string.
byte[] data = result.getBytes();
int prev = 0; // The index where the current char starts
- for(int i = 1; i < result.getLength(); i++) {
- if( GenericUDFUtils.isUtfStartByte(data[i]) ) {
- reverse(data, prev, i-1);
+ for (int i = 1; i < result.getLength(); i++) {
+ if (GenericUDFUtils.isUtfStartByte(data[i])) {
+ reverse(data, prev, i - 1);
prev = i;
}
}
reverse(data, prev, result.getLength() - 1);
reverse(data, 0, result.getLength() - 1);
-
+
return result;
}
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java Thu Jan 21 10:37:58 2010
@@ -27,18 +27,13 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
-@description(
- name = "round",
- value = "_FUNC_(x[, d]) - round x to d decimal places",
- extended = "Example:\n" +
- " > SELECT _FUNC_(12.3456, 1) FROM src LIMIT 1;\n" +
- " 12.3'"
- )
+@description(name = "round", value = "_FUNC_(x[, d]) - round x to d decimal places", extended = "Example:\n"
+ + " > SELECT _FUNC_(12.3456, 1) FROM src LIMIT 1;\n" + " 12.3'")
public class UDFRound extends UDF {
DoubleWritable doubleWritable = new DoubleWritable();
LongWritable longWritable = new LongWritable();
-
+
public UDFRound() {
}
@@ -46,7 +41,8 @@
if (n == null) {
return null;
}
- longWritable.set(BigDecimal.valueOf(n.get()).setScale(0, RoundingMode.HALF_UP).longValue());
+ longWritable.set(BigDecimal.valueOf(n.get()).setScale(0,
+ RoundingMode.HALF_UP).longValue());
return longWritable;
}
@@ -54,8 +50,9 @@
if ((n == null) || (i == null)) {
return null;
}
- doubleWritable.set(BigDecimal.valueOf(n.get()).setScale(i.get(), RoundingMode.HALF_UP).doubleValue());
+ doubleWritable.set(BigDecimal.valueOf(n.get()).setScale(i.get(),
+ RoundingMode.HALF_UP).doubleValue());
return doubleWritable;
}
-
+
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRpad.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRpad.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRpad.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRpad.java Thu Jan 21 10:37:58 2010
@@ -23,52 +23,46 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
+@description(name = "rpad", value = "_FUNC_(str, len, pad) - Returns str, right-padded with pad to a "
+ + "length of len", extended = "If str is longer than len, the return value is shortened to "
+ + "len characters.\n"
+ + "Example:\n"
+ + " > SELECT _FUNC_('hi', 5, '??') FROM src LIMIT 1;\n"
+ + " 'hi???'"
+ + " > SELECT _FUNC_('hi', 1, '??') FROM src LIMIT 1;\n" + " 'h'")
+public class UDFRpad extends UDF {
+
+ private final Text result = new Text();
-@description(
- name = "rpad",
- value = "_FUNC_(str, len, pad) - Returns str, right-padded with pad to a " +
- "length of len",
- extended = "If str is longer than len, the return value is shortened to " +
- "len characters.\n" +
- "Example:\n" +
- " > SELECT _FUNC_('hi', 5, '??') FROM src LIMIT 1;\n" +
- " 'hi???'" +
- " > SELECT _FUNC_('hi', 1, '??') FROM src LIMIT 1;\n" +
- " 'h'"
- )
-public class UDFRpad extends UDF {
-
- private Text result = new Text();
-
public Text evaluate(Text s, IntWritable n, Text pad) {
if (s == null || n == null || pad == null) {
return null;
}
-
+
int len = n.get();
-
+
byte[] data = result.getBytes();
- if(data.length < len) {
+ if (data.length < len) {
data = new byte[len];
}
-
+
byte[] txt = s.getBytes();
byte[] padTxt = pad.getBytes();
-
+
int pos;
// Copy the text
- for(pos = 0; pos < s.getLength() && pos < len; pos++) {
+ for (pos = 0; pos < s.getLength() && pos < len; pos++) {
data[pos] = txt[pos];
}
-
+
// Copy the padding
- while(pos < len) {
- for(int i = 0; i < pad.getLength() && i < len-pos; i++) {
- data[pos+i] = padTxt[i];
+ while (pos < len) {
+ for (int i = 0; i < pad.getLength() && i < len - pos; i++) {
+ data[pos + i] = padTxt[i];
}
pos += pad.getLength();
}
-
+
result.set(data, 0, len);
return result;
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java Thu Jan 21 10:37:58 2010
@@ -30,41 +30,41 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
-@description(
- name = "second",
- value = "_FUNC_(date) - Returns the second of date",
- extended = "date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or " +
- "'HH:mm:ss'.\n" +
- "Example:\n " +
- " > SELECT _FUNC_('2009-07-30 12:58:59') FROM src LIMIT 1;\n" +
- " 59\n" +
- " > SELECT _FUNC_('12:58:59') FROM src LIMIT 1;\n" +
- " 59"
- )
+@description(name = "second", value = "_FUNC_(date) - Returns the second of date", extended = "date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or "
+ + "'HH:mm:ss'.\n"
+ + "Example:\n "
+ + " > SELECT _FUNC_('2009-07-30 12:58:59') FROM src LIMIT 1;\n"
+ + " 59\n"
+ + " > SELECT _FUNC_('12:58:59') FROM src LIMIT 1;\n" + " 59")
public class UDFSecond extends UDF {
private static Log LOG = LogFactory.getLog(UDFSecond.class.getName());
- private SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- private SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");
- private Calendar calendar = Calendar.getInstance();
+ private final SimpleDateFormat formatter1 = new SimpleDateFormat(
+ "yyyy-MM-dd HH:mm:ss");
+ private final SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");
+ private final Calendar calendar = Calendar.getInstance();
IntWritable result = new IntWritable();
+
public UDFSecond() {
}
/**
* Get the minute from a date string.
*
- * @param dateString the dateString in the format of "yyyy-MM-dd HH:mm:ss" or "yyyy-MM-dd".
- * @return an int from 0 to 59. null if the dateString is not a valid date string.
+ * @param dateString
+ * the dateString in the format of "yyyy-MM-dd HH:mm:ss" or
+ * "yyyy-MM-dd".
+ * @return an int from 0 to 59. null if the dateString is not a valid date
+ * string.
*/
- public IntWritable evaluate(Text dateString) {
-
+ public IntWritable evaluate(Text dateString) {
+
if (dateString == null) {
return null;
}
-
+
try {
Date date = null;
try {
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSin.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSin.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSin.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSin.java Thu Jan 21 10:37:58 2010
@@ -24,26 +24,21 @@
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
-@description(
- name = "sin",
- value = "_FUNC_(x) - returns the sine of x (x is in radians)",
- extended = "Example:\n " +
- " > SELECT _FUNC_(0) FROM src LIMIT 1;\n" +
- " 0"
- )
+@description(name = "sin", value = "_FUNC_(x) - returns the sine of x (x is in radians)", extended = "Example:\n "
+ + " > SELECT _FUNC_(0) FROM src LIMIT 1;\n" + " 0")
public class UDFSin extends UDF {
private static Log LOG = LogFactory.getLog(UDFSin.class.getName());
DoubleWritable result = new DoubleWritable();
-
+
public UDFSin() {
}
/**
- * Take Sine of a.
+ * Take Sine of a.
*/
- public DoubleWritable evaluate(DoubleWritable a) {
+ public DoubleWritable evaluate(DoubleWritable a) {
if (a == null) {
return null;
} else {
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSpace.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSpace.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSpace.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSpace.java Thu Jan 21 10:37:58 2010
@@ -25,36 +25,29 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
+@description(name = "space", value = "_FUNC_(n) - returns n spaces", extended = "Example:\n "
+ + " > SELECT _FUNC_(2) FROM src LIMIT 1;\n" + " ' '")
+public class UDFSpace extends UDF {
+ private final Text result = new Text();
-@description(
- name = "space",
- value = "_FUNC_(n) - returns n spaces",
- extended = "Example:\n " +
- " > SELECT _FUNC_(2) FROM src LIMIT 1;\n" +
- " ' '"
- )
-public class UDFSpace extends UDF {
- private Text result = new Text();
-
public Text evaluate(IntWritable n) {
if (n == null) {
return null;
}
-
+
int len = n.get();
- if(len < 0) {
+ if (len < 0) {
len = 0;
}
-
- if(result.getBytes().length >= len) {
+
+ if (result.getBytes().length >= len) {
result.set(result.getBytes(), 0, len);
- }
- else {
+ } else {
byte[] spaces = new byte[len];
- Arrays.fill(spaces, (byte)' ');
+ Arrays.fill(spaces, (byte) ' ');
result.set(spaces);
}
-
+
return result;
}
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSqrt.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSqrt.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSqrt.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSqrt.java Thu Jan 21 10:37:58 2010
@@ -24,30 +24,24 @@
import org.apache.hadoop.hive.ql.exec.description;
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
-
/**
* Implementation of the SQRT UDF found in many databases.
*/
-@description(
- name = "sqrt",
- value = "_FUNC_(x) - returns the square root of x",
- extended = "Example:\n " +
- " > SELECT _FUNC_(4) FROM src LIMIT 1;\n" +
- " 2"
- )
+@description(name = "sqrt", value = "_FUNC_(x) - returns the square root of x", extended = "Example:\n "
+ + " > SELECT _FUNC_(4) FROM src LIMIT 1;\n" + " 2")
public class UDFSqrt extends UDF {
private static Log LOG = LogFactory.getLog(UDFSqrt.class.getName());
DoubleWritable result = new DoubleWritable();
+
public UDFSqrt() {
}
/**
- * Return NULL for NULL or negative inputs; otherwise, return
- * the square root.
+ * Return NULL for NULL or negative inputs; otherwise, return the square root.
*/
- public DoubleWritable evaluate(DoubleWritable i) {
+ public DoubleWritable evaluate(DoubleWritable i) {
if (i == null) {
return null;
} else if (i.get() < 0) {
@@ -57,5 +51,5 @@
return result;
}
}
-
+
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSubstr.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSubstr.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSubstr.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSubstr.java Thu Jan 21 10:37:58 2010
@@ -23,33 +23,30 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
-@description(
- name = "substr,substring",
- value = "_FUNC_(str, pos[, len]) - returns the substring of str that" +
- " starts at pos and is of length len",
- extended = "pos is a 1-based index. If pos<0 the starting position is" +
- " determined by counting backwards from the end of str.\n" +
- "Example:\n " +
- " > SELECT _FUNC_('Facebook', 5) FROM src LIMIT 1;\n" +
- " 'book'\n" +
- " > SELECT _FUNC_('Facebook', -5) FROM src LIMIT 1;\n" +
- " 'ebook'\n" +
- " > SELECT _FUNC_('Facebook', 5, 1) FROM src LIMIT 1;\n" +
- " 'b'"
- )
+@description(name = "substr,substring", value = "_FUNC_(str, pos[, len]) - returns the substring of str that"
+ + " starts at pos and is of length len", extended = "pos is a 1-based index. If pos<0 the starting position is"
+ + " determined by counting backwards from the end of str.\n"
+ + "Example:\n "
+ + " > SELECT _FUNC_('Facebook', 5) FROM src LIMIT 1;\n"
+ + " 'book'\n"
+ + " > SELECT _FUNC_('Facebook', -5) FROM src LIMIT 1;\n"
+ + " 'ebook'\n"
+ + " > SELECT _FUNC_('Facebook', 5, 1) FROM src LIMIT 1;\n"
+ + " 'b'")
public class UDFSubstr extends UDF {
Text r;
+
public UDFSubstr() {
r = new Text();
}
-
- public Text evaluate(Text t, IntWritable pos, IntWritable len) {
-
+
+ public Text evaluate(Text t, IntWritable pos, IntWritable len) {
+
if ((t == null) || (pos == null) || (len == null)) {
return null;
}
-
+
r.clear();
if ((len.get() <= 0)) {
return r;
@@ -59,7 +56,7 @@
if ((Math.abs(pos.get()) > s.length())) {
return r;
}
-
+
int start, end;
if (pos.get() > 0) {
@@ -69,20 +66,20 @@
} else {
start = 0;
}
-
+
if ((s.length() - start) < len.get()) {
end = s.length();
} else {
end = start + len.get();
}
-
+
r.set(s.substring(start, end));
return r;
}
IntWritable maxValue = new IntWritable(Integer.MAX_VALUE);
-
- public Text evaluate(Text s, IntWritable pos) {
+
+ public Text evaluate(Text s, IntWritable pos) {
return evaluate(s, pos, maxValue);
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToBoolean.java Thu Jan 21 10:37:58 2010
@@ -31,34 +31,34 @@
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
-
-
public class UDFToBoolean extends UDF {
private static Log LOG = LogFactory.getLog(UDFToBoolean.class.getName());
BooleanWritable booleanWritable = new BooleanWritable();
-
+
public UDFToBoolean() {
}
/**
* Convert a void to boolean. This is called for CAST(... AS BOOLEAN)
- *
- * @param i The value of a void type
+ *
+ * @param i
+ * The value of a void type
* @return BooleanWritable
*/
- public BooleanWritable evaluate(NullWritable i) {
- return null;
+ public BooleanWritable evaluate(NullWritable i) {
+ return null;
}
/**
* Convert from a byte to boolean. This is called for CAST(... AS BOOLEAN)
- *
- * @param i The byte value to convert
+ *
+ * @param i
+ * The byte value to convert
* @return BooleanWritable
*/
- public BooleanWritable evaluate(ByteWritable i) {
+ public BooleanWritable evaluate(ByteWritable i) {
if (i == null) {
return null;
} else {
@@ -69,11 +69,12 @@
/**
* Convert from a short to boolean. This is called for CAST(... AS BOOLEAN)
- *
- * @param i The short value to convert
+ *
+ * @param i
+ * The short value to convert
* @return BooleanWritable
*/
- public BooleanWritable evaluate(ShortWritable i) {
+ public BooleanWritable evaluate(ShortWritable i) {
if (i == null) {
return null;
} else {
@@ -84,11 +85,12 @@
/**
* Convert from a integer to boolean. This is called for CAST(... AS BOOLEAN)
- *
- * @param i The integer value to convert
+ *
+ * @param i
+ * The integer value to convert
* @return BooleanWritable
*/
- public BooleanWritable evaluate(IntWritable i) {
+ public BooleanWritable evaluate(IntWritable i) {
if (i == null) {
return null;
} else {
@@ -99,11 +101,12 @@
/**
* Convert from a long to boolean. This is called for CAST(... AS BOOLEAN)
- *
- * @param i The long value to convert
+ *
+ * @param i
+ * The long value to convert
* @return BooleanWritable
*/
- public BooleanWritable evaluate(LongWritable i) {
+ public BooleanWritable evaluate(LongWritable i) {
if (i == null) {
return null;
} else {
@@ -114,11 +117,12 @@
/**
* Convert from a float to boolean. This is called for CAST(... AS BOOLEAN)
- *
- * @param i The float value to convert
+ *
+ * @param i
+ * The float value to convert
* @return BooleanWritable
- */
- public BooleanWritable evaluate(FloatWritable i) {
+ */
+ public BooleanWritable evaluate(FloatWritable i) {
if (i == null) {
return null;
} else {
@@ -129,11 +133,12 @@
/**
* Convert from a double to boolean. This is called for CAST(... AS BOOLEAN)
- *
- * @param i The double value to convert
+ *
+ * @param i
+ * The double value to convert
* @return BooleanWritable
*/
- public BooleanWritable evaluate(DoubleWritable i) {
+ public BooleanWritable evaluate(DoubleWritable i) {
if (i == null) {
return null;
} else {
@@ -144,11 +149,12 @@
/**
* Convert from a string to boolean. This is called for CAST(... AS BOOLEAN)
- *
- * @param i The string value to convert
+ *
+ * @param i
+ * The string value to convert
* @return BooleanWritable
*/
- public BooleanWritable evaluate(Text i) {
+ public BooleanWritable evaluate(Text i) {
if (i == null) {
return null;
} else {
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToByte.java Thu Jan 21 10:37:58 2010
@@ -32,128 +32,136 @@
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
-
public class UDFToByte extends UDF {
private static Log LOG = LogFactory.getLog(UDFToByte.class.getName());
ByteWritable byteWritable = new ByteWritable();
-
+
public UDFToByte() {
}
/**
* Convert from void to a byte. This is called for CAST(... AS TINYINT)
- *
- * @param i The void value to convert
+ *
+ * @param i
+ * The void value to convert
* @return Byte
*/
- public ByteWritable evaluate(NullWritable i) {
+ public ByteWritable evaluate(NullWritable i) {
return null;
- }
+ }
/**
* Convert from boolean to a byte. This is called for CAST(... AS TINYINT)
- *
- * @param i The boolean value to convert
+ *
+ * @param i
+ * The boolean value to convert
* @return Byte
*/
- public ByteWritable evaluate(BooleanWritable i) {
+ public ByteWritable evaluate(BooleanWritable i) {
if (i == null) {
return null;
} else {
- byteWritable.set(i.get() ? (byte)1 : (byte)0);
+ byteWritable.set(i.get() ? (byte) 1 : (byte) 0);
return byteWritable;
}
- }
+ }
/**
* Convert from short to a byte. This is called for CAST(... AS TINYINT)
- *
- * @param i The short value to convert
+ *
+ * @param i
+ * The short value to convert
* @return Byte
*/
- public ByteWritable evaluate(ShortWritable i) {
+ public ByteWritable evaluate(ShortWritable i) {
if (i == null) {
return null;
} else {
- byteWritable.set((byte)i.get());
+ byteWritable.set((byte) i.get());
return byteWritable;
}
}
/**
* Convert from integer to a byte. This is called for CAST(... AS TINYINT)
- *
- * @param i The integer value to convert
+ *
+ * @param i
+ * The integer value to convert
* @return Byte
*/
- public ByteWritable evaluate(IntWritable i) {
+ public ByteWritable evaluate(IntWritable i) {
if (i == null) {
return null;
} else {
- byteWritable.set((byte)i.get());
+ byteWritable.set((byte) i.get());
return byteWritable;
}
}
/**
* Convert from long to a byte. This is called for CAST(... AS TINYINT)
- *
- * @param i The long value to convert
+ *
+ * @param i
+ * The long value to convert
* @return Byte
*/
- public ByteWritable evaluate(LongWritable i) {
+ public ByteWritable evaluate(LongWritable i) {
if (i == null) {
return null;
} else {
- byteWritable.set((byte)i.get());
+ byteWritable.set((byte) i.get());
return byteWritable;
}
- }
+ }
/**
* Convert from float to a byte. This is called for CAST(... AS TINYINT)
- *
- * @param i The float value to convert
+ *
+ * @param i
+ * The float value to convert
* @return Byte
*/
- public ByteWritable evaluate(FloatWritable i) {
+ public ByteWritable evaluate(FloatWritable i) {
if (i == null) {
return null;
} else {
- byteWritable.set((byte)i.get());
+ byteWritable.set((byte) i.get());
return byteWritable;
}
}
/**
* Convert from double to a byte. This is called for CAST(... AS TINYINT)
- *
- * @param i The double value to convert
+ *
+ * @param i
+ * The double value to convert
* @return Byte
- */
- public ByteWritable evaluate(DoubleWritable i) {
+ */
+ public ByteWritable evaluate(DoubleWritable i) {
if (i == null) {
return null;
} else {
- byteWritable.set((byte)i.get());
+ byteWritable.set((byte) i.get());
return byteWritable;
}
}
/**
* Convert from string to a byte. This is called for CAST(... AS TINYINT)
- *
- * @param i The string value to convert
+ *
+ * @param i
+ * The string value to convert
* @return Byte
- */
- public ByteWritable evaluate(Text i) {
+ */
+ public ByteWritable evaluate(Text i) {
if (i == null) {
return null;
} else {
try {
- byteWritable.set(LazyByte.parseByte(i.getBytes(), 0 , i.getLength(), 10));
+ byteWritable
+ .set(LazyByte.parseByte(i.getBytes(), 0, i.getLength(), 10));
return byteWritable;
} catch (NumberFormatException e) {
// MySQL returns 0 if the string is not a well-formed numeric value.
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDate.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDate.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDate.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDate.java Thu Jan 21 10:37:58 2010
@@ -22,7 +22,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.UDF;
-
public class UDFToDate extends UDF {
private static Log LOG = LogFactory.getLog(UDFToDate.class.getName());
@@ -30,7 +29,7 @@
public UDFToDate() {
}
- public java.sql.Date evaluate(String i) {
+ public java.sql.Date evaluate(String i) {
if (i == null) {
return null;
} else {
@@ -38,68 +37,63 @@
// Supported format: "YYYY-MM-DD"
return java.sql.Date.valueOf(i);
} catch (IllegalArgumentException e) {
- // We return NULL when the string is in a wrong format, which is conservative.
+ // We return NULL when the string is in a wrong format, which is
+ // conservative.
return null;
}
}
}
-
+
public java.sql.Date evaluate(Void i) {
return null;
}
-
+
public java.sql.Date evaluate(Byte i) {
if (i == null) {
return null;
- }
- else {
+ } else {
return new java.sql.Date(i.longValue());
}
}
-
+
public java.sql.Date evaluate(Short i) {
if (i == null) {
return null;
- }
- else {
+ } else {
return new java.sql.Date(i.longValue());
}
}
-
+
public java.sql.Date evaluate(Integer i) {
if (i == null) {
return null;
- }
- else {
+ } else {
return new java.sql.Date(i.longValue());
}
}
-
+
public java.sql.Date evaluate(Long i) {
if (i == null) {
return null;
- }
- else {
+ } else {
return new java.sql.Date(i.longValue());
}
}
-
+
public java.sql.Date evaluate(Float i) {
if (i == null) {
return null;
- }
- else {
+ } else {
return new java.sql.Date(i.longValue());
}
}
-
+
public java.sql.Date evaluate(Double i) {
if (i == null) {
return null;
- }
- else {
+ } else {
return new java.sql.Date(i.longValue());
}
}
-
+
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToDouble.java Thu Jan 21 10:37:58 2010
@@ -31,33 +31,34 @@
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
-
public class UDFToDouble extends UDF {
private static Log LOG = LogFactory.getLog(UDFToDouble.class.getName());
DoubleWritable doubleWritable = new DoubleWritable();
-
+
public UDFToDouble() {
}
/**
* Convert from void to a double. This is called for CAST(... AS DOUBLE)
- *
- * @param i The void value to convert
+ *
+ * @param i
+ * The void value to convert
* @return DoubleWritable
*/
- public DoubleWritable evaluate(NullWritable i) {
+ public DoubleWritable evaluate(NullWritable i) {
return null;
}
/**
* Convert from boolean to a double. This is called for CAST(... AS DOUBLE)
- *
- * @param i The boolean value to convert
+ *
+ * @param i
+ * The boolean value to convert
* @return DoubleWritable
*/
- public DoubleWritable evaluate(BooleanWritable i) {
+ public DoubleWritable evaluate(BooleanWritable i) {
if (i == null) {
return null;
} else {
@@ -68,11 +69,12 @@
/**
* Convert from boolean to a double. This is called for CAST(... AS DOUBLE)
- *
- * @param i The byte value to convert
+ *
+ * @param i
+ * The byte value to convert
* @return DoubleWritable
*/
- public DoubleWritable evaluate(ByteWritable i) {
+ public DoubleWritable evaluate(ByteWritable i) {
if (i == null) {
return null;
} else {
@@ -80,14 +82,15 @@
return doubleWritable;
}
}
-
+
/**
* Convert from short to a double. This is called for CAST(... AS DOUBLE)
- *
- * @param i The short value to convert
+ *
+ * @param i
+ * The short value to convert
* @return DoubleWritable
*/
- public DoubleWritable evaluate(ShortWritable i) {
+ public DoubleWritable evaluate(ShortWritable i) {
if (i == null) {
return null;
} else {
@@ -95,14 +98,15 @@
return doubleWritable;
}
}
-
+
/**
* Convert from integer to a double. This is called for CAST(... AS DOUBLE)
- *
- * @param i The integer value to convert
+ *
+ * @param i
+ * The integer value to convert
* @return DoubleWritable
*/
- public DoubleWritable evaluate(IntWritable i) {
+ public DoubleWritable evaluate(IntWritable i) {
if (i == null) {
return null;
} else {
@@ -110,14 +114,15 @@
return doubleWritable;
}
}
-
+
/**
* Convert from long to a double. This is called for CAST(... AS DOUBLE)
- *
- * @param i The long value to convert
+ *
+ * @param i
+ * The long value to convert
* @return DoubleWritable
*/
- public DoubleWritable evaluate(LongWritable i) {
+ public DoubleWritable evaluate(LongWritable i) {
if (i == null) {
return null;
} else {
@@ -125,14 +130,15 @@
return doubleWritable;
}
}
-
+
/**
* Convert from float to a double. This is called for CAST(... AS DOUBLE)
- *
- * @param i The float value to convert
+ *
+ * @param i
+ * The float value to convert
* @return DoubleWritable
*/
- public DoubleWritable evaluate(FloatWritable i) {
+ public DoubleWritable evaluate(FloatWritable i) {
if (i == null) {
return null;
} else {
@@ -140,14 +146,15 @@
return doubleWritable;
}
}
-
+
/**
* Convert from string to a double. This is called for CAST(... AS DOUBLE)
- *
- * @param i The string value to convert
+ *
+ * @param i
+ * The string value to convert
* @return DoubleWritable
*/
- public DoubleWritable evaluate(Text i) {
+ public DoubleWritable evaluate(Text i) {
if (i == null) {
return null;
} else {
@@ -161,6 +168,5 @@
}
}
}
-
-
+
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToFloat.java Thu Jan 21 10:37:58 2010
@@ -31,123 +31,130 @@
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
-
public class UDFToFloat extends UDF {
private static Log LOG = LogFactory.getLog(UDFToFloat.class.getName());
FloatWritable floatWritable = new FloatWritable();
-
+
public UDFToFloat() {
}
/**
* Convert from void to a float. This is called for CAST(... AS FLOAT)
- *
- * @param i The void value to convert
+ *
+ * @param i
+ * The void value to convert
* @return FloatWritable
*/
- public FloatWritable evaluate(NullWritable i) {
+ public FloatWritable evaluate(NullWritable i) {
return null;
}
/**
* Convert from boolean to a float. This is called for CAST(... AS FLOAT)
- *
- * @param i The boolean value to convert
+ *
+ * @param i
+ * The boolean value to convert
* @return FloatWritable
*/
- public FloatWritable evaluate(BooleanWritable i) {
+ public FloatWritable evaluate(BooleanWritable i) {
if (i == null) {
return null;
} else {
- floatWritable.set(i.get() ? (float)1.0 : (float)0.0);
+ floatWritable.set(i.get() ? (float) 1.0 : (float) 0.0);
return floatWritable;
}
}
-
+
/**
* Convert from byte to a float. This is called for CAST(... AS FLOAT)
- *
- * @param i The byte value to convert
+ *
+ * @param i
+ * The byte value to convert
* @return FloatWritable
*/
- public FloatWritable evaluate(ByteWritable i) {
+ public FloatWritable evaluate(ByteWritable i) {
if (i == null) {
return null;
} else {
- floatWritable.set((float)i.get());
+ floatWritable.set(i.get());
return floatWritable;
}
}
-
+
/**
* Convert from short to a float. This is called for CAST(... AS FLOAT)
- *
- * @param i The short value to convert
+ *
+ * @param i
+ * The short value to convert
* @return FloatWritable
*/
- public FloatWritable evaluate(ShortWritable i) {
+ public FloatWritable evaluate(ShortWritable i) {
if (i == null) {
return null;
} else {
- floatWritable.set((float)i.get());
+ floatWritable.set(i.get());
return floatWritable;
}
}
-
+
/**
* Convert from integer to a float. This is called for CAST(... AS FLOAT)
- *
- * @param i The integer value to convert
+ *
+ * @param i
+ * The integer value to convert
* @return FloatWritable
*/
- public FloatWritable evaluate(IntWritable i) {
+ public FloatWritable evaluate(IntWritable i) {
if (i == null) {
return null;
} else {
- floatWritable.set((float)i.get());
+ floatWritable.set(i.get());
return floatWritable;
}
}
-
+
/**
* Convert from long to a float. This is called for CAST(... AS FLOAT)
- *
- * @param i The long value to convert
+ *
+ * @param i
+ * The long value to convert
* @return FloatWritable
*/
- public FloatWritable evaluate(LongWritable i) {
+ public FloatWritable evaluate(LongWritable i) {
if (i == null) {
return null;
} else {
- floatWritable.set((float)i.get());
+ floatWritable.set(i.get());
return floatWritable;
}
}
/**
* Convert from double to a float. This is called for CAST(... AS FLOAT)
- *
- * @param i The double value to convert
+ *
+ * @param i
+ * The double value to convert
* @return FloatWritable
- */
- public FloatWritable evaluate(DoubleWritable i) {
+ */
+ public FloatWritable evaluate(DoubleWritable i) {
if (i == null) {
return null;
} else {
- floatWritable.set((float)i.get());
+ floatWritable.set((float) i.get());
return floatWritable;
}
}
-
+
/**
* Convert from string to a float. This is called for CAST(... AS FLOAT)
- *
- * @param i The string value to convert
+ *
+ * @param i
+ * The string value to convert
* @return FloatWritable
*/
- public FloatWritable evaluate(Text i) {
+ public FloatWritable evaluate(Text i) {
if (i == null) {
return null;
} else {
@@ -161,5 +168,5 @@
}
}
}
-
+
}
Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java?rev=901644&r1=901643&r2=901644&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToInteger.java Thu Jan 21 10:37:58 2010
@@ -32,33 +32,34 @@
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
-
public class UDFToInteger extends UDF {
private static Log LOG = LogFactory.getLog(UDFToInteger.class.getName());
IntWritable intWritable = new IntWritable();
-
+
public UDFToInteger() {
}
/**
* Convert from void to an integer. This is called for CAST(... AS INT)
- *
- * @param i The void value to convert
+ *
+ * @param i
+ * The void value to convert
* @return Integer
*/
- public IntWritable evaluate(NullWritable i) {
+ public IntWritable evaluate(NullWritable i) {
return null;
}
/**
* Convert from boolean to an integer. This is called for CAST(... AS INT)
- *
- * @param i The boolean value to convert
+ *
+ * @param i
+ * The boolean value to convert
* @return IntWritable
*/
- public IntWritable evaluate(BooleanWritable i) {
+ public IntWritable evaluate(BooleanWritable i) {
if (i == null) {
return null;
} else {
@@ -66,94 +67,101 @@
return intWritable;
}
}
-
+
/**
* Convert from byte to an integer. This is called for CAST(... AS INT)
- *
- * @param i The byte value to convert
+ *
+ * @param i
+ * The byte value to convert
* @return IntWritable
*/
- public IntWritable evaluate(ByteWritable i) {
+ public IntWritable evaluate(ByteWritable i) {
if (i == null) {
return null;
} else {
- intWritable.set((int)i.get());
+ intWritable.set(i.get());
return intWritable;
}
}
-
+
/**
* Convert from short to an integer. This is called for CAST(... AS INT)
- *
- * @param i The short value to convert
+ *
+ * @param i
+ * The short value to convert
* @return IntWritable
*/
- public IntWritable evaluate(ShortWritable i) {
+ public IntWritable evaluate(ShortWritable i) {
if (i == null) {
return null;
} else {
- intWritable.set((int)i.get());
+ intWritable.set(i.get());
return intWritable;
}
}
-
+
/**
* Convert from long to an integer. This is called for CAST(... AS INT)
- *
- * @param i The long value to convert
+ *
+ * @param i
+ * The long value to convert
* @return IntWritable
*/
- public IntWritable evaluate(LongWritable i) {
+ public IntWritable evaluate(LongWritable i) {
if (i == null) {
return null;
} else {
- intWritable.set((int)i.get());
+ intWritable.set((int) i.get());
return intWritable;
}
}
-
+
/**
* Convert from float to an integer. This is called for CAST(... AS INT)
- *
- * @param i The float value to convert
+ *
+ * @param i
+ * The float value to convert
* @return IntWritable
*/
- public IntWritable evaluate(FloatWritable i) {
+ public IntWritable evaluate(FloatWritable i) {
if (i == null) {
return null;
} else {
- intWritable.set((int)i.get());
+ intWritable.set((int) i.get());
return intWritable;
}
}
-
+
/**
* Convert from double to an integer. This is called for CAST(... AS INT)
- *
- * @param i The double value to convert
+ *
+ * @param i
+ * The double value to convert
* @return IntWritable
*/
- public IntWritable evaluate(DoubleWritable i) {
+ public IntWritable evaluate(DoubleWritable i) {
if (i == null) {
return null;
} else {
- intWritable.set((int)i.get());
+ intWritable.set((int) i.get());
return intWritable;
}
}
-
+
/**
* Convert from string to an integer. This is called for CAST(... AS INT)
- *
- * @param i The string value to convert
+ *
+ * @param i
+ * The string value to convert
* @return IntWritable
*/
- public IntWritable evaluate(Text i) {
+ public IntWritable evaluate(Text i) {
if (i == null) {
return null;
} else {
try {
- intWritable.set(LazyInteger.parseInt(i.getBytes(), 0 , i.getLength(), 10));
+ intWritable.set(LazyInteger
+ .parseInt(i.getBytes(), 0, i.getLength(), 10));
return intWritable;
} catch (NumberFormatException e) {
// MySQL returns 0 if the string is not a well-formed numeric value.
@@ -163,5 +171,5 @@
}
}
}
-
+
}