Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TestUdf.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.hive.executor;
16 
17 import org.apache.hadoop.hive.ql.exec.UDF;
18 import org.apache.hadoop.hive.serde2.io.ByteWritable;
19 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
20 import org.apache.hadoop.hive.serde2.io.ShortWritable;
21 import org.apache.hadoop.hive.serde2.io.TimestampWritable;
22 import org.apache.hadoop.io.BooleanWritable;
23 import org.apache.hadoop.io.BytesWritable;
24 import org.apache.hadoop.io.FloatWritable;
25 import org.apache.hadoop.io.IntWritable;
26 import org.apache.hadoop.io.LongWritable;
27 import org.apache.hadoop.io.Text;
28 
32 public class TestUdf extends UDF {
33  public TestUdf() {
34  }
35 
36  // Identity UDFs for all the supported types
37  public BooleanWritable evaluate(BooleanWritable a) {
38  if (a == null) return null;
39  return new BooleanWritable(a.get());
40  }
41  public ByteWritable evaluate(ByteWritable a) {
42  if (a == null) return null;
43  return new ByteWritable(a.get());
44  }
45  public ShortWritable evaluate(ShortWritable a) {
46  if (a == null) return null;
47  return new ShortWritable(a.get());
48  }
49  public IntWritable evaluate(IntWritable a) {
50  if (a == null) return null;
51  return new IntWritable(a.get());
52  }
53  public LongWritable evaluate(LongWritable a) {
54  if (a == null) return null;
55  return new LongWritable(a.get());
56  }
57  public FloatWritable evaluate(FloatWritable a) {
58  if (a == null) return null;
59  return new FloatWritable(a.get());
60  }
61  public DoubleWritable evaluate(DoubleWritable a) {
62  if (a == null) return null;
63  return new DoubleWritable(a.get());
64  }
65  public BytesWritable evaluate(BytesWritable a) {
66  if (a == null) return null;
67  return new BytesWritable(a.getBytes());
68  }
69  public Text evaluate(Text a) {
70  if (a == null) return null;
71  return new Text(a.getBytes());
72  }
73  public TimestampWritable evaluate(TimestampWritable a) {
74  if (a == null) return a;
75  return new TimestampWritable(a);
76  }
77  public String evaluate(String a) {
78  if (a == null) return a;
79  return a;
80  }
81 
82  public DoubleWritable evaluate(DoubleWritable arg1, DoubleWritable arg2) {
83  if (arg1 == null || arg2 == null) return null;
84  return new DoubleWritable(arg1.get() + arg2.get());
85  }
86 
87  public String evaluate(String a, String b) {
88  if (a == null || b == null) return null;
89  return a + b;
90  }
91 
92 }
String evaluate(String a, String b)
Definition: TestUdf.java:87
DoubleWritable evaluate(DoubleWritable a)
Definition: TestUdf.java:61
BooleanWritable evaluate(BooleanWritable a)
Definition: TestUdf.java:37
ByteWritable evaluate(ByteWritable a)
Definition: TestUdf.java:41
FloatWritable evaluate(FloatWritable a)
Definition: TestUdf.java:57
LongWritable evaluate(LongWritable a)
Definition: TestUdf.java:53
IntWritable evaluate(IntWritable a)
Definition: TestUdf.java:49
BytesWritable evaluate(BytesWritable a)
Definition: TestUdf.java:65
TimestampWritable evaluate(TimestampWritable a)
Definition: TestUdf.java:73
DoubleWritable evaluate(DoubleWritable arg1, DoubleWritable arg2)
Definition: TestUdf.java:82
ShortWritable evaluate(ShortWritable a)
Definition: TestUdf.java:45