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