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