PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 96 lines | 70 code | 6 blank | 20 comment | 9 complexity | 02bede2b25594ab5c249618e2e8257c3 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;
24import org.apache.hadoop.hive.shims.ShimLoader;
25import org.apache.hadoop.io.Text;
26
27/**
28 * GenericUDF Class for operation EqualOrGreaterThan.
29 */
30@Description(name = ">=", value = "a _FUNC_ b - Returns TRUE if a is not smaller than b")
31public class GenericUDFOPEqualOrGreaterThan extends GenericUDFBaseCompare {
32  public GenericUDFOPEqualOrGreaterThan(){
33    this.opName = "EQUAL OR GREATER THAN";
34    this.opDisplayName = ">=";
35  }
36
37  @Override
38  public Object evaluate(DeferredObject[] arguments) throws HiveException {
39    Object o0,o1;
40    o0 = arguments[0].get();
41    if (o0 == null) {
42      return null;
43    }
44    o1 = arguments[1].get();
45    if (o1 == null) {
46      return null;
47    }
48
49    switch(compareType) {
50    case COMPARE_TEXT:
51      Text t0, t1;
52      t0 = soi0.getPrimitiveWritableObject(o0);
53      t1 = soi1.getPrimitiveWritableObject(o1);
54      result.set(ShimLoader.getHadoopShims().compareText(t0, t1) >= 0);
55      break;
56    case COMPARE_INT:
57      result.set(ioi0.get(o0) >= ioi1.get(o1));
58      break;
59    case COMPARE_LONG:
60      result.set(loi0.get(o0) >= loi1.get(o1));
61      break;
62    case COMPARE_BYTE:
63      result.set(byoi0.get(o0) >= byoi1.get(o1));
64      break;
65    case COMPARE_BOOL:
66      boolean b0 = boi0.get(o0);
67      boolean b1 = boi1.get(o1);
68      result.set(b0 || !b1);
69      break;
70    case COMPARE_STRING:
71      String s0, s1;
72      s0 = soi0.getPrimitiveJavaObject(o0);
73      s1 = soi1.getPrimitiveJavaObject(o1);
74      result.set(s0.compareTo(s1) >= 0);
75      break;
76    case SAME_TYPE:
77      result.set(ObjectInspectorUtils.compare(
78          o0, argumentOIs[0], o1, argumentOIs[1]) >= 0);
79      break;
80    default:
81      Object converted_o0 = converter0.convert(o0);
82      if (converted_o0 == null) {
83        return null;
84      }
85      Object converted_o1 = converter1.convert(o1);
86      if (converted_o1 == null) {
87        return null;
88      }
89      result.set(ObjectInspectorUtils.compare(
90          converted_o0, compareOI,
91          converted_o1, compareOI) >= 0);
92    }
93    return result;
94  }
95
96}