PageRenderTime 29ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 2ms 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
 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;
20
21import org.apache.hadoop.hive.ql.exec.UDF;
22
23/**
24 * UDFToDate.
25 *
26 */
27public class UDFToDate extends UDF {
28
29  public UDFToDate() {
30  }
31
32  public java.sql.Date evaluate(String i) {
33    if (i == null) {
34      return null;
35    } else {
36      try {
37        // Supported format: "YYYY-MM-DD"
38        return java.sql.Date.valueOf(i);
39      } catch (IllegalArgumentException e) {
40        // We return NULL when the string is in a wrong format, which is
41        // conservative.
42        return null;
43      }
44    }
45  }
46
47  public java.sql.Date evaluate(Void i) {
48    return null;
49  }
50
51  public java.sql.Date evaluate(Byte i) {
52    if (i == null) {
53      return null;
54    } else {
55      return new java.sql.Date(i.longValue());
56    }
57  }
58
59  public java.sql.Date evaluate(Short i) {
60    if (i == null) {
61      return null;
62    } else {
63      return new java.sql.Date(i.longValue());
64    }
65  }
66
67  public java.sql.Date evaluate(Integer i) {
68    if (i == null) {
69      return null;
70    } else {
71      return new java.sql.Date(i.longValue());
72    }
73  }
74
75  public java.sql.Date evaluate(Long i) {
76    if (i == null) {
77      return null;
78    } else {
79      return new java.sql.Date(i.longValue());
80    }
81  }
82
83  public java.sql.Date evaluate(Float i) {
84    if (i == null) {
85      return null;
86    } else {
87      return new java.sql.Date(i.longValue());
88    }
89  }
90
91  public java.sql.Date evaluate(Double i) {
92    if (i == null) {
93      return null;
94    } else {
95      return new java.sql.Date(i.longValue());
96    }
97  }
98
99}