PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPBitXor.java

#
Java | 70 lines | 40 code | 9 blank | 21 comment | 16 complexity | 5109aca40a6b4e2a7332a6a91d271dd6 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.ShortWritable;
24import org.apache.hadoop.io.IntWritable;
25import org.apache.hadoop.io.LongWritable;
26
27/**
28 * UDFOPBitXor.
29 *
30 */
31@Description(name = "^", value = "a _FUNC_ b - Bitwise exclusive or", extended = "Example:\n"
32    + "  > SELECT 3 _FUNC_ 5 FROM src LIMIT 1;\n" + "  2")
33public class UDFOPBitXor extends UDFBaseBitOP {
34
35  public UDFOPBitXor() {
36  }
37
38  public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
39    if (a == null || b == null) {
40      return null;
41    }
42    byteWritable.set((byte) (a.get() ^ b.get()));
43    return byteWritable;
44  }
45
46  public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
47    if (a == null || b == null) {
48      return null;
49    }
50    shortWritable.set((short) (a.get() ^ b.get()));
51    return shortWritable;
52  }
53
54  public IntWritable evaluate(IntWritable a, IntWritable b) {
55    if (a == null || b == null) {
56      return null;
57    }
58    intWritable.set(a.get() ^ b.get());
59    return intWritable;
60  }
61
62  public LongWritable evaluate(LongWritable a, LongWritable b) {
63    if (a == null || b == null) {
64      return null;
65    }
66    longWritable.set(a.get() ^ b.get());
67    return longWritable;
68  }
69
70}