PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 87 lines | 62 code | 5 blank | 20 comment | 14 complexity | 18e663f76f63fabde206a74b4d6e843f 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.generic;
20
21import org.apache.hadoop.hive.ql.exec.Description;
22import org.apache.hadoop.hive.ql.metadata.HiveException;
23import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
24
25/**
26 * GenericUDF Class for operation Not EQUAL.
27 */
28@Description(name = "<>", value = "a _FUNC_ b - Returns TRUE if a is not equal to b")
29public class GenericUDFOPNotEqual extends GenericUDFBaseCompare {
30  public GenericUDFOPNotEqual(){
31    this.opName = "NOT EQUAL";
32    this.opDisplayName = "<>";
33  }
34
35  @Override
36  public Object evaluate(DeferredObject[] arguments) throws HiveException {
37    Object o0,o1;
38    o0 = arguments[0].get();
39    if (o0 == null) {
40      return null;
41    }
42    o1 = arguments[1].get();
43    if (o1 == null) {
44      return null;
45    }
46
47    switch(compareType) {
48    case COMPARE_TEXT:
49      result.set(!soi0.getPrimitiveWritableObject(o0).equals(
50          soi1.getPrimitiveWritableObject(o1)));
51      break;
52    case COMPARE_INT:
53      result.set(ioi0.get(o0) != ioi1.get(o1));
54      break;
55    case COMPARE_LONG:
56      result.set(loi0.get(o0) != loi1.get(o1));
57      break;
58    case COMPARE_BYTE:
59      result.set(byoi0.get(o0) != byoi1.get(o1));
60      break;
61    case COMPARE_BOOL:
62      result.set(boi0.get(o0) != boi1.get(o1));
63      break;
64    case COMPARE_STRING:
65      result.set(!soi0.getPrimitiveJavaObject(o0).equals(
66          soi1.getPrimitiveJavaObject(o1)));
67      break;
68    case SAME_TYPE:
69      result.set(ObjectInspectorUtils.compare(
70          o0, argumentOIs[0], o1, argumentOIs[1]) != 0);
71      break;
72    default:
73      Object converted_o0 = converter0.convert(o0);
74      if (converted_o0 == null) {
75        return null;
76      }
77      Object converted_o1 = converter1.convert(o1);
78      if (converted_o1 == null) {
79        return null;
80      }
81      result.set(ObjectInspectorUtils.compare(
82          converted_o0, compareOI,
83          converted_o1, compareOI) != 0);
84    }
85    return result;
86  }
87}