PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 99 lines | 62 code | 13 blank | 24 comment | 21 complexity | 92d61c4d8f1a57a397bdb74c854522e8 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.UDF;
  20. /**
  21. * UDFToDate.
  22. *
  23. */
  24. public class UDFToDate extends UDF {
  25. public UDFToDate() {
  26. }
  27. public java.sql.Date evaluate(String i) {
  28. if (i == null) {
  29. return null;
  30. } else {
  31. try {
  32. // Supported format: "YYYY-MM-DD"
  33. return java.sql.Date.valueOf(i);
  34. } catch (IllegalArgumentException e) {
  35. // We return NULL when the string is in a wrong format, which is
  36. // conservative.
  37. return null;
  38. }
  39. }
  40. }
  41. public java.sql.Date evaluate(Void i) {
  42. return null;
  43. }
  44. public java.sql.Date evaluate(Byte i) {
  45. if (i == null) {
  46. return null;
  47. } else {
  48. return new java.sql.Date(i.longValue());
  49. }
  50. }
  51. public java.sql.Date evaluate(Short i) {
  52. if (i == null) {
  53. return null;
  54. } else {
  55. return new java.sql.Date(i.longValue());
  56. }
  57. }
  58. public java.sql.Date evaluate(Integer i) {
  59. if (i == null) {
  60. return null;
  61. } else {
  62. return new java.sql.Date(i.longValue());
  63. }
  64. }
  65. public java.sql.Date evaluate(Long i) {
  66. if (i == null) {
  67. return null;
  68. } else {
  69. return new java.sql.Date(i.longValue());
  70. }
  71. }
  72. public java.sql.Date evaluate(Float i) {
  73. if (i == null) {
  74. return null;
  75. } else {
  76. return new java.sql.Date(i.longValue());
  77. }
  78. }
  79. public java.sql.Date evaluate(Double i) {
  80. if (i == null) {
  81. return null;
  82. } else {
  83. return new java.sql.Date(i.longValue());
  84. }
  85. }
  86. }