PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 93 lines | 61 code | 11 blank | 21 comment | 12 complexity | fd5bb73bf3372b34f20e2c9d52fca337 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;
  19. import org.apache.hadoop.hive.ql.exec.Description;
  20. import org.apache.hadoop.hive.serde2.io.ByteWritable;
  21. import org.apache.hadoop.hive.serde2.io.DoubleWritable;
  22. import org.apache.hadoop.hive.serde2.io.ShortWritable;
  23. import org.apache.hadoop.io.FloatWritable;
  24. import org.apache.hadoop.io.IntWritable;
  25. import org.apache.hadoop.io.LongWritable;
  26. /**
  27. * UDFOPNegative.
  28. *
  29. */
  30. @Description(name = "-", value = "_FUNC_ a - Returns -a")
  31. public class UDFOPNegative extends UDFBaseNumericUnaryOp {
  32. public UDFOPNegative() {
  33. }
  34. @Override
  35. public ByteWritable evaluate(ByteWritable a) {
  36. if (a == null) {
  37. return null;
  38. }
  39. byteWritable.set((byte) -a.get());
  40. return byteWritable;
  41. }
  42. @Override
  43. public ShortWritable evaluate(ShortWritable a) {
  44. if (a == null) {
  45. return null;
  46. }
  47. shortWritable.set((short) -a.get());
  48. return shortWritable;
  49. }
  50. @Override
  51. public IntWritable evaluate(IntWritable a) {
  52. if (a == null) {
  53. return null;
  54. }
  55. intWritable.set(-a.get());
  56. return intWritable;
  57. }
  58. @Override
  59. public LongWritable evaluate(LongWritable a) {
  60. if (a == null) {
  61. return null;
  62. }
  63. longWritable.set(-a.get());
  64. return longWritable;
  65. }
  66. @Override
  67. public FloatWritable evaluate(FloatWritable a) {
  68. if (a == null) {
  69. return null;
  70. }
  71. floatWritable.set(-a.get());
  72. return floatWritable;
  73. }
  74. @Override
  75. public DoubleWritable evaluate(DoubleWritable a) {
  76. if (a == null) {
  77. return null;
  78. }
  79. doubleWritable.set(-a.get());
  80. return doubleWritable;
  81. }
  82. }