PageRenderTime 15ms CodeModel.GetById 7ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPNegative.java

#
Java | 93 lines | 61 code | 11 blank | 21 comment | 12 complexity | fd5bb73bf3372b34f20e2c9d52fca337 MD5 | raw file
 1/**
 2 * Licensed to the Apache Software Foundation (ASF) under one
 3 * or more contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  The ASF licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.hive.ql.udf;
20
21import org.apache.hadoop.hive.ql.exec.Description;
22import org.apache.hadoop.hive.serde2.io.ByteWritable;
23import org.apache.hadoop.hive.serde2.io.DoubleWritable;
24import org.apache.hadoop.hive.serde2.io.ShortWritable;
25import org.apache.hadoop.io.FloatWritable;
26import org.apache.hadoop.io.IntWritable;
27import org.apache.hadoop.io.LongWritable;
28
29/**
30 * UDFOPNegative.
31 *
32 */
33@Description(name = "-", value = "_FUNC_ a - Returns -a")
34public class UDFOPNegative extends UDFBaseNumericUnaryOp {
35
36  public UDFOPNegative() {
37  }
38
39  @Override
40  public ByteWritable evaluate(ByteWritable a) {
41    if (a == null) {
42      return null;
43    }
44    byteWritable.set((byte) -a.get());
45    return byteWritable;
46  }
47
48  @Override
49  public ShortWritable evaluate(ShortWritable a) {
50    if (a == null) {
51      return null;
52    }
53    shortWritable.set((short) -a.get());
54    return shortWritable;
55  }
56
57  @Override
58  public IntWritable evaluate(IntWritable a) {
59    if (a == null) {
60      return null;
61    }
62    intWritable.set(-a.get());
63    return intWritable;
64  }
65
66  @Override
67  public LongWritable evaluate(LongWritable a) {
68    if (a == null) {
69      return null;
70    }
71    longWritable.set(-a.get());
72    return longWritable;
73  }
74
75  @Override
76  public FloatWritable evaluate(FloatWritable a) {
77    if (a == null) {
78      return null;
79    }
80    floatWritable.set(-a.get());
81    return floatWritable;
82  }
83
84  @Override
85  public DoubleWritable evaluate(DoubleWritable a) {
86    if (a == null) {
87      return null;
88    }
89    doubleWritable.set(-a.get());
90    return doubleWritable;
91  }
92
93}